Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- strategy("Strategy Template", overlay=true)
- //Enter Technical indicators here
- ki_Length = input(34, minval=1)
- //Calculation
- donchian(len) => avg(lowest(len), highest(len))
- ki_baseLine = donchian(ki_Length)
- //entry rules
- ki_long = close[1]<ki_baseLine and close>ki_baseLine
- ki_short = close[1]>ki_baseLine and close<ki_baseLine
- long = ki_long
- short = ki_short
- l_exit = close[1]<ki_baseLine
- s_exit = close[1]>ki_baseLine
- ///*******************below is default enty no changes to the below while testing************
- longEntry = long
- shortEntry = short
- longExit = l_exit
- shortExit =s_exit
- //backtest year from and to
- backtestyearfrom = input(2018, title="Backtesting Year from")
- baecktestyearto = input(2020, title="Bakctesting year to")
- //risk management
- target = atr(14)*1/syminfo.mintick
- stop = atr(14)*1.5/syminfo.mintick
- contract = 100
- plotchar(year >=backtestyearfrom and year <= baecktestyearto and (longEntry), "year >=backtestyearfrom and year <= baecktestyearto and (longEntry)", "▲", location.top)
- //long
- if year >=backtestyearfrom and year <= baecktestyearto and (longEntry)
- strategy.entry("buy", strategy.long,contract, when = strategy.position_size==0)
- strategy.exit("lx","buy", qty = contract/2, profit = target, loss=stop)
- strategy.exit("lx2","buy", loss=stop, when = l_exit)
- plotchar(year >=backtestyearfrom and year <= baecktestyearto and (shortEntry) , "year >=backtestyearfrom and year <= baecktestyearto and (shortEntry) ", "▲", location.top)
- plotchar(shortEntry, "shortEntry", "•", location.bottom)
- //short
- if year >=backtestyearfrom and year <= baecktestyearto and (shortEntry)
- strategy.entry ("short", strategy.short,contract, when = strategy.position_size==0 )
- strategy.exit("sx1","short", qty = contract/2, profit = target, loss=stop)
- strategy.exit("sx2","short", loss=stop, when = s_exit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement