ddcpb

Binary Option EMA/Stoch Strat (timeframe not working)

Sep 29th, 2020
1,495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //@version=2
  2. strategy("Binary Option EMA/Stoch Strat - Drew", overlay=true)
  3.  
  4. //stoch
  5.  
  6. length1 = input(14, minval=1), smoothK = input(1, minval=1), smoothD = input(3, minval=1)
  7. k = sma(stoch(close, high, low, length1), smoothK)
  8. d = sma(k, smoothD)
  9.  
  10.  
  11. len = input(4, minval=1, title="Length")
  12. src = input(high, title="Source")
  13. out = ema(src, len)
  14. HIGH = out
  15.  
  16. len1 = input(4, minval=1, title="Length")
  17. src1 = input(low, title="Source")
  18. out1 = ema(src1, len1)
  19. LOW = out1
  20.  
  21.  
  22. HL2 = (HIGH+LOW)/2
  23.  
  24. len2 = input(21, minval=1, title="Length")
  25. src2 = input(close, title="Source")
  26. out2 = ema(src2, len2)
  27. EMA = out2
  28.  
  29. timeframe = input(title="Timeframe", type=integer, minval=1, defval=3)
  30.  
  31.  
  32. x = close < LOW and open < HL2 and close < EMA  and d < 50 and k < 50
  33.  
  34. y =   close > HIGH and open > HL2 and close > EMA and d > 50 and k > 50
  35.  
  36. if (x)
  37.     strategy.entry("UP", strategy.long)
  38.  
  39. if (y)
  40.     strategy.entry("DOWN", strategy.short)
  41.  
  42. // original expiry tie code (doesn't work properly)
  43. //bars = barssince(strategy.opentrades == 0)
  44. //strategy.close_all(when=(bars>=timeframe))
  45.  
  46. // new expiry time code (still not working)    
  47. opened_order = strategy.position_size[0] != strategy.position_size[1] and strategy.position_size[0] != 0
  48. bars = barssince(opened_order) + 1
  49. strategy.close_all(when=(bars>=timeframe))
Advertisement
Add Comment
Please, Sign In to add comment