Advertisement
JustUncleL

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

Dec 17th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.22 KB | None | 0 0
  1. //@version=3
  2.  
  3. study("[ALERT][BO]ADX and DI R1.0 by JustUncleL",overlay=false,shorttitle="[ALERT][BO]ADX+DI")
  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. // === Plotting ===
  94.  
  95. plot(DIPlus, color=green, title="DI+")
  96. plot(DIMinus, color=red, title="DI-")
  97. plot(ADX, color=black, title="ADX")
  98. hline(th, color=black, linestyle=dashed)
  99.  
  100. // === /Plotting ===
  101.  
  102. // === ALERT conditions
  103. longCond = op=="DI Cross"? crossover(DIPlus,DIMinus):
  104. op=="ADX Cross"? crossover(DIPlus,ADX) or crossunder(DIMinus,ADX):
  105. op=="DI+ADX Cross"? crossover(DIPlus,DIMinus) or crossover(DIPlus,ADX) or crossunder(DIMinus,ADX):
  106. op=="DI Cross+ADX Confirm"? crossover(DIPlus,DIMinus) and ADX<th :
  107. op=="ADX Cross+ADX Confirm"? (crossover(DIPlus,ADX) and ADX<th) or (crossunder(DIMinus,ADX) and ADX>th):false
  108. shortCond = op=="DI Cross"? crossunder(DIPlus,DIMinus):
  109. op=="ADX Cross"? crossover(DIMinus,ADX) or crossunder(DIPlus,ADX):
  110. op=="DI+ADX Cross"? crossunder(DIPlus,DIMinus) or crossunder(DIPlus,ADX) or crossover(DIMinus,ADX):
  111. op=="DI Cross+ADX Confirm"? crossunder(DIPlus,DIMinus) and ADX<th :
  112. op=="ADX Cross+ADX Confirm"? (crossover(DIMinus,ADX) and ADX<th) or (crossunder(DIPlus,ADX) and ADX>th): false
  113. // === /ALERT conditions.
  114.  
  115. // === STRATEGY ===
  116. //
  117. // Calculate how many mars since last bar
  118. tdays = (timenow-time)/60000.0 // number of minutes since last bar
  119. 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
  120. //
  121.  
  122. ctimer = 0
  123. ptimer = 0
  124. //
  125. // Signal only when previous BO trade closed
  126. call = longCond ? nz(ctimer[1])>boExpiry or (nz(ctimer[1])==0 and nz(ptimer[1])==0)? true : false : false
  127. put = shortCond ? nz(ptimer[1])>boExpiry or (nz(ptimer[1])==0 and nz(ctimer[1])==0)? true : false : false
  128. ctimer := call? 1 : nz(ctimer[1])==0 or nz(ctimer[1])>boExpiry? 0 : ctimer[1]+1
  129. ptimer := put? 1 : nz(ptimer[1])==0 or nz(ptimer[1])>boExpiry? 0 : ptimer[1]+1
  130.  
  131. // Signal All
  132. ctimer := not boAll? ctimer: longCond? 1 : 0
  133. ptimer := not boAll? ptimer: shortCond? 1 : 0
  134.  
  135. //
  136. bc = ctimer==1? green : ptimer==1?red : na
  137. bgcolor(bc,transp=80)
  138.  
  139. //
  140. alertcondition(ctimer==1,message="CALL",title="CALL")
  141. alertcondition(ptimer==1,message="PUT",title="PUT")
  142.  
  143. // eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement