Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. //@version=4
  2. strategy("SugarBot_V4[BETA](6hr)", shorttitle="SugarBot_V4[BETA](6hr)", overlay=true, initial_capital=100, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=2)
  3. //**********************************************************************************************************************************************************************************
  4. length = input(title="Length of SWMA", type=input.integer, defval=65) // Best Value: 65 &&& DRAWDOWN MIN: UNKNOWN
  5. highlightMovements = input(title="Highlight Movements ?", type=input.bool, defval=true)
  6. src = input(title="Source", type=input.source, defval=close)
  7. PI = 2 * asin(1)
  8. sum = 0.0
  9. weightSum = 0.0
  10. for i = 0 to length - 1 by 1
  11. weight = sin((i + 1) * PI / (length + 1))
  12. sum := sum + nz(src[i]) * weight
  13. weightSum := weightSum + weight
  14. weightSum
  15. swma = sum / weightSum
  16. swmaColor = highlightMovements ? swma > swma[1] ? color.green : color.red : #6D1E7F
  17. plot(swma, title="SWMA", linewidth=2, color=swmaColor, transp=0)
  18. // I have the Sine Weighted Moving average function (above) here as a basis for a primary entry indicator later
  19. //*********************************************************************************************************************************************************************************
  20. ema1 = input(title="lenght ema1", defval=66) // Best Value: 66 &&& DRAWDOWN MIN: 66
  21. roc1 = input(title="lenght roc of ema1", defval=66) // Best Value: 68 &&& DRAWDOWN MIN: 66
  22. ema2 = input(title="lenght ema2 on roc1", defval=43) // Best value: 53, 32 &&& DRAWDOWN MIN: 45
  23. ema3 = input(title="lenght ema3 on roc1", defval=25) // best Value: 26 &&& DRAWDOWN MIN: 22
  24. roc3 = input(title="lenght roc on swma", defval=101) // Best value: UNKNOWN &&& DRAWDOWN MIN: UNKNOWN
  25. ema4 = input(title="lenght ema4 on roc of SWMA", defval=37) // Best value: 32 &&& DRAWDOWN MIN: 37
  26. roc2 = input(title="lenght roc on roc", defval=101) // Best value: 70, 68 &&& DRAWDOWN MIN: 101
  27.  
  28.  
  29. //roc1 is used to determine when price action is changing direction.
  30. //roc2 is used later to determine parabolic moments of inflection that are useful in selling tops or covering bottoms
  31. //roc3 is used to maintain a level of abstraction from the SWMA, which is useful in trading choppy markets
  32. //ema4 is used in our analysis of the abstracted data obtained from SWMA
  33.  
  34. ema1Val = ema(close, ema1)
  35. roc1Val = roc(ema1Val, roc1)
  36. roc2Val = roc(roc1Val, roc2)
  37. roc3Val = roc(swma, roc3)
  38. ema2Val = ema(roc1Val, ema2)
  39. ema3Val = ema(roc1Val, ema3)
  40. ema4Val = ema(roc3Val, ema4)
  41.  
  42. conditionBuy1 = crossover(roc1Val, ema2Val)
  43. conditionSell1 = crossunder(roc1Val, ema2Val)
  44. conditionBuy2 = crossover(roc1Val, ema3Val)
  45. conditionSell2 = crossunder(roc1Val, ema3Val)
  46. conditionBuy3 = crossover(roc3Val, ema4Val)
  47. conditionSell3 = crossunder(roc3Val, ema4Val)
  48. conditionCloseLong = crossunder(roc2Val, roc1Val)
  49. conditionCloseShort = crossover(roc2Val, roc1Val)
  50.  
  51.  
  52. startDay = input(defval=1, title="Start Day")
  53. startMonth = input(defval=1, title="Start Month")
  54. startYear = input(defval=2018, title="Start Year")
  55. endDay = input(defval=31, title="End Day")
  56. endMonth = input(defval=12, title="End Month")
  57. endYear = input(defval=2019, title="End Year")
  58.  
  59. start = timestamp(startYear, startMonth, startDay, 00, 00) // backtest start window
  60. finish = timestamp(endYear, endMonth, endDay, 23, 59) // backtest finish window
  61. window() => // create function "within window of time"
  62. time >= start and time <= finish ? true : false
  63.  
  64.  
  65. if window()
  66. strategy.entry("buy", strategy.long, when=conditionBuy1[1] or conditionBuy2[1] or conditionBuy3[1])
  67. strategy.entry("sell", strategy.short, when=conditionSell1[1] or conditionSell2[1] or conditionSell3[1])
  68. strategy.close_all(when=conditionCloseLong)
  69. strategy.close_all(when=conditionCloseShort)
  70. //alertcondition(conditionBuy, "LONG", "roc crossover ema -> long")
  71. //alertcondition(conditionSell, "SHORT", "roc crossunder ema -> short")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement