Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © ysantur
- //@version=4
- strategy("Yeşillim strategy", overlay = true , precision = 7, max_bars_back = 500,pyramiding = 0, initial_capital = 1000, currency = currency.USD, default_qty_type = strategy.cash, default_qty_value = 500, commission_type = "percent", commission_value = 0.1, calc_on_every_tick=false, process_orders_on_close=false)
- // === INPUT BACKTEST RANGE ===
- fromMonth = input(defval = 1, title = "From Month", type = input.integer, minval = 1, maxval = 12)
- fromDay = input(defval = 1, title = "From Day", type = input.integer, minval = 1, maxval = 31)
- fromYear = input(defval = 2021, title = "From Year", type = input.integer, minval = 1970)
- thruMonth = input(defval = 1, title = "Thru Month", type = input.integer, minval = 1, maxval = 12)
- thruDay = input(defval = 1, title = "Thru Day", type = input.integer, minval = 1, maxval = 31)
- thruYear = input(defval = 2112, title = "Thru Year", type = input.integer, minval = 1970)
- // === INPUT SHOW PLOT ===
- showDate = input(defval = true, title = "Show Date Range", type = input.bool)
- // === FUNCTION EXAMPLE ===
- start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start window
- finish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish window
- window() => time >= start and time <= finish ? true : false // create function "within window of time"
- src = (close*2+high+low+open)/5
- depth = input(title="Depth", type=input.integer, defval=10)
- smooth = input(title="Smooth", type=input.integer, defval=9)
- bias = input(title="Bias", type=input.float, step=0.1, defval=0.3)
- up=(100+bias)/100
- down=(100-bias)/100
- f=array.new_int(depth+1)
- W=array.new_float(depth)
- a=1
- b=1
- sum=0.0
- for i=0 to depth
- array.set(f,i,a+b)
- a:=b
- b:=array.get(f,i)
- x=0.0
- for i=1 to depth-1
- array.set(W,i,array.get(f,depth-1)/array.get(f,i))
- sum:=sum+array.get(f,depth-1)/array.get(f,i)
- for i=1 to depth-1
- x:=x+array.get(W,depth-i) * src
- x:=x/sum
- x:=ema(x,8)
- y=ema(x,3)
- e1 = stdev(x, 3)
- e2 = stdev(x, 8)
- u=x+e1
- l=x-2*(e1+e2)
- buySignal = crossover(src, x)
- sellSignal = crossunder(src, y)
- //plotshape(buySignal,text="Buy",style=shape.labelup, size=size.tiny,color=color.green, textcolor=color.white)
- //plotshape(sellSignal,text="Sell",style=shape.labeldown, size=size.tiny,color=color.red, textcolor=color.white)
- renk=color.yellow
- if (crossover(src, x) or src>=x ) or src>=y
- renk:=color.green
- if (crossunder(src, y) or src<y)
- renk:=color.red
- plot(l,color=renk, linewidth=3)
- longCond = bool(na)
- shortCond = bool(na)
- //longCond := (crossover(src, x) or src>=x ) or src>=y
- //shortCond := (crossunder(src, y) or src<y)
- longCond := crossover(src, x)
- shortCond := crossunder(src, y)
- CondIni = 0
- CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
- long = longCond and CondIni[1] == -1
- short = shortCond and CondIni[1] == 1
- plotshape(long, title="BUY", text="B", style=shape.labeldown, textcolor=color.white, size=size.auto, location=location.top, color=color.green, transp=0)
- plotshape(short, title="SELL", text="S", style=shape.labelup, textcolor=color.white, size=size.auto, location=location.bottom, color=color.red, transp=0)
- strategy.entry(id="Long Entry", comment="buy", long=true, when=long and window() )
- strategy.close("Long Entry", comment="sell", when=short and window() )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement