Advertisement
JustUncleL

T3MA Ribbon R4.1 by JustUncleL

Jan 6th, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.64 KB | None | 0 0
  1. //@version=3
  2.  
  3. study(title="T3MA Ribbon R4.1 by JustUncleL", shorttitle="T3RIBBON", overlay = true)
  4.  
  5. //
  6. // Revision: R4
  7. // Revision Author: JustUncleL
  8. //
  9. // Description:
  10. // This study draws a T3 Moving average Coloured Ribbon based on a Fast and Slow T3 MAs.
  11. //
  12. // References:
  13. // - https://www.forexstrategiesresources.com/binary-options-trading-strategies/84-winner-binary-system/
  14. // =======
  15. // - T3 Average by HPotter v1.0 21/05/2014
  16. // This indicator plots the moving average described in the January, 1998 issue
  17. // of S&C, p.57, "Smoothing Techniques for More Accurate Signals", by Tim Tillson.
  18. // This indicator plots T3 moving average presented in Figure 4 in the article.
  19. // T3 indicator is a moving average which is calculated according to formula:
  20. // T3(n) = GD(GD(GD(n))),
  21. // where GD - generalized DEMA (Double EMA) and calculating according to this:
  22. // GD(n,v) = EMA(n) * (1+v)-EMA(EMA(n)) * v,
  23. // where "v" is volume factor, which determines how hot the moving average’s response
  24. // to linear trends will be. The author advises to use v=0.7.
  25. // When v = 0, GD = EMA, and when v = 1, GD = DEMA. In between, GD is a less aggressive
  26. // version of DEMA. By using a value for v less than1, trader cure the multiple DEMA
  27. // overshoot problem but at the cost of accepting some additional phase delay.
  28. // In filter theory terminology, T3 is a six-pole nonlinear Kalman filter. Kalman
  29. // filters are ones that use the error — in this case, (time series - EMA(n)) —
  30. // to correct themselves. In the realm of technical analysis, these are called adaptive
  31. // moving averages; they track the time series more aggres-sively when it is making large
  32. // moves. Tim Tillson is a software project manager at Hewlett-Packard, with degrees in
  33. // mathematics and computer science. He has privately traded options and equities for 15 years.
  34. // =======
  35. // Options:
  36. //
  37. // 1) Option to display coloured Candles around the Ribbon, the coulouring uses
  38. // the Standard candle colours:
  39. // - Lime = candle closed above Ribbon.
  40. // - Red = candle closed below Ribbon.
  41. // - Gray = Candle Closed inside Ribbon.
  42. // the Grab candles scheme:
  43. // - Lime = Bull candle closed above Ribbon.
  44. // - Green = Bear candle closed above Ribbon.
  45. // - Red = Bull candle closed below Ribbon.
  46. // - DarkRed = Bear candle closed below Ribbon.
  47. // - Aqua = Bull candle closed inside Ribbon.
  48. // - Blue = Bear candle closed inside Ribbon.
  49. //
  50. // 2) Option to base the candles on a higher time frame (HFT), this performed by increasing
  51. // the MA length to create equivalent lengths from the HFT. So no re-painting.
  52. // NOTE: The script will time out if the MA lengths get too long after resizing.
  53. //
  54. // Modifications:
  55. // R1 - Original
  56. // R2 - Added optional Bar colouring
  57. // - Added option to Anchor chart to a higher Time Frame (1440 max)
  58. //
  59. // 10-Aug-2017 - R3:
  60. // - Made updates for Pinescript version 3 Compliance.
  61. // - Allow anchor option to be used for Days and Weeks.
  62. // - Allow option to use standard 3-tone bar colouring, or 6-tone Grab candle Colouring
  63. // - Added named colour constants, to include fully opaque colours, a work around
  64. // for bar colouring transparency bug.
  65. //
  66. // 7-Jan-2018 R4:
  67. // - Added Alert Buy/Sell exit options.
  68. // - Added alarms for TradingView's Alarm Subsystem.
  69. // - Added implied GPL Copyright notice.
  70. // - Some coding efficiency and some variable name changes to make it easier
  71. // to read.
  72. //
  73. //
  74. // -----------------------------------------------------------------------------
  75. // Copyright 2014 HPotter
  76. // Copyright 2017,2018 JustUncleL
  77. //
  78. // This program is free software: you can redistribute it and/or modify
  79. // it under the terms of the GNU General Public License as published by
  80. // the Free Software Foundation, either version 3 of the License, or
  81. // any later version.
  82. //
  83. // This program is distributed in the hope that it will be useful,
  84. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  85. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  86. // GNU General Public License for more details.
  87. //
  88. // The GNU General Public License can be found here
  89. // <http://www.gnu.org/licenses/>.
  90. //
  91. // -----------------------------------------------------------------------------
  92. //
  93.  
  94. // Use Alternate Anchor TF for MAs
  95. anchor = input(0,minval=0,maxval=1440,title="Use Alternate Anchor TimeFrame (0=none, max=1440mins)")
  96. LengthFast_ = input(8, minval=1,title="Fast T3MA length")
  97. VolFactorFast= input(0.7,minval=0.0,maxval=1.0,title="Fast T3 Volume Factor")
  98. LengthSlow__ = input(13, minval=2,title="Slow T3MA length")
  99. VolFactorSlow= input(0.6,minval=0.0,maxval=1.0,title="Slow T3 Volume Factor")
  100. ma_src = input(close,title="T3MA Source")
  101. sBars = input(false,title="Show Coloured Trend Bars")
  102. uGrabClr = input(false,title="Use Grab Bar 6-tone Colours, instead of Standard 3-tone")
  103. ShowSwing = input(false,title="Show Swing Alerts")
  104. dFilter = input(false,title="Filter Alerts to Ribbon Colour")
  105.  
  106. // Constants colours that include fully non-transparent option.
  107. green100 = #008000FF
  108. lime100 = #00FF00FF
  109. red100 = #FF0000FF
  110. blue100 = #0000FFFF
  111. aqua100 = #00FFFFFF
  112. darkred100 = #8B0000FF
  113. gray100 = #808080FF
  114.  
  115. // Make sure we have minimum channel spread.
  116. LengthSlow_ = (LengthSlow__-LengthFast_)<1?LengthFast_+1:LengthSlow__
  117.  
  118. // If this is 5min or less Time Frame select EMAs
  119. mult = not isintraday or anchor==0 or interval<=0 or interval>=anchor or anchor>1440 ? 1 : round(anchor/interval)>1? round(anchor/interval) : 1
  120. mult := isintraday or anchor==0 or interval<=0 or interval>=anchor or anchor>52 ? mult : round(anchor/interval)>1? round(anchor/interval) : 1
  121. //
  122. LengthFast = mult==1 ? LengthFast_ : (LengthFast_*mult)-1
  123. LengthSlow = mult==1 ? LengthSlow_ : (LengthSlow_*mult)-1
  124.  
  125.  
  126. // T3 Moving Average Calculation Function.
  127. T3MA(src, Length, VolFactor) =>
  128. xe1 = ema(src, Length)
  129. xe2 = ema(xe1, Length)
  130. xe3 = ema(xe2, Length)
  131. xe4 = ema(xe3, Length)
  132. xe5 = ema(xe4, Length)
  133. xe6 = ema(xe5, Length)
  134. b = VolFactor
  135. c1 = -b*b*b
  136. c2 = 3*b*b+3*b*b*b
  137. c3 = -6*b*b-3*b-3*b*b*b
  138. c4 = 1+3*b+b*b*b+3*b*b
  139. c1 * xe6 + c2 * xe5 + c3 * xe4 + c4 * xe3
  140.  
  141. // Get the two T3MAs
  142. t3maFast = T3MA(ma_src, LengthFast, VolFactorFast)
  143. t3maSlow = T3MA(ma_src, LengthSlow, VolFactorSlow)
  144.  
  145. //Plot the Ribbon
  146. ma1=plot( t3maFast,color=rising(t3maFast,2)?green:red,linewidth=1,join=true,transp=20,title="Fast t3ma")
  147. ma2=plot( t3maSlow,color=rising(t3maSlow,2)?green:red,linewidth=1,join=true,transp=20,title="Slow t3ma")
  148. fcolor = t3maFast>t3maSlow?green:red
  149. fill(ma1,ma2,color=fcolor,transp=80,title="Ribbon Fill")
  150.  
  151. // Colour bars according to the close position relative to the MA selected
  152. // Or Grab candle colour code bars according to the close position relative to the MA selected
  153. grabcol = close>=open? close>t3maFast and close>t3maSlow? lime100 : close<t3maFast and close<t3maSlow? red100 : aqua100 :
  154. close>t3maFast and close>t3maSlow? green100 : close<t3maFast and close<t3maSlow? darkred100 : blue100
  155. stdcol = close>t3maFast and close>t3maSlow ? lime100 : close<t3maFast and close<t3maSlow? red100 : gray100
  156.  
  157. barcolor(sBars?uGrabClr? grabcol: stdcol:na, title = "Bar Colours")
  158.  
  159. // Generate Alert Arrows
  160. buy = 0
  161. sell=0
  162. buyT = 0
  163. sellT =0
  164. // Generate signal by Grab Candle Colour
  165. buy := grabcol==lime100? (nz(buy[1])+1) : grabcol==green100? (nz(buy[1])>0? nz(buy[1])+1: 0) : 0
  166. sell := grabcol==darkred100? (nz(sell[1])+1) : grabcol==red100? (nz(sell[1])>0? nz(sell[1])+1: 0) : 0
  167.  
  168. // Trend Filter
  169. buyT := buy==0? 0 : (dFilter and t3maFast<t3maSlow)? 0 : nz(buyT[1])+1
  170. sellT := sell==0? 0 : (dFilter and t3maFast>t3maSlow)? 0 : nz(sellT[1])+1
  171.  
  172. // Exit conditions
  173. exitbuy = nz(buyT[1])>0 and buyT==0
  174. exitsell = nz(sellT[1])>0 and sellT==0
  175.  
  176. //
  177. plotarrow(ShowSwing and buyT==1 ?1:na, title="BUY Swing Arrow", colorup=lime, maxheight=60, minheight=50, transp=20)
  178. plotarrow(ShowSwing and sellT==1 ?-1:na, title="SELL Swing Arrow", colordown=red, maxheight=60, minheight=50, transp=20)
  179. //
  180. plotshape(ShowSwing and exitbuy, title='BUY Exit', style=shape.xcross, location=location.belowbar, color=gray, text="Exit\nBuy", offset=0,transp=0)
  181. plotshape(ShowSwing and exitsell, title='Sell Exit', style=shape.xcross, location=location.abovebar, color=gray, text="Exit\nSell", offset=0,transp=0)
  182.  
  183. // Generate Alarms
  184. alertcondition(buyT==1,title="BUY Alert",message="BUY")
  185. alertcondition(sellT==1,title="SELL Alert",message="SELL")
  186. alertcondition(exitbuy,title="BUY Exit Alert",message="ExitBuy")
  187. alertcondition(exitsell,title="SELL Exit Alert",message="ExitSell")
  188.  
  189. //eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement