Advertisement
Guest User

Untitled

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