Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.15 KB | None | 0 0
  1. //@version=2
  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)
  3. sep_thresh = input(title="Sep Val Threshold for Entries", type=float, defval=0.2, minval=0, step=0.01)
  4. lengthrsi=input(13)
  5. lengthband=input(34)
  6. lengthrsipl=input(2)
  7. lengthtradesl=input(7)
  8. lenH = input(5, minval=1, title="Price Action Channel Length")
  9. lenL = lenH
  10. rsiOSL= input(22, minval=0,maxval=49,title="RSI Oversold Level")
  11. rsiOBL= input(78, minval=51,maxval=100,title="RSI Overbought Level")
  12. strength = input(2,minval=1,maxval=3,step=1,title="Strength Level: (1)Strong (2)Medium (3)All")
  13. sgb = input(true, title="Check Box To Turn Bars Gray")
  14. sbr = input(true, title="Highlight TDI Alert Bars")
  15. sal = input(true, title="Show Alert Condition Status")
  16. uha = input(false, title="Use Heikin Ashi Candles for Calculations")
  17. //
  18. // Use only Heikinashi Candles for all calculations
  19. srcClose = uha ? security(heikinashi(tickerid), period, close) : close
  20. srcOpen = uha ? security(heikinashi(tickerid), period, open) : open
  21. srcHigh = uha ? security(heikinashi(tickerid), period, high) : high
  22. srcLow = uha ?security(heikinashi(tickerid), period, low) : low
  23. //
  24. r=rsi(srcClose, lengthrsi)
  25. ma=sma(r,lengthband)
  26. offs=(1.6185 * stdev(r, lengthband))
  27. upZone=ma+offs
  28. dnZone=ma-offs
  29. mid=(upZone+dnZone)/2
  30. mab=sma(r, lengthrsipl)
  31. mbb=sma(r, lengthtradesl)
  32.  
  33. // HTF Code
  34.  
  35. current_tf = interval
  36. higher_tf = iff(current_tf == 1 and isintraday, "5",
  37. iff(current_tf == 3 and isintraday, "10",
  38. iff(current_tf == 5 and isintraday, "15",
  39. iff(current_tf == 15 and isintraday, "60",
  40. iff(current_tf == 30 and isintraday, "120",
  41. iff(current_tf == 60 and isintraday, "240",
  42. iff(current_tf == 240 and isintraday, "720",
  43. iff(current_tf == 1 and isdaily, "5D",
  44. "15"))))))))
  45.  
  46. srcClose_htf = security(tickerid, higher_tf, close)
  47. srcOpen_htf = security(tickerid, higher_tf, open)
  48. srcHigh_htf = security(tickerid, higher_tf, high)
  49. srcLow_htf = security(tickerid, higher_tf, low)
  50. //
  51. r_htf=rsi(srcClose_htf, lengthrsi)
  52. ma_htf=sma(r_htf,lengthband)
  53. offs_htf=(1.6185 * stdev(r_htf, lengthband))
  54. upZone_htf=ma_htf+offs_htf
  55. dnZone_htf=ma_htf-offs_htf
  56. mid_htf=(upZone_htf+dnZone_htf)/2
  57. mab_htf=sma(r_htf, lengthrsipl)
  58. mbb_htf=sma(r_htf, lengthtradesl)
  59.  
  60. //
  61. hline(rsiOSL, color=red, linewidth=1)
  62. hline(50, color=black, linewidth=1)
  63. hline(rsiOBL, color=lime, linewidth=1)
  64.  
  65. // Plot the TDI
  66. upl=plot(upZone, color=blue, title="VB Channel High",linewidth=2)
  67. dnl=plot(dnZone, color=blue, title="VB Channel Low",linewidth=2)
  68. midl=plot(mid, color=black, linewidth=2, title="MBL")
  69. mabl=plot(mab, color=green, linewidth=2, title="RSI PL")
  70. mbbl=plot(mbb, color=red, linewidth=2, title="TSL Signal")
  71.  
  72. //create RSI TSL cloud to indicate trend direction.
  73. fill(mabl,mbbl, color=mab>mbb?green:red,transp=90)
  74.  
  75. // Calculate Price Action Channel (PAC)
  76. smmaH = na(smmaH[1]) ? sma(srcHigh, lenH) : (smmaH[1] * (lenH - 1) + srcHigh) / lenH
  77. smmaL = na(smmaL[1]) ? sma(srcLow, lenL) : (smmaL[1] * (lenL - 1) + srcLow) / lenL
  78. //
  79. fastMA = input(title="MACD Fast MA Length", type = integer, defval = 5, minval = 2)
  80. slowMA = input(title="MACD Slow MA Length", type = integer, defval = 15, minval = 7)
  81. signal = input(title="MACD Signal Length",type=integer,defval=1,minval=1)
  82. umacd = input(true,title="Use MACD Filtering")
  83. //
  84. [currMacd,_,_] = macd(srcClose[0], fastMA, slowMA, signal)
  85. [prevMacd,_,_] = macd(srcClose[1], fastMA, slowMA, signal)
  86. macdH = currMacd > 0 ? currMacd > prevMacd ? 1 : -1 : currMacd < prevMacd ? -1 : 1
  87.  
  88. //
  89. // Bar - Highlighting based on indication strength
  90. 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
  91. 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
  92. //
  93. barcolor(not sbr?na:long==1?blue: long==2 and strength>1?aqua:long==3 and strength>2?white: na, title="BUY Bars")
  94. barcolor(not sbr?na:short==1?red: short==2 and strength>1?orange:short==3 and strength>2? yellow : na, title="SELL Bars")
  95. //
  96. barcolor(sgb? gray : na)
  97. //
  98. // create alert only once per sequence type.
  99. //
  100. c_alert = (long>0 and long!=long[1] and long<=strength) or (short>0 and short!=short[1] and short<=strength)
  101. alertcondition(c_alert, title="TDIALT Alert", message="TDIALT Alert")
  102.  
  103. // show dot only when alert condition is met and bar closed.
  104. 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)
  105.  
  106.  
  107. // CURRENCY STRENGTH CODE
  108.  
  109. fast=input(5)
  110. slow=input(15)
  111.  
  112. v1=security('EURGBP',period,close)
  113. v2=security('EURJPY',period,close)
  114. v3=security('EURUSD',period,close)
  115. v4=security('GBPJPY',period,close)
  116. v5=security('GBPUSD',period,close)
  117. v6=security('USDJPY',period,close)
  118. v7=security('EURCAD',period,close)
  119. v8=security('EURNZD',period,close)
  120. v9=security('EURCHF',period,close)
  121. v10=security('EURAUD',period,close)
  122. v11=security('GBPCAD',period,close)
  123. v12=security('GBPNZD',period,close)
  124. v13=security('GBPAUD',period,close)
  125. v14=security('GBPCHF',period,close)
  126. v15=security('USDCAD',period,close)
  127. v16=security('NZDUSD',period,close)
  128. v17=security('USDCHF',period,close)
  129. v18=security('AUDUSD',period,close)
  130. v19=security('AUDCAD',period,close)
  131. v20=security('AUDNZD',period,close)
  132. v21=security('AUDCHF',period,close)
  133. v22=security('AUDJPY',period,close)
  134. v23=security('NZDCAD',period,close)
  135. v24=security('NZDCHF',period,close)
  136. v25=security('NZDJPY',period,close)
  137. v26=security('CADCHF',period,close)
  138. v27=security('CADJPY',period,close)
  139. v28=security('CHFJPY',period,close)
  140.  
  141. EUR=(v1+v2+v3+v7+v8+v9+v10)/7
  142. GBP=((100-v1)+v4+v5+v11+v12+v13+v14)/7
  143. JPY=((100-v2)+(100-v4)+(100-v6)+(100-v22)+(100-v25)+(100-v27)+(100-v28))/7
  144. USD=((100-v3) + (100-v5) + v6 + v15 + (100-v16) + v17 + (100-v18)) /7
  145. AUD=((100-v10)+(100-v12)+v18+v19+v20+v21+v22)/7
  146. NZD=((100-v8) + (100-v13) +v16 +(100-v20) +v23+v24+v25)/7
  147. CAD=((100-v7) + (100-v11) + (100-v15) + (100-v19) + (100-v23) + v26+v27)/7
  148. CHF=((100-v9) + (100-v14) + (100-v17) + (100-v21) + (100-v24) + (100-v26) + v28)/7
  149. eur=tsi(EUR,fast,slow)
  150. gbp=tsi(GBP,fast,slow)
  151. jpy=tsi(JPY,fast,slow)
  152. usd=tsi(USD,fast,slow)
  153. aud=tsi(AUD,fast,slow)
  154. nzd=tsi(NZD,fast,slow)
  155. cad=tsi(CAD,fast,slow)
  156. chf=tsi(CHF,fast,slow)
  157.  
  158. pre = 0
  159. suf = 0
  160.  
  161. if ticker == "EURUSD"
  162. pre := eur
  163. suf := usd
  164.  
  165. if ticker == "GBPUSD"
  166. pre := gbp
  167. suf := usd
  168.  
  169. if ticker == "USDJPY"
  170. pre := usd
  171. suf := jpy
  172.  
  173. if ticker == "NZDUSD"
  174. pre := nzd
  175. suf := usd
  176.  
  177. if ticker == "USDCAD"
  178. pre := usd
  179. suf := cad
  180.  
  181. if ticker == "USDCHF"
  182. pre := usd
  183. suf := chf
  184.  
  185. sep_val = abs(pre - suf)
  186. //plot(sep_val, color=white)
  187.  
  188. //EOF
  189.  
  190. // Created by Robert N. 030715
  191. // Candle labels
  192. //(title = "Candles", overlay = true)
  193.  
  194. trend= input(5, minval=1, title="Trend in Bars")
  195.  
  196. DojiSize = input(0.05, minval=0.01, title="Doji size")
  197. doji=(abs(open - close) <= (high - low) * DojiSize)
  198. plotchar(doji, title="Doji", text='Doji', color=white)
  199. barcolor(doji ? fuchsia : na)
  200.  
  201.  
  202. //1) TF2 (RSI_PL GREEN > TSL_Signal RED) and;
  203. //2) TF1 (RSI_PL > TSL_Signal) and (TSL_Signal > MBL) and (CS_Pre > CS_Suf) and (CS_SV > 0.1)
  204. open_long = mab_htf > mbb_htf and mab_htf > mid_htf and mab > mbb and mbb > mid and pre > suf and sep_val > sep_thresh
  205. open_short = mab_htf < mbb_htf and mab_htf < mid_htf and mab < mbb and mbb < mid and pre < suf and sep_val > sep_thresh
  206.  
  207. //(CS_SV < 1) OR (TF1 (RSI_PL < TSL_Signal)
  208. close_long = (sep_val < 1) and (mab < mbb) and (mab < mab[1]) and doji
  209. close_short = (sep_val < 1) and (mab > mbb) and (mab > mab[1]) and doji
  210.  
  211. // Code to avoid repeated buy or sell singals.
  212. buy_open = barssince(open_long) < barssince(open_short) and barssince(open_long) < barssince(close_long)
  213. sell_open = barssince(open_short) < barssince(open_long) and barssince(open_short) < barssince(close_short)
  214.  
  215. plotshape(open_long and not buy_open[1], style=shape.triangleup, color=lime, size=size.normal, location=location.bottom, transp=0)
  216. plotshape(open_short and not sell_open[1], style=shape.triangledown, color=red, size=size.normal, location=location.top, transp=0)
  217. 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)
  218. 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)
  219.  
  220. if ((year >= 2010) and (year <= 2016))
  221. strategy.close("short", when = close_short)
  222. //strategy.exit("short SL", "short", loss = lossinpoints)
  223. strategy.entry("short", strategy.short, when = open_short)
  224.  
  225. if ((year >= 2010) and (year <= 2016))
  226. strategy.close("long", when = close_long)
  227. //strategy.exit("long SL", "long", loss = lossinpoints)
  228. strategy.entry("long", strategy.long, when = open_long)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement