Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=2
- strategy("TDI JustUncleL MTF with Doji 1.7", initial_capital=100000000, currency="USD", default_qty_type=strategy.cash, default_qty_value=100000) //max_bars_back=150)
- lengthrsi=input(13)
- lengthband=input(34)
- lengthrsipl=input(2)
- lengthtradesl=input(7)
- lenH = input(5, minval=1, title="Price Action Channel Length")
- lenL = lenH
- rsiOSL= input(22, minval=0,maxval=49,title="RSI Oversold Level")
- rsiOBL= input(78, minval=51,maxval=100,title="RSI Overbought Level")
- strength = input(2,minval=1,maxval=3,step=1,title="Strength Level: (1)Strong (2)Medium (3)All")
- sgb = input(true, title="Check Box To Turn Bars Gray")
- sbr = input(true, title="Highlight TDI Alert Bars")
- sal = input(true, title="Show Alert Condition Status")
- uha = input(false, title="Use Heikin Ashi Candles for Calculations")
- //
- // Use only Heikinashi Candles for all calculations
- srcClose = uha ? security(heikinashi(tickerid), period, close) : close
- srcOpen = uha ? security(heikinashi(tickerid), period, open) : open
- srcHigh = uha ? security(heikinashi(tickerid), period, high) : high
- srcLow = uha ?security(heikinashi(tickerid), period, low) : low
- //
- r=rsi(srcClose, lengthrsi)
- ma=sma(r,lengthband)
- offs=(1.6185 * stdev(r, lengthband))
- upZone=ma+offs
- dnZone=ma-offs
- mid=(upZone+dnZone)/2
- mab=sma(r, lengthrsipl)
- mbb=sma(r, lengthtradesl)
- // HTF Code
- current_tf = interval
- higher_tf = iff(current_tf == 1 and isintraday, "5",
- iff(current_tf == 3 and isintraday, "10",
- iff(current_tf == 5 and isintraday, "15",
- iff(current_tf == 15 and isintraday, "60",
- iff(current_tf == 30 and isintraday, "120",
- iff(current_tf == 60 and isintraday, "240",
- iff(current_tf == 240 and isintraday, "720",
- iff(current_tf == 1 and isdaily, "5D",
- "15"))))))))
- srcClose_htf = security(tickerid, higher_tf, close)
- srcOpen_htf = security(tickerid, higher_tf, open)
- srcHigh_htf = security(tickerid, higher_tf, high)
- srcLow_htf = security(tickerid, higher_tf, low)
- //
- r_htf=rsi(srcClose_htf, lengthrsi)
- ma_htf=sma(r_htf,lengthband)
- offs_htf=(1.6185 * stdev(r_htf, lengthband))
- upZone_htf=ma_htf+offs_htf
- dnZone_htf=ma_htf-offs_htf
- mid_htf=(upZone_htf+dnZone_htf)/2
- mab_htf=sma(r_htf, lengthrsipl)
- mbb_htf=sma(r_htf, lengthtradesl)
- //
- hline(rsiOSL, color=red, linewidth=1)
- hline(50, color=black, linewidth=1)
- hline(rsiOBL, color=lime, linewidth=1)
- // Plot the TDI
- upl=plot(upZone, color=blue, title="VB Channel High",linewidth=2)
- dnl=plot(dnZone, color=blue, title="VB Channel Low",linewidth=2)
- midl=plot(mid, color=black, linewidth=2, title="MBL")
- mabl=plot(mab, color=green, linewidth=2, title="RSI PL")
- mbbl=plot(mbb, color=red, linewidth=2, title="TSL Signal")
- //create RSI TSL cloud to indicate trend direction.
- fill(mabl,mbbl, color=mab>mbb?green:red,transp=90)
- // Calculate Price Action Channel (PAC)
- smmaH = na(smmaH[1]) ? sma(srcHigh, lenH) : (smmaH[1] * (lenH - 1) + srcHigh) / lenH
- smmaL = na(smmaL[1]) ? sma(srcLow, lenL) : (smmaL[1] * (lenL - 1) + srcLow) / lenL
- //
- fastMA = input(title="MACD Fast MA Length", type = integer, defval = 5, minval = 2)
- slowMA = input(title="MACD Slow MA Length", type = integer, defval = 15, minval = 7)
- signal = input(title="MACD Signal Length",type=integer,defval=1,minval=1)
- umacd = input(true,title="Use MACD Filtering")
- //
- [currMacd,_,_] = macd(srcClose[0], fastMA, slowMA, signal)
- [prevMacd,_,_] = macd(srcClose[1], fastMA, slowMA, signal)
- macdH = currMacd > 0 ? currMacd > prevMacd ? 1 : -1 : currMacd < prevMacd ? -1 : 1
- //
- // Bar - Highlighting based on indication strength
- long= (not umacd or macdH>0) and mab > mbb and mab < rsiOBL and mab > rsiOSL and srcHigh > smmaH and srcClose > srcOpen ? mbb > mid ? 1 : mab>mid and mbb<mid ? 2 : mab<mid and mbb<mid ? 3 : 0: 0
- short= (not umacd or macdH<0) and mab < mbb and mab <rsiOBL and mab > rsiOSL and srcLow < smmaL and srcClose < srcOpen ? mbb < mid ? 1 : mab<mid and mbb>mid ? 2 :mab>mid and mbb>mid ? 3 : 0 : 0
- //
- barcolor(not sbr?na:long==1?blue: long==2 and strength>1?aqua:long==3 and strength>2?white: na, title="BUY Bars")
- barcolor(not sbr?na:short==1?red: short==2 and strength>1?orange:short==3 and strength>2? yellow : na, title="SELL Bars")
- //
- barcolor(sgb? gray : na)
- //
- // create alert only once per sequence type.
- //
- c_alert = (long>0 and long!=long[1] and long<=strength) or (short>0 and short!=short[1] and short<=strength)
- alertcondition(c_alert, title="TDIALT Alert", message="TDIALT Alert")
- // show dot only when alert condition is met and bar closed.
- plotshape(sal and c_alert[1],title= "Alert Indicator", location=location.bottom, color=long[1]==1? blue: long[1]==2?aqua: long[1]==3?white: short[1]==1?red: short[1]==2?orange: short[1]==3? yellow : na, transp=0, style=shape.circle,offset=-1)
- // CURRENCY STRENGTH CODE
- fast=input(5)
- slow=input(15)
- v1=security('EURGBP',period,close)
- v2=security('EURJPY',period,close)
- v3=security('EURUSD',period,close)
- v4=security('GBPJPY',period,close)
- v5=security('GBPUSD',period,close)
- v6=security('USDJPY',period,close)
- v7=security('EURCAD',period,close)
- v8=security('EURNZD',period,close)
- v9=security('EURCHF',period,close)
- v10=security('EURAUD',period,close)
- v11=security('GBPCAD',period,close)
- v12=security('GBPNZD',period,close)
- v13=security('GBPAUD',period,close)
- v14=security('GBPCHF',period,close)
- v15=security('USDCAD',period,close)
- v16=security('NZDUSD',period,close)
- v17=security('USDCHF',period,close)
- v18=security('AUDUSD',period,close)
- v19=security('AUDCAD',period,close)
- v20=security('AUDNZD',period,close)
- v21=security('AUDCHF',period,close)
- v22=security('AUDJPY',period,close)
- v23=security('NZDCAD',period,close)
- v24=security('NZDCHF',period,close)
- v25=security('NZDJPY',period,close)
- v26=security('CADCHF',period,close)
- v27=security('CADJPY',period,close)
- v28=security('CHFJPY',period,close)
- EUR=(v1+v2+v3+v7+v8+v9+v10)/7
- GBP=((100-v1)+v4+v5+v11+v12+v13+v14)/7
- JPY=((100-v2)+(100-v4)+(100-v6)+(100-v22)+(100-v25)+(100-v27)+(100-v28))/7
- USD=((100-v3) + (100-v5) + v6 + v15 + (100-v16) + v17 + (100-v18)) /7
- AUD=((100-v10)+(100-v12)+v18+v19+v20+v21+v22)/7
- NZD=((100-v8) + (100-v13) +v16 +(100-v20) +v23+v24+v25)/7
- CAD=((100-v7) + (100-v11) + (100-v15) + (100-v19) + (100-v23) + v26+v27)/7
- CHF=((100-v9) + (100-v14) + (100-v17) + (100-v21) + (100-v24) + (100-v26) + v28)/7
- eur=tsi(EUR,fast,slow)
- gbp=tsi(GBP,fast,slow)
- jpy=tsi(JPY,fast,slow)
- usd=tsi(USD,fast,slow)
- aud=tsi(AUD,fast,slow)
- nzd=tsi(NZD,fast,slow)
- cad=tsi(CAD,fast,slow)
- chf=tsi(CHF,fast,slow)
- pre = 0
- suf = 0
- if ticker == "EURUSD"
- pre := eur
- suf := usd
- if ticker == "GBPUSD"
- pre := gbp
- suf := usd
- if ticker == "USDJPY"
- pre := usd
- suf := jpy
- if ticker == "NZDUSD"
- pre := nzd
- suf := usd
- if ticker == "USDCAD"
- pre := usd
- suf := cad
- if ticker == "USDCHF"
- pre := usd
- suf := chf
- sep_val = abs(pre - suf)
- //plot(sep_val, color=white)
- //EOF
- // Created by Robert N. 030715
- // Candle labels
- //(title = "Candles", overlay = true)
- trend= input(5, minval=1, title="Trend in Bars")
- DojiSize = input(0.05, minval=0.01, title="Doji size")
- doji=(abs(open - close) <= (high - low) * DojiSize)
- plotchar(doji, title="Doji", text='Doji', color=white)
- barcolor(doji ? fuchsia : na)
- //1) TF2 (RSI_PL GREEN > TSL_Signal RED) and;
- //2) TF1 (RSI_PL > TSL_Signal) and (TSL_Signal > MBL) and (CS_Pre > CS_Suf) and (CS_SV > 0.1)
- open_long = mab_htf > mbb_htf and mab_htf > mid_htf and mab > mbb and mbb > mid and pre > suf and sep_val > 0.2
- open_short = mab_htf < mbb_htf and mab_htf < mid_htf and mab < mbb and mbb < mid and pre < suf and sep_val > 0.2
- //(CS_SV < 1) OR (TF1 (RSI_PL < TSL_Signal)
- close_long = (sep_val < 1) and (mab < mbb) and (mab < mab[1]) and doji
- close_short = (sep_val < 1) and (mab > mbb) and (mab > mab[1]) and doji
- // Code to avoid repeated buy or sell singals.
- buy_open = barssince(open_long) < barssince(open_short) and barssince(open_long) < barssince(close_long)
- sell_open = barssince(open_short) < barssince(open_long) and barssince(open_short) < barssince(close_short)
- plotshape(open_long and not buy_open[1], style=shape.triangleup, color=lime, size=size.normal, location=location.bottom, transp=0)
- plotshape(open_short and not sell_open[1], style=shape.triangledown, color=red, size=size.normal, location=location.top, transp=0)
- plotshape(close_long and not close_long[1] and buy_open[1] and not sell_open, style=shape.triangledown, color=green, size=size.small, location=location.top, transp=0)
- plotshape(close_short and not close_short[1] and sell_open[1] and not buy_open, style=shape.triangleup, color=maroon, size=size.small, location=location.bottom, transp=0)
- if ((year >= 2010) and (year <= 2016))
- strategy.close("short", when = close_short)
- //strategy.exit("short SL", "short", loss = lossinpoints)
- strategy.entry("short", strategy.short, when = open_short)
- if ((year >= 2010) and (year <= 2016))
- strategy.close("long", when = close_long)
- //strategy.exit("long SL", "long", loss = lossinpoints)
- strategy.entry("long", strategy.long, when = open_long)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement