Harigami
ログイン
anonymous タイトルなし
Python
//@version=3

study(title = "BBRSI", shorttitle = "BSI")

source = hlc3
length = input(20, minval=1), multi = input(2.0, minval=0.001,title="シグマ", maxval=50)
len = input(20, minval=1, title="移動平均線")

//RSI
rsi1 = rsi(source, length)

// BB of RSI
basis = sma(rsi1, length)
dev = multi * stdev(rsi1, length)
upper = basis + dev
lower = basis - dev
br = (rsi1 - lower)/(upper - lower)

//MA OF RSI
er = sma(br,len)

//COLOR
plot(br, color=aqua)
hb = hline(1, color=silver, linestyle=dashed)
lb = hline(0, color=silver, linestyle=dashed)
fill(hb, lb, color=green,transp=95)
plot(er, title="MA", style=circles, linewidth=1, color=orange)


  • 0
  • 0
anonymous ビット演算でフラグ管理をする
Python
state = 0b0000  # 初期状態

sleep = 0b0001  # 眠り
poison = 0b0010  # 毒
paralysis = 0b0100  # 麻痺
excitation = 0b1000  # 励起


# 眠り状態か判別
def isSleep(state):
    if state & 0b0001:
        return 'Sleep'
    else:
        return 'Not Sleep'


# 眠り状態にする
state = state | sleep
print(isSleep(state))

# 眠り状態を解く
state = state & ~ sleep
print(isSleep(state))
  • 0
  • 2
anonymous タイトルなし
Python
if true:
    print('Hello, World')
  • 0
  • 1
anonymous Tkinter
Python
from tkinter import *
from tkinter.colorchooser import askcolor
import sys


class Paint(object):

    DEFAULT_PEN_SIZE = 5.0
    DEFAULT_COLOR = 'black'

    def __init__(self):
        self.root = Tk()

        self.pen_button = Button(self.root, text=u'pen', command=self.use_pen)
        self.pen_button.grid(row=0, column=0)

        self.brush_button = Button(self.root, text='brush', command=self.use_brush)
        self.brush_button.grid(row=0, column=1)

        self.color_button = Button(self.root, text='color', command=self.choose_color)
        self.color_button.grid(row=0, column=2)

        self.eraser_button = Button(self.root, text='eraser', command=self.use_eraser)
        self.eraser_button.grid(row=0, column=3)
        
        self.undo_button = Button(self.root, text='戻る', command=self.undo)
        self.undo_button.grid(row=0, column=4)
        
        self.redo_button = Button(self.root, text='進む', command=self.redo)
        self.redo_button.grid(row=0, column=5)

        self.choose_size_button = Scale(self.root, from_=1, to=1000, orient=HORIZONTAL)
        self.choose_size_button.grid(row=0, column=6)
        
        # 自作
        self.size_box = Entry(width=20)
        self.size_box.grid(row=0, column=7)
        
        self.temp_size = 1
        
        self.decide_size_button = Button(self.root, text="サイズ決定", command=self.decide_size)
        self.decide_size_button.grid(row=0, column=8)
        
        #

        self.c = Canvas(self.root, bg='white', width=1400, height=800)
        #self.draw_zone = Canvas(self.root, bg='white', width=1400, height=800)
        self.c.grid(row=1, columnspan=4)

        self.setup()
        self.root.mainloop()

    def setup(self):
        self.old_x = None
        self.old_y = None
        self.line_width = self.choose_size_button.get()
        self.color = self.DEFAULT_COLOR
        self.eraser_on = False
        self.active_button = self.pen_button
        ################
        self.line_start_x = None
        self.line_start_y = None
        
        self.Line_objects = []
        self.temp_stack = []
        self.undo_stack = []
        self.redo_stack = []
        
        self.c.bind('<Button-1>', self.paint)#クリックを押した
        #self.c.bind('<Button-1>', self.line_start)#クリックを押した
        self.c.bind('<B1-Motion>', self.paint)#ドラッグした
        #self.c.bind('<B1-Motion>', self.line_motion)#ドラッグした
        self.c.bind('<ButtonRelease-1>', self.reset)#クリックを離した
        #self.c.bind('<ButtonRelease-1>', self.line_end)#クリックを離した
        ################
        
    #####################################################
    def line_start(self,event):
        self.line_start_x=event.x
        self.line_start_y=event.y
    def line_motion(self,event):
        self.c.delete('temp_line_objects')
        self.c.create_line(self.line_start_x,self.line_start_y,event.x,event.y,fill=self.DEFAULT_COLOR,smooth=1,tags='temp_line_objects')
    def line_end(self,event):
        x=self.c.create_line(self.line_start_x,self.line_start_y,event.x,event.y,fill=self.DEFAULT_COLOR,smooth=1)
        self.Line_objects.append(x)
        self.undo_stack.append(x)
        self.redo_stack.clear()#描き始めたらそれまでのredoスタックは削除
    #####################################################

    def use_pen(self):
        self.activate_button(self.pen_button)

    def use_brush(self):
        self.activate_button(self.brush_button)

    def choose_color(self):
        self.eraser_on = False
        self.color = askcolor(color=self.color)[1]

    def use_eraser(self):
        self.activate_button(self.eraser_button, eraser_mode=True)
        
    def erase(self):
        self.c.delete("temp")

    def activate_button(self, some_button, eraser_mode=False):
        self.active_button.config(relief=RAISED)
        some_button.config(relief=SUNKEN)
        self.active_button = some_button
        self.eraser_on = eraser_mode
        
    #
    def decide_size(self):
        self.line_width = self.size_box.get()
        #self.choose_size_button = self.size_box.get()
    #

    def paint(self, event):
        #
        if self.temp_size != self.choose_size_button.get():
            self.line_width = self.choose_size_button.get()
            self.temp_size = self.choose_size_button.get()
        #self.line_width = self.choose_size_button.get()
        
        #
        
        paint_color = 'white' if self.eraser_on else self.color
        if self.old_x and self.old_y:
            self.c.create_line(self.old_x, self.old_y, event.x, event.y,
                               width=self.line_width, fill=paint_color,
                               capstyle=ROUND, smooth=TRUE, splinesteps=36, tag="temp")
            z=self.c.create_line(self.old_x, self.old_y, event.x, event.y,
                               width=self.line_width, fill=paint_color,
                               capstyle=ROUND, smooth=TRUE, splinesteps=36)
            self.temp_stack.append(z)
        self.old_x = event.x
        self.old_y = event.y

    def reset(self, event):
        self.undo_stack.append(self.temp_stack)
        #self.temp_stack.clear()
        self.redo_stack.clear()#描き始めたらそれまでのredoスタックは削除
        self.old_x, self.old_y = None, None
        
    def undo(self):
        x = self.undo_stack.pop()
        while(self.temp_stack):
            y = self.temp_stack.pop()
            self.c.delete(y)
        
    def redo(self):
        x = 1


if __name__ == '__main__':
    Paint()
  • 0
  • 0
anonymous ABC124 B
Python
N = int(input())
H = list(map(int, input().split()))

res = 0
for i in range(len(H)):
    cnt = 0
    for j in range(0, i):
        if H[j] > H[i]:
            cnt += 1
    if cnt == 0:
        res += 1

print(res)
  • 0
  • 0
anonymous ABC123 A
Python
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

k = int(input())

ls = [a, b, c, d, e]

ans = 'Yay!'
for l in ls:
    for n in ls:
        if l - n > k:
            ans = ':('

print(ans)
  • 0
  • 0
anonymous タイトルなし
Python
//@version=3
study("DCCフィボナッチ", overlay=true)

//DCCF
len=input(37, "DCC期間")
h3=highest(high,len)
l3=lowest(low,len)  
len2=h3-l3        
h2=h3-len2*0.236    
h1=h3-len2*0.382   
l1=h3-len2*0.618    
l2=h3-len2*0.764    
basis= avg(l3, h3)
//ENTRY&ALERT
LONG = cross(high,h3) 
SHORT = cross(low,l3)

switch = 0
setA = 0
setB = 0

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

alertcondition(setA, title = "HIGHT", message = "HIGHT")
alertcondition(setB, title = "LOW", message = "LOW")
//COLOR
fill(plot(h3, title="+3σ"), plot(l3, title="-3σ"), color = aqua) 
fill(plot(h2, title="+2σ"), plot(l2, title="-2σ"), color = aqua) 
fill(plot(h1, title="+1σ"), plot(l1, title="-1σ"), color = aqua) 
plot(basis,color=orange,style=cross)

plotshape(setA,title="HIGHT",style=shape.triangleup,text="HI",color=blue,textcolor=blue,location=location.belowbar)
plotshape(setB,title="LOW",style=shape.triangledown,text="LO",color=red,textcolor=red,location=location.abovebar)
  • 0
  • 1
anonymous タイトルなし
Python
//@version=3
strategy("pivot reverse", overlay=true)

//pivot
len=4
len2=20
pL = input(len,minval=1,title="left")
pR = input(len2,minval=1,title="right")
SL     = input(true,title="line")
maxLvlLen        = input(20,minval=0, title="line")
pvthi = pivothigh(pL,pR)
pvtlo = pivotlow(pL,pR)
swh = pivothigh(pL, pR)
swl = pivotlow(pL, pR)

//entry
swh_cond = not na(swh)

hprice = 0.0
hprice := swh_cond ? swh : hprice[1]

le = false
le := swh_cond ? true : (le[1] and high > hprice ? false : le[1])

if (le)
    strategy.entry("BUY", strategy.long, comment="L", stop=hprice + syminfo.mintick)

swl_cond = not na(swl)

lprice = 0.0
lprice := swl_cond ? swl : lprice[1]


se = false
se := swl_cond ? true : (se[1] and low < lprice ? false : se[1])

if (se)
    strategy.entry("SEL", strategy.short, comment="S", stop=lprice - syminfo.mintick)

//coler&etc.

counthi = 0.0 
counthi := pvthi[1] ? 0 : nz(counthi[1])+1
countlo = 0.0
countlo := pvtlo[1] ? 0 : nz(countlo[1])+1
pvthis = 0.0
pvthis := pvthi[1] ? high[pR+1] : pvthis[1]
pvtlos = 0.0
pvtlos := pvtlo[1] ? low[pR+1] :  pvtlos[1]
hipc = (pvthis != pvthis[1]) ? na : blue
lopc = (pvtlos != pvtlos[1]) ? na: red
h2l= (pvthis+pvtlos)/2
plot(SL and (maxLvlLen==0 or counthi<maxLvlLen)? pvthis : na, color=hipc, transp=30, linewidth=1, offset=-pR-1, title="H-line", trackprice=false)
plot(SL and (maxLvlLen==0 or countlo<maxLvlLen)? pvtlos : na, color=lopc, transp=30, linewidth=1, offset=-pR-1, title="L-line", trackprice=false)
  • 2
  • 0
LC23 タイトルなし
Python
//@version=3
strategy("CB", overlay=true)
len=37
//DCC
i2 = input(len, "DCC", type=integer, minval=3)
eh = highest(high,i2)
el = lowest(low,i2)
r = eh - el
k = (close - el) / r
upBound = highest(high, i2)
downBound = lowest(low, i2)

//ENTRY
if (not na(close[i2]))
    strategy.entry("CBL", strategy.long, stop=upBound + syminfo.mintick, comment="L")
    strategy.entry("ChS", strategy.short, stop=downBound - syminfo.mintick, comment="S")


//COLOR
P1 = plot(eh,color=aqua)
P2 = plot(el,color=aqua)
fill(P1 , P2 ,color=aqua)
  • 0
  • 1
anonymous タイトルなし
Python
//@version=3
strategy("CB", overlay=true)
len=37
//DCC
i2 = input(len, "DCC", type=integer, minval=3)
eh = highest(high,i2)
el = lowest(low,i2)
r = eh - el
k = (close - el) / r
upBound = highest(high, i2)
downBound = lowest(low, i2)

//ENTRY
if (not na(close[i2]))
    strategy.entry("CBL", strategy.long, stop=upBound + syminfo.mintick, comment="L")
    strategy.entry("ChS", strategy.short, stop=downBound - syminfo.mintick, comment="S")


//COLOR
P1 = plot(eh,color=aqua)
P2 = plot(el,color=aqua)
fill(P1 , P2 ,color=aqua)
  • 0
  • 0
あなたもコードを投稿しませんか?
投稿する