Advertisement
JustUncleL

STRATEGY][BO]ADX and DI R1.0 by JustUncleL

Dec 17th, 2017
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.94 KB | None | 0 0
  1. //@version=3
  2.  
  3. strategy("[STRATEGY][BO]ADX and DI R1.0 by JustUncleL",overlay=true,shorttitle="[STRATEGY]BO ADX+DI",pyramiding=10)
  4.  
  5. // Author: JustUncleL
  6. // Date : 15-Dec-2017
  7. // Inspiration: @vicmoney4
  8. //
  9. // Description:
  10. // ------------
  11. // This is the Binary Options strategy based on the ADX and DI indicator.
  12. // The indicator creates signal arrow when the following conditions are forefilled:
  13. //
  14. // +DI crosses down -DI = PUT ARROW
  15. // +DI crosses down ADX = PUT ARROW
  16. // -DI crosses down ADX = CALL ARROW
  17. //
  18. // +DI crosses up -DI = CALL ARROW
  19. // +DI crosses up ADX = CALL ARROW
  20. // -DI crosses up ADX = PUT ARROW
  21. //
  22. // The arrow should will appear on the bar where the conditions are met on next candle OPEN
  23. // coordinates.
  24. //
  25. // Basic settings:
  26. //
  27. // Timeframe in use (Custom timeframes like 2min, 4min should be able to be used)
  28. // Number of bars to be traded (Minimum value; 1 (1 being the 1st bar))
  29. // Type of signal Options:
  30. // DI Cross = DI crosses only
  31. // ADX Cross = DI crossing ADX line only
  32. // DI+ADX Cross = All DI and ADX crosses
  33. // DI Cross+ADX Confirm = DI crosses where ADX<threshold
  34. // ADX Cross+ADX Confirm= ADX crosses confirmed as appropriate against threshold
  35. //
  36. //
  37. // -----------------------------------------------------------------------------
  38. // Copyright 2017 JustUncleL
  39. //
  40. // This program is free software: you can redistribute it and/or modify
  41. // it under the terms of the GNU General Public License as published by
  42. // the Free Software Foundation, either version 3 of the License, or
  43. // any later version.
  44. //
  45. // This program is distributed in the hope that it will be useful,
  46. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  47. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  48. // GNU General Public License for more details.
  49. //
  50. // The GNU General Public License can be found here
  51. // <http://www.gnu.org/licenses/>.
  52. //
  53. // -----------------------------------------------------------------------------
  54. //
  55.  
  56. // === INPUTS ===
  57. //
  58. len = input(title="Length", type=integer, defval=14,minval=1)
  59. th = input(title="threshold", type=integer, defval=20,minval=0,maxval=100)
  60. uatf = input(false,title="Use Alternate Time Frame to generate Alerts")
  61. aperiod = input("5",type=string,title="Alternate Time Frame Period")
  62. //
  63. op = input("DI+ADX Cross",title="Type of Signal :",options=["DI Cross","ADX Cross","DI+ADX Cross","DI Cross+ADX Confirm","ADX Cross+ADX Confirm"],type=string)
  64. //
  65. boExpiry = input(3,minval=1,title="Expiry Candles (for Binary Option)")
  66. boALL = input(false,title="Allow Muliple BO Trades to be Open")
  67. // Include bar limiting algorithm
  68. ebar = input(defval = 5000, title="Number of Bars for Back Testing", minval=0)
  69. dummy = input(false, title="- SET to ZERO for Daily or Longer Timeframes" )
  70.  
  71. // === /INPUTS ===
  72. //
  73. // === SERIES ===
  74.  
  75. DirectionalMovementPlus = uatf? security(tickerid,aperiod, high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0, barmerge.gaps_off, barmerge.lookahead_off):
  76. high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
  77. DirectionalMovementMinus = uatf? security(tickerid,aperiod, nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0, barmerge.gaps_off, barmerge.lookahead_off):
  78. nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0
  79. //
  80. SmoothedTrueRange = 0.0
  81. SmoothedDirectionalMovementPlus = 0.0
  82. SmoothedDirectionalMovementMinus = 0.0
  83. SmoothedTrueRange := uatf? security(tickerid,aperiod, rma(tr,len), barmerge.gaps_off, barmerge.lookahead_off): rma(tr,len)
  84. SmoothedDirectionalMovementPlus := rma(DirectionalMovementPlus,len)
  85. SmoothedDirectionalMovementMinus := rma(DirectionalMovementMinus,len)
  86. //
  87. DIPlus = (SmoothedDirectionalMovementPlus / SmoothedTrueRange) * 100
  88. DIMinus = (SmoothedDirectionalMovementMinus / SmoothedTrueRange) * 100
  89. DX = (abs(DIPlus-DIMinus) / (DIPlus+DIMinus))*100
  90. ADX = sma(DX, len)
  91. // === /SERIES ===
  92.  
  93.  
  94. // === ALERT conditions
  95. longCond = op=="DI Cross"? crossover(DIPlus,DIMinus):
  96. op=="ADX Cross"? crossover(DIPlus,ADX) or crossunder(DIMinus,ADX):
  97. op=="DI+ADX Cross"? crossover(DIPlus,DIMinus) or crossover(DIPlus,ADX) or crossunder(DIMinus,ADX):
  98. op=="DI Cross+ADX Confirm"? crossover(DIPlus,DIMinus) and ADX<th :
  99. op=="ADX Cross+ADX Confirm"? (crossover(DIPlus,ADX) and ADX<th) or (crossunder(DIMinus,ADX) and ADX>th):false
  100. shortCond = op=="DI Cross"? crossunder(DIPlus,DIMinus):
  101. op=="ADX Cross"? crossover(DIMinus,ADX) or crossunder(DIPlus,ADX):
  102. op=="DI+ADX Cross"? crossunder(DIPlus,DIMinus) or crossunder(DIPlus,ADX) or crossover(DIMinus,ADX):
  103. op=="DI Cross+ADX Confirm"? crossunder(DIPlus,DIMinus) and ADX<th :
  104. op=="ADX Cross+ADX Confirm"? (crossover(DIMinus,ADX) and ADX<th) or (crossunder(DIPlus,ADX) and ADX>th): false
  105. //
  106. // --- debug
  107. //bc = longCond? green : shortCond?red : na
  108. //bgcolor(bc,transp=80)
  109. //
  110. // === /ALERT conditions.
  111.  
  112. // === STRATEGY ===
  113. //
  114. // Calculate how many mars since last bar
  115. tdays = (timenow-time)/60000.0 // number of minutes since last bar
  116. tdays := ismonthly? tdays/1440.0/5.0/4.3/interval : isweekly? tdays/1440.0/5.0/interval : isdaily? tdays/1440.0/interval : tdays/interval // number of bars since last bar
  117. //
  118.  
  119. //set up entry conditions for Binary Options
  120. call = longCond==true
  121. put = shortCond==true
  122.  
  123. // Restrict Backtesting Bars
  124. if (ebar==0 or tdays<=ebar)
  125. strategy.entry("CALL", strategy.long, when = call and (boALL or (not put and strategy.opentrades == 0)))
  126. strategy.close("CALL", when = call[boExpiry]) // exit after boExpiry bars
  127. strategy.entry("PUT", strategy.short, when = put and (boALL or (not call and strategy.opentrades == 0)))
  128. strategy.close("PUT", when = put[boExpiry]) // exit after boExpiry bars
  129.  
  130.  
  131. // === /STRATEGY ===
  132. // eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement