Harigami
ログイン
anonymous タイトルなし
Python
>>> import pickle
>>> l=[1, 2, "three", "four"]
>>> ps=pickle.dumps(l)
>>> print ps
(lp0
I1
aI2
aS'three'
p1
aS'four'
p2
a.
>>> pl=pickle.loads(ps)
>>> print pl
[1, 2, 'three', 'four']
  • 0
  • 1
anonymous ペンギンさん
Python
# 1
n = int(input("何羽?:"))
penguin_data = {}

# 2
for i in range(n):
    name = input(str(i+1)+"羽目の名前:")
    print("ε( ミ' ・)>")
    slide = float(input("何m滑った?:"))
    print("_ε( ミ' ・)>♪")
    penguin_data[name] = slide

# 3
# 辞書からスライド距離だけ取り出してリスト化
slide_list = list(penguin_data.values())

slide_mean = sum(slide_list) / n
slide_max = max(slide_list)
slide_min = min(slide_list)

print("平均は " + str(slide_mean) + " m/羽です.")
print("最大値は " + str(slide_max) + " m, 最小値は " + str(slide_min) + " mです.")

# 4
upper = (slide_min+3*slide_max)/4
lower = (slide_max+3*slide_min)/4
# リスト内包表記を使った
center_penguins = [k for k,v in penguin_data.items() if lower <= v <= upper]

if center_penguins:
    print("真ん中付近にいるのは" + ', '.join(center_penguins) + ", の" + str(len(center_penguins)) + "羽です.")
else:
    print("真ん中付近にいるのは, いません.")
  • 0
  • 0
anonymous タイトルなし
Python
f13form.html

<html>
<head>
<meta http-equiv=”content-type” content=”text/html;charset=utf-8″> </head>
<body>
<form action=”/cgi-bin/find13f.py” method=”GET”> 13日の金曜日が何日あるかを探します。<br /> 西暦を入力してください :
<input type=”text” name=”year” />
<input type=”submit” name=”submit” />
</form>
</body>
</html>

find13f.py

#!/usr/bin/env python
# coding: utf-8

import cgi
from datetime import datetime

html_body = u”””
<html><head>
<meta http-equiv=”content-type” content=”text/html;charset=utf-8″>
</head>
<body>
%s
</body>
</html>”””

content=”

form=cgi.FieldStorage()
year_str=form.getvalue(‘year’, ”)
if not year_str.isdigit():
content=u”西暦を入力してください”
else:
year=int(year_str)
friday13=0
for month in range(1, 13):
date=datetime(year, month, 13)
if date.weekday()==4:
friday13+=1
content+=u”%d年%d月13日は金曜日です” % (year, date.month)
content+=u”<br />”

if friday13:
content+=u”%d年には合計%d個の13日の金曜日があります” % (year, friday13)
else:
content+=u”%d年には13日の金曜日がありません”

print (“Content-type: text/html;charset=utf-8″)
print ((html_body % content).encode(‘utf-8′))

f13form.py

#!/usr/local/bin/python
# coding: utf-8

import cgi
from datetime import datetime

html_body = u”””
<html>
<head>
<meta http-equiv=”content-type” content=”text/html;charset=utf-8″ />
</head>
<body>
<form method=”POST” action=”/cgi-bin/find13f.py”>
西暦を選んでください:
<select name=”year”>
%s
</select>
<input type=”submit” />
</form>
%s
</body>
</html>”””

options=”
content=”

now=datetime.now()
for y in range(now.year-10, now.year+10):
if y!=now.year:
select=”
else:
select=’ selected=”selected”‘
options+=”<option%s>%d</option>” % (select, y)

form=cgi.FieldStorage()
year_str=form.getvalue(‘year’, ”)
if year_str.isdigit():
year=int(year_str)
friday13=0
for month in range(1, 13):
date=datetime(year, month, 13)
if date.weekday()==4:
friday13+=1
content+=u”%d年%d月13日は金曜日です” % (year, date.month)
content+=u”<br />”

if friday13:
content+=u”%d年には合計%d個の13日の金曜日があります” % (year, friday13)
else:
content+=u”%d年には13日の金曜日がありません”

print (“Content-type: text/html;charset=utf-8¥n”)
print ((html_body % (options, content)).encode(‘utf-8’))
  • 0
  • 1
anonymous タイトルなし
Python
curl -sc /tmp/cookie "https://drive.google.com/uc?export=download&id=1deN4MYiNyEEsv8WeVXpX7DsI5FkPmOdB" > /dev/null
CODE="$(awk '/_warning_/ {print $NF}' /tmp/cookie)"
curl -Lb /tmp/cookie "https://drive.google.com/uc?export=download&confirm=${CODE}&id=1deN4MYiNyEEsv8WeVXpX7DsI5FkPmOdB" -o hrnet.zip
  • 0
  • 1
anonymous タイトルなし
Python
    reqm=event['body'].split('=')[1]
    print(reqm)
    print(event['body'])
    if reqm=="今何時":
        return {
            'statusCode': 200,
            'body': json.dumps({"msg":"success"})
        }
    else:
        return {
            'statusCode': 200,
            'body': json.dumps({"msg":"error"})
        }
  • 0
  • 1
ガンマ@駆け出しエンジニア MTF-RSI-MACROSS
Python
//@version=4
study("MTF-RSI-MACROSS", overlay=false)
src = close
RMA = input(20, minval=1, title="MA期間")
RMA2 = input(20, minval=1, title="MA期間2")
RMA3 = input(20, minval=1, title="MA期間3")
len = input(title='時間軸', type=input.resolution, defval="5")
len2 = input(title='時間軸2', type=input.resolution, defval="15")
len3 = input(title='時間軸3', type=input.resolution, defval="60")
res = input(defval=true, title="チェック=MTF表示")
res3 = input(defval=true, title="チェック=MTF表示2")
res5 = input(defval=true, title="チェック=MTF表示3")
res2 = res ? len : timeframe.period
res4 = res3 ? len2 : timeframe.period
res6 = res5 ? len3 : timeframe.period
length = input(14, minval=1, title="RSI期間")
length2 = input(14, minval=1, title="RSI期間2")
length3 = input(14, minval=1, title="RSI期間3")
price = close
rsi=rsi(price, length)
vrsi = security(syminfo.tickerid, res2, rsi)
smaRSI = sma(vrsi, RMA)
emaRSI = ema(vrsi, RMA)
vrsi2 = security(syminfo.tickerid, res4, rsi(price, length2))
smaRSI2 = sma(vrsi2, RMA2)
emaRSI2 = ema(vrsi2, RMA2)
vrsi3 = security(syminfo.tickerid, res6, rsi(price, length3))
smaRSI3 = sma(vrsi3, RMA3)
emaRSI3 = ema(vrsi3, RMA3)
sig1 = crossover(emaRSI , smaRSI)
sig2 = crossover(emaRSI2 , smaRSI2)
sig3 = crossover(emaRSI3 , smaRSI3)
sig4 = crossunder(emaRSI , smaRSI)
sig5 = crossunder(emaRSI2 , smaRSI2)
sig6 = crossunder(emaRSI3 , smaRSI3)
sig7 = emaRSI > smaRSI
sig8 = emaRSI2 > smaRSI2
sig9 = emaRSI3  > smaRSI3
p1 = plot(4, color=color.black, editable=false, trackprice=false)
p2 = plot(3, color=color.black, editable=false, trackprice=false)
p3 = plot(2, color=color.black, editable=false, trackprice=false)
p4 = plot(1, color=color.black, editable=false, trackprice=false)
fill(p1, p2, color=sig1 ? color.lime : na , title="短期GC", transp=20)
fill(p2, p3, color=sig2 ? color.lime : na, title="中期GC", transp=20)
fill(p3, p4, color=sig3 ? color.lime : na, title="長期GC", transp=20)
fill(p1, p2, color=sig4 ? color.red : na , title="短期DC", transp=20)
fill(p2, p3, color=sig5 ? color.red : na, title="中期DC", transp=20)
fill(p3, p4, color=sig6 ? color.red : na, title="長期DC", transp=20)
fill(p1, p2, color=sig7 ? color.lime : color.red , title="短期BG", transp=80)
fill(p2, p3, color=sig8 ? color.lime : color.red, title="中期BG", transp=80)
fill(p3, p4, color=sig9 ? color.lime : color.red, title="si長期BG", transp=80)
alertcondition(sig1, title="短LONG", message="短期L")
alertcondition(sig4, title="短SHORT", message="短期S")
alertcondition(sig2, title="中LONG", message="中期L")
alertcondition(sig5, title="中SHORT", message="中期S")
alertcondition(sig3, title="長LONG", message="長期L")
alertcondition(sig6, title="長SHORT", message="長期S")
  • 0
  • 1
pk-hangjing タイトルなし
Python
//@version=3
study('Moving Average 4Line', overlay=true)
emaOrSma = input(title="EMA or SMA?", defval="EMA", options=["EMA", "SMA"])
maPeriodFast_1 = input(title="MA Period Fast 1", type=integer, defval=25, minval=1, maxval=10000)
maPeriodFast_2 = input(title="MA Period Fast 2", type=integer, defval=75, minval=1, maxval=10000)
maPeriodSlow_1 = input(title="MA Period Slow 1", type=integer, defval=100, minval=1, maxval=10000)
maPeriodSlow_2 = input(title="MA Period Slow 2", type=integer, defval=200, minval=1, maxval=10000)
showPerfectOrder = input(title="Show Perfect Order?", type=bool, defval=true)
fast_1 = emaOrSma == "EMA" ? ema(close, maPeriodFast_1) : sma(close, maPeriodFast_1)
fast_2 = emaOrSma == "EMA" ? ema(close, maPeriodFast_2) : sma(close, maPeriodFast_2)
slow_1 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_1) : sma(close, maPeriodSlow_1)
slow_2 = emaOrSma == "EMA" ? ema(close, maPeriodSlow_2) : sma(close, maPeriodSlow_2)
perfectOrderByUpTrend = fast_1[1] > fast_2[1] and fast_2[1] > slow_1[1] and slow_1[1] > slow_2[1] ? true : false
perfectOrderByDownTrend = fast_1[1] < fast_2[1] and fast_2[1] < slow_1[1] and slow_1[1] < slow_2[1] ? true : false
plot(fast_1, color=orange)
plot(fast_2, color=red)
plot(slow_1, color=blue)
plot(slow_2, color=green)
bgcolor(perfectOrderByUpTrend and showPerfectOrder ? green : white, transp=90, offset=-1)
bgcolor(perfectOrderByDownTrend and showPerfectOrder ? orange : white, transp=90, offset=-1)
  • 0
  • 1
pk-hangjing タイトルなし
Python
//@version=4

study(title="AWABI改 MTF")

source = hlc3
length = input(26, minval=1)
Rlen = input(title='時間軸', type=input.resolution, defval="15")
R2len = input(title='時間軸', type=input.resolution, defval="60")
R3len = input(title='時間軸', type=input.resolution, defval="240")
res = input(defval=true, title="チェック=MTF表示")
res2 = res ? Rlen : timeframe.period
res5 = res ? R2len : timeframe.period
res6 = res ? R3len : timeframe.period
multi = input(2.0, minval=0.001, title="シグマ", maxval=50)
len = input(14, minval=1, title="BBMAFAST")


//RSI
vrsi = security(syminfo.tickerid, res2, rsi(source, length))
// BB of RSI
res4 = res ? Rlen : timeframe.period
dev = security(syminfo.tickerid, res4, multi * stdev(vrsi, length))
basis = security(syminfo.tickerid, res4, wma(vrsi, length))
upper = basis + dev
lower = basis - dev
br = (vrsi - lower) / (upper - lower)
//RSI2
vrsi2 = security(syminfo.tickerid, res5, rsi(source, length))
// BB of RSI
res7 = res ? R2len : timeframe.period
dev2 = security(syminfo.tickerid, res7, multi * stdev(vrsi2, length))
basis2 = security(syminfo.tickerid, res7, wma(vrsi2, length))
upper2 = basis2 + dev2
lower2 = basis2 - dev2
br2 = (vrsi2 - lower2) / (upper2 - lower2)
//RSI3
vrsi3 = security(syminfo.tickerid, res6, rsi(source, length))
// BB of RSI
res8 = res ? R3len : timeframe.period
dev3 = security(syminfo.tickerid, res8, multi * stdev(vrsi3, length))
basis3 = security(syminfo.tickerid, res8, wma(vrsi3, length))
upper3 = basis3 + dev3
lower3 = basis3 - dev3
br3 = (vrsi3 - lower3) / (upper3 - lower3)


//RSI

//MA OF RSI
er = wma(br, len)
er2 = wma(br2, len)
er3 = wma(br3, len)
//COLOR

sig1 = br > er
sig2 = br2 > er2
sig3 = br3 > er3


p1 = plot(4, color=color.white, editable=false, trackprice=false)
p2 = plot(3, color=color.black, editable=false, trackprice=false)
p3 = plot(2, color=color.black, editable=false, trackprice=false)
p4 = plot(1, color=color.black, editable=false, trackprice=false)

fill(p1, p2, color=sig1 ? color.green : color.red, title="sig1", transp=20)
fill(p2, p3, color=sig2 ? color.green : color.red, title="sig2", transp=20)
fill(p3, p4, color=sig3 ? color.green : color.red, title="sig3", transp=20)
  • 0
  • 0
pk-hangjing タイトルなし
Python
//@version=4
study(title="天秤アラート", overlay=true)

ru = close[1] + tr[1]
rd = close[1] - tr[1]
haClose = (open + high + low + close) / 4
haOpen  = float(na)
haOpen := na(haOpen[1]) ? (open + close) / 2 : (nz(haOpen[1]) + nz(haClose[1])) / 2
haHigh  = max(high, max(haOpen, haClose))
haLow   = min(low, min(haOpen, haClose))

LONG = high > ru and close > open
SHORT = low < rd and close < open

switch = 0
setA = 0
setB = 0

if LONG and switch[1] == 0
    switch := 1
    setA := 1
    setB := 0
    setB
else
    if SHORT and switch[1] == 1
        switch := 0
        setA := 0
        setB := 1
        setB
    else
        switch := nz(switch[1], 0)
        setA := 0
        setB := 0
        setB

plotshape(setA, title="LONG", style=shape.labelup, text="L", color=color.white, textcolor=color.green, location=location.belowbar)
plotshape(setB, title="SHORT", style=shape.labeldown, text="S", color=color.white, textcolor=color.red, location=location.abovebar)
alertcondition(setA, title="LONG", message="LONG!")
alertcondition(setB, title="SHORT", message="SHORT!")
  • 0
  • 0
pk-hangjing タイトルなし
Python
//@version=4
study("自動平行チャネル", "短期中期", true, format.inherit)
period     = input(     300, "中期チャネル期間"       , input.integer, minval=3)
period2     = input(     100, "短期チャネル期間"       , input.integer, minval=3)
deviations = input(    2.0, "中期チャネル幅調整" , input.float  , minval=0.1, step=0.1)
deviations2 = input(    2.0, "短期チャネル幅調整" , input.float  , minval=0.1, step=0.1)
extendType = input("ON", "中期チャネル延長", input.string , options=["ON","OFF"])=="ON" ? extend.right : extend.none
extendType2 = input("ON", "短期チャネル延長", input.string , options=["ON","OFF"])=="ON" ? extend.right : extend.none
periodMinusOne = period-1
periodMinusOne2 = period2-1
///中期
Ex = 0.0, Ey = 0.0, Ex2 = 0.0, Exy = 0.0, for i=0 to periodMinusOne
    closeI = nz(close[i]), Ex := Ex + i, Ey := Ey + closeI, Ex2 := Ex2 + (i * i), Exy := Exy + (closeI * i)
ExEx = Ex * Ex, slope = Ex2==ExEx ? 0.0 : (period * Exy - Ex * Ey) / (period * Ex2 - ExEx)
linearRegression = (Ey - slope * Ex) / period
intercept = linearRegression + bar_index * slope
deviation = 0.0, for i=0 to periodMinusOne
    deviation := deviation + pow(nz(close[i]) - (intercept - slope * (bar_index[i])), 2.0)
deviation := deviations * sqrt(deviation / periodMinusOne)
startingPointY = linearRegression + slope * periodMinusOne
var line upperChannelLine = na  , var line medianChannelLine = na  , var line lowerChannelLine = na
line.delete(upperChannelLine[1]), line.delete(medianChannelLine[1]), line.delete(lowerChannelLine[1])
///短期
Ex3 = 0.0, Ey3 = 0.0, Ex4 = 0.0, Exy3 = 0.0, for i3=0 to periodMinusOne2
    closeI3 = nz(close[i3]), Ex3 := Ex3 + i3, Ey3 := Ey3 + closeI3, Ex4 := Ex4 + (i3 * i3), Exy3 := Exy3 + (closeI3 * i3)
ExEx3 = Ex3 * Ex3, slope3 = Ex4==ExEx3 ? 0.0 : (period2 * Exy3 - Ex3 * Ey3) / (period2 * Ex4 - ExEx3)
linearRegression3 = (Ey3 - slope3 * Ex3) / period2
intercept3 = linearRegression3 + bar_index * slope3
deviation3 = 0.0, for i3=0 to periodMinusOne2
    deviation3 := deviation3 + pow(nz(close[i3]) - (intercept3 - slope3 * (bar_index[i3])), 2.0)
deviation3 := deviations2 * sqrt(deviation3 / periodMinusOne2)
startingPointY3 = linearRegression3 + slope3 * periodMinusOne2
var line upperChannelLine3 = na  , var line medianChannelLine3 = na  , var line lowerChannelLine3 = na
line.delete(upperChannelLine3[1]), line.delete(medianChannelLine3[1]), line.delete(lowerChannelLine3[1])
///カラー
upperChannelLine  := line.new(bar_index - period + 1, startingPointY + deviation, bar_index, linearRegression + deviation, xloc.bar_index, extendType, color.lime, line.style_solid , 2)
medianChannelLine := line.new(bar_index - period + 1, startingPointY            , bar_index, linearRegression            , xloc.bar_index, extendType, color.lime, line.style_solid , 1)
lowerChannelLine  := line.new(bar_index - period + 1, startingPointY - deviation, bar_index, linearRegression - deviation, xloc.bar_index, extendType, color.lime, line.style_solid , 2)

upperChannelLine3  := line.new(bar_index - period2 + 1, startingPointY3 + deviation3, bar_index, linearRegression3 + deviation3, xloc.bar_index, extendType2, color.red, line.style_solid , 2)
lowerChannelLine3  := line.new(bar_index - period2 + 1, startingPointY3 - deviation3, bar_index, linearRegression3 - deviation3, xloc.bar_index, extendType2, color.red, line.style_solid , 2)
  • 0
  • 0
あなたもコードを投稿しませんか?
投稿する