Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- strategy("[STRATEGY][BO]ADX and DI R1.0 by JustUncleL",overlay=true,shorttitle="[STRATEGY]BO ADX+DI",pyramiding=10)
- // Author: JustUncleL
- // Date : 15-Dec-2017
- // Inspiration: @vicmoney4
- //
- // Description:
- // ------------
- // This is the Binary Options strategy based on the ADX and DI indicator.
- // The indicator creates signal arrow when the following conditions are forefilled:
- //
- // +DI crosses down -DI = PUT ARROW
- // +DI crosses down ADX = PUT ARROW
- // -DI crosses down ADX = CALL ARROW
- //
- // +DI crosses up -DI = CALL ARROW
- // +DI crosses up ADX = CALL ARROW
- // -DI crosses up ADX = PUT ARROW
- //
- // The arrow should will appear on the bar where the conditions are met on next candle OPEN
- // coordinates.
- //
- // Basic settings:
- //
- // Timeframe in use (Custom timeframes like 2min, 4min should be able to be used)
- // Number of bars to be traded (Minimum value; 1 (1 being the 1st bar))
- // Type of signal Options:
- // DI Cross = DI crosses only
- // ADX Cross = DI crossing ADX line only
- // DI+ADX Cross = All DI and ADX crosses
- // DI Cross+ADX Confirm = DI crosses where ADX<threshold
- // ADX Cross+ADX Confirm= ADX crosses confirmed as appropriate against threshold
- //
- //
- // -----------------------------------------------------------------------------
- // Copyright 2017 JustUncleL
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // The GNU General Public License can be found here
- // <http://www.gnu.org/licenses/>.
- //
- // -----------------------------------------------------------------------------
- //
- // === INPUTS ===
- //
- len = input(title="Length", type=integer, defval=14,minval=1)
- th = input(title="threshold", type=integer, defval=20,minval=0,maxval=100)
- uatf = input(false,title="Use Alternate Time Frame to generate Alerts")
- aperiod = input("5",type=string,title="Alternate Time Frame Period")
- //
- 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)
- //
- boExpiry = input(3,minval=1,title="Expiry Candles (for Binary Option)")
- boALL = input(false,title="Allow Muliple BO Trades to be Open")
- // Include bar limiting algorithm
- ebar = input(defval = 5000, title="Number of Bars for Back Testing", minval=0)
- dummy = input(false, title="- SET to ZERO for Daily or Longer Timeframes" )
- // === /INPUTS ===
- //
- // === SERIES ===
- 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):
- high-nz(high[1]) > nz(low[1])-low ? max(high-nz(high[1]), 0): 0
- 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):
- nz(low[1])-low > high-nz(high[1]) ? max(nz(low[1])-low, 0): 0
- //
- SmoothedTrueRange = 0.0
- SmoothedDirectionalMovementPlus = 0.0
- SmoothedDirectionalMovementMinus = 0.0
- SmoothedTrueRange := uatf? security(tickerid,aperiod, rma(tr,len), barmerge.gaps_off, barmerge.lookahead_off): rma(tr,len)
- SmoothedDirectionalMovementPlus := rma(DirectionalMovementPlus,len)
- SmoothedDirectionalMovementMinus := rma(DirectionalMovementMinus,len)
- //
- DIPlus = (SmoothedDirectionalMovementPlus / SmoothedTrueRange) * 100
- DIMinus = (SmoothedDirectionalMovementMinus / SmoothedTrueRange) * 100
- DX = (abs(DIPlus-DIMinus) / (DIPlus+DIMinus))*100
- ADX = sma(DX, len)
- // === /SERIES ===
- // === ALERT conditions
- longCond = op=="DI Cross"? crossover(DIPlus,DIMinus):
- op=="ADX Cross"? crossover(DIPlus,ADX) or crossunder(DIMinus,ADX):
- op=="DI+ADX Cross"? crossover(DIPlus,DIMinus) or crossover(DIPlus,ADX) or crossunder(DIMinus,ADX):
- op=="DI Cross+ADX Confirm"? crossover(DIPlus,DIMinus) and ADX<th :
- op=="ADX Cross+ADX Confirm"? (crossover(DIPlus,ADX) and ADX<th) or (crossunder(DIMinus,ADX) and ADX>th):false
- shortCond = op=="DI Cross"? crossunder(DIPlus,DIMinus):
- op=="ADX Cross"? crossover(DIMinus,ADX) or crossunder(DIPlus,ADX):
- op=="DI+ADX Cross"? crossunder(DIPlus,DIMinus) or crossunder(DIPlus,ADX) or crossover(DIMinus,ADX):
- op=="DI Cross+ADX Confirm"? crossunder(DIPlus,DIMinus) and ADX<th :
- op=="ADX Cross+ADX Confirm"? (crossover(DIMinus,ADX) and ADX<th) or (crossunder(DIPlus,ADX) and ADX>th): false
- //
- // --- debug
- //bc = longCond? green : shortCond?red : na
- //bgcolor(bc,transp=80)
- //
- // === /ALERT conditions.
- // === STRATEGY ===
- //
- // Calculate how many mars since last bar
- tdays = (timenow-time)/60000.0 // number of minutes since last bar
- 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
- //
- //set up entry conditions for Binary Options
- call = longCond==true
- put = shortCond==true
- // Restrict Backtesting Bars
- if (ebar==0 or tdays<=ebar)
- strategy.entry("CALL", strategy.long, when = call and (boALL or (not put and strategy.opentrades == 0)))
- strategy.close("CALL", when = call[boExpiry]) // exit after boExpiry bars
- strategy.entry("PUT", strategy.short, when = put and (boALL or (not call and strategy.opentrades == 0)))
- strategy.close("PUT", when = put[boExpiry]) // exit after boExpiry bars
- // === /STRATEGY ===
- // eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement