Advertisement
PineCoders

Strat not working

Apr 15th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. //@version=4
  2. strategy("Strategy Template", overlay=true)
  3.  
  4. //Enter Technical indicators here
  5. ki_Length = input(34, minval=1)
  6. //Calculation
  7. donchian(len) => avg(lowest(len), highest(len))
  8. ki_baseLine = donchian(ki_Length)
  9.  
  10. //entry rules
  11. ki_long = close[1]<ki_baseLine and close>ki_baseLine
  12. ki_short = close[1]>ki_baseLine and close<ki_baseLine
  13.  
  14. long = ki_long
  15. short = ki_short
  16. l_exit = close[1]<ki_baseLine
  17. s_exit = close[1]>ki_baseLine
  18.  
  19. ///*******************below is default enty no changes to the below while testing************
  20. longEntry = long
  21. shortEntry = short
  22. longExit = l_exit
  23. shortExit =s_exit
  24.  
  25. //backtest year from and to
  26. backtestyearfrom = input(2018, title="Backtesting Year from")
  27. baecktestyearto = input(2020, title="Bakctesting year to")
  28.  
  29. //risk management
  30. target = atr(14)*1/syminfo.mintick
  31. stop = atr(14)*1.5/syminfo.mintick
  32. contract = 100
  33.  
  34. plotchar(year >=backtestyearfrom and year <= baecktestyearto and (longEntry), "year >=backtestyearfrom and year <= baecktestyearto and (longEntry)", "▲", location.top)
  35.  
  36. //long
  37. if year >=backtestyearfrom and year <= baecktestyearto and (longEntry)
  38. strategy.entry("buy", strategy.long,contract, when = strategy.position_size==0)
  39. strategy.exit("lx","buy", qty = contract/2, profit = target, loss=stop)
  40. strategy.exit("lx2","buy", loss=stop, when = l_exit)
  41.  
  42. plotchar(year >=backtestyearfrom and year <= baecktestyearto and (shortEntry) , "year >=backtestyearfrom and year <= baecktestyearto and (shortEntry) ", "▲", location.top)
  43. plotchar(shortEntry, "shortEntry", "•", location.bottom)
  44.  
  45. //short
  46. if year >=backtestyearfrom and year <= baecktestyearto and (shortEntry)
  47. strategy.entry ("short", strategy.short,contract, when = strategy.position_size==0 )
  48. strategy.exit("sx1","short", qty = contract/2, profit = target, loss=stop)
  49. strategy.exit("sx2","short", loss=stop, when = s_exit)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement