Advertisement
JustUncleL

Pullback Trading Tool R10.1 by JustUncleL

Dec 12th, 2017
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.31 KB | None | 0 0
  1. //@version=3
  2. //
  3.  
  4. study(title = "Pullback Trading Tool R10.1 by JustUncleL", shorttitle = "PBTOOL R10.1", overlay = true)
  5.  
  6. //
  7. //
  8. // Revision: R10
  9. // Original Author: JustUncleL
  10. //
  11. // Description:
  12. // This study is an alternative Pullback trading Tool to my previous R5 version.
  13. // It incorporates the majority of the indicators needed to analyse trade Trends for Pullbacks and Reversals.
  14. // The set up utilies, optionally, Heikin Ashi candle charts.
  15. //
  16. // NOTE: A Pullback is synomous to Retracement, generally a Pullback refers to a large Retracement of 100pips
  17. // or more. In the context of this Tool and any comments related to it, a Pullback will be the
  18. // same as a Retracement.
  19. //
  20. // Incorporated within this tool are the following indicators:
  21. // 1. Three Moving Averages (EMA by default) that can optionally be Anchored to a Higher Time Frame:
  22. // - DodgerBlue = EMA08 (default)
  23. // - Green = EMA50 (default)
  24. // - Gray = EMA200 (default)
  25. // 2. One Signal Moving Average line Yellow EMA21 (default), optionally Anchored to HTF.
  26. // 3. Two Un-Anchored Moving Averages, only display when there is an HTF Anchor specified.
  27. // - Aqua = EMA08 (default)
  28. // - Fuchsia = EMA21 (default)
  29. // 4. Display Fractals/Pivots and optional Fractal/Pivot Levels
  30. // 5. HH, LH, LL, HL finder to help with drawing Trend lines and mini Trend Lines.
  31. // 6. Coloured coded Bar based on the signal MA:
  32. // the Standard candle colours:
  33. // - Blue = candle open and closed above signal MA.
  34. // - Red = candle open and closed below signal MA.
  35. // - Yellow = Candle stradle across signal MA.
  36. // the Grab candles scheme:
  37. // - Lime = Bull candle open and closed above signal MA.
  38. // - Green = Bear candle open and closed above signal MA.
  39. // - Red = Bull candle open and closed below signal MA.
  40. // - DarkRed = Bear candle open and closed below signal MA.
  41. // - Aqua = Bull candle closed across signal MA.
  42. // - Blue = Bear candle stradle across signal MA.
  43. //
  44. //
  45. // Setup and hints:
  46. // I cannot go into a full description, as Pullback trading incorporates a full trading Methodology,
  47. // there are many articles and books written on the subject.
  48. //
  49. // - I also add a "Sweetspot Gold RN" indicator to the chart as well to help with support and resistance
  50. // finding and shows where the important "00" lines are.
  51. // - First on a weekly basis say Sunday night or Monday morning, analyse the Daily and Weekly charts
  52. // to establish overall trends, and support/resistant levels. Draw significant trend lines,
  53. // vertical trend lines (VTL) and S/R levels. Use Pivots option to guide VTL drawing and use Fractals
  54. // to help guide TL drawing.
  55. // - Once the trend direction and any potential major reversals highlighted, drop down to the 4hr chart
  56. // and draw appropriate mini Trend line matching the established momentum direction. Take note of
  57. // potential pull backs from and of the EMAs, in particular the 36EMA and the 200EMA. Can use the
  58. // Fractals and HH/LL points to guide your TL drawing.
  59. // - Check to see if the TL is broken and is pulling back off one of the EMA lines, then trade
  60. // that alert, or drop down to lower time frames (TF) and perform the same analysis there and trade at the lower
  61. // TF. Trading at lower TF you will be able to get tighter Stop loss settings.
  62. // - Other than the SweetSpot Gold RN indicator, you should not require any other indicator to trade trends
  63. // for pull backs and reversals.
  64. //
  65. // Revisions:
  66. //
  67. // R1 to R7 Original Versions by JustUncleL
  68. //
  69. // R10 Alternate version by JustUncleL.
  70. //
  71. // References:
  72. // - Scalp Jockey v2 by Jay Rogers
  73. // - [RS]Fractals V8 by RicardoSantos
  74. // - SweetSpot Gold RN by JustUncleL
  75. // - Price Action Trading System v0.3 by JustUncleL
  76. // - http://www.swing-trade-stocks.com/pullbacks.html
  77. //
  78. //
  79. // -----------------------------------------------------------------------------
  80. // Copyright 2017 JustUncleL
  81. //
  82. // This program is free software: you can redistribute it and/or modify
  83. // it under the terms of the GNU General Public License as published by
  84. // the Free Software Foundation, either version 3 of the License, or
  85. // any later version.
  86. //
  87. // This program is distributed in the hope that it will be useful,
  88. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  89. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  90. // GNU General Public License for more details.
  91. //
  92. // The GNU General Public License can be found here
  93. // <http://www.gnu.org/licenses/>.
  94. //
  95. // -----------------------------------------------------------------------------
  96. //
  97.  
  98.  
  99. // === INPUTS ===
  100.  
  101. // Un-Anchored Fast + Slow MA - Type and Length
  102. fastType = input(defval="EMA", title="Fast Un-Anchored MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"], type=string)
  103. fastLen = input(defval=8, title="Fast Un-Anchored MA Length:", minval=1)
  104. slowType = input(defval="EMA", title="Slow Un-Anchored MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"], type=string)
  105. slowLen = input(defval=21, title="Slow Un-Anchored MA Length:", minval=1)
  106. //
  107. // Anchor Higher Time Frame
  108. anchorTF = input(0,minval=0,maxval=1440,title="Anchor TimeFrame (0=none, max=1440 (mins,D,W)")
  109. //
  110. // Anchored Fast+ Medium + Slow MA - type, length
  111. fastAnchorType = input(defval="EMA", title="Fast Anchored MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"], type=string)
  112. fastAnchorLen_ = input(defval=8, title="Fast Anchored MA Length:", minval=1)
  113. mediumAnchorType = input(defval="EMA", title="Medium Anchored MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"], type=string)
  114. mediumAnchorLen_ = input(defval=50, title="Medium Anchored MA Length:", minval=1)
  115. slowAnchorType = input(defval="EMA", title="Slow Anchored MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"], type=string)
  116. slowAnchorLen_ = input(defval=200, title="Slow Anchored MA Length:", minval=1)
  117. // Signal MA
  118. anchorSignal = input(true,title="Anchor the Signal MA:")
  119. signalType = input(defval="EMA", title="Signal MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"], type=string)
  120. signalLen_ = input(defval=21, title="Signal MA Length:", minval=1)
  121. //
  122. ShowBarColor = input(true, title="Show coloured Bars close relative to Signal MA")
  123. useGrabClr = input(false, title="Use Grab Candle (6-tone) Colouring, instead of Standard (3-tone)")
  124. // Pivots
  125. ShowPivots = input(true,title="Show Pivot Points")
  126. pvtLenL = input(2,minval=1,title="Pivot Length Left Hand Side")
  127. pvtLenR = input(2,minval=1,title="Pivot Length Right Hand Side")
  128. ShowSRLevels = input(false,title="Show S/R Level Extensions")
  129. maxLvlLen = input(0,minval=0, title="Maximum S/R Level Extension Length")
  130. uRenko = input(false, title="Use Renko Style Pivots (open/close for high/low)")
  131. ShowHHLL = input(false)
  132. ma_src = input(close,title="Source for Moving Averages")
  133.  
  134. //
  135. //
  136. // --- CONSTANTS ---
  137. DodgerBlue = #1E90FF
  138. Gold = #FFD700
  139. // --- /CONTANTS ---
  140. //
  141.  
  142. // Constants colours that include fully non-transparent option.
  143. GREEN = #008000FF
  144. LIME = #00FF00FF
  145. RED = #FF0000FF
  146. BLUE = #0000FFFF
  147. AQUA = #00FFFFFF
  148. DARKRED = #8B0000FF
  149. GRAY = #808080FF
  150. YELLOW = #FFFF00FF
  151. GOLD = #FFD700FF
  152. DODGERBLUE = #1E90FFFF
  153.  
  154. //
  155. // === /INPUTS ===
  156.  
  157. // === FUNCTIONS ===
  158.  
  159. // - variant(type, src, len)
  160. // Returns MA input selection variant, default to SMA if blank or typo.
  161.  
  162. // SuperSmoother filter
  163. // © 2013 John F. Ehlers
  164. variant_supersmoother(src,len) =>
  165. a1 = exp(-1.414*3.14159 / len)
  166. b1 = 2*a1*cos(1.414*3.14159 / len)
  167. c2 = b1
  168. c3 = (-a1)*a1
  169. c1 = 1 - c2 - c3
  170. v9 = 0.0
  171. v9 := c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
  172. v9
  173.  
  174. variant_smoothed(src,len) =>
  175. v5 = 0.0
  176. v5 := na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len
  177. v5
  178.  
  179. variant_zerolagema(src,len) =>
  180. ema1 = ema(src, len)
  181. ema2 = ema(ema1, len)
  182. v10 = ema1+(ema1-ema2)
  183. v10
  184.  
  185. variant_doubleema(src,len) =>
  186. v2 = ema(src, len)
  187. v6 = 2 * v2 - ema(v2, len)
  188. v6
  189.  
  190. variant_tripleema(src,len) =>
  191. v2 = ema(src, len)
  192. v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
  193. v7
  194.  
  195. // return variant, defaults to SMA
  196. variant(type, src, len) =>
  197. type=="EMA" ? ema(src,len) :
  198. type=="WMA" ? wma(src,len):
  199. type=="VWMA" ? vwma(src,len) :
  200. type=="SMMA" ? variant_smoothed(src,len) :
  201. type=="DEMA" ? variant_doubleema(src,len):
  202. type=="TEMA" ? variant_tripleema(src,len):
  203. type=="HullMA"? wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) :
  204. type=="SSMA" ? variant_supersmoother(src,len) :
  205. type=="ZEMA" ? variant_zerolagema(src,len) :
  206. type=="TMA" ? sma(sma(src,len),len) :
  207. sma(src,len)
  208.  
  209. // - /variant
  210.  
  211. // === /FUNCTIONS ===
  212.  
  213. // === SERIES ===
  214.  
  215. // If this is 5min or less Time Frame select EMAs
  216. mult = not isintraday or anchorTF==0 or interval<=0 or interval>=anchorTF or anchorTF>1440 ? 1 : round(anchorTF/interval)>1? round(anchorTF/interval) : 1
  217. mult := isintraday or anchorTF==0 or interval<=0 or interval>=anchorTF or anchorTF>52 ? mult : round(anchorTF/interval)>1? round(anchorTF/interval) : 1
  218.  
  219. fastAnchorLen = mult==1 ? fastAnchorLen_ : (fastAnchorLen_*mult)
  220. mediumAnchorLen = mult==1 ? mediumAnchorLen_ : (mediumAnchorLen_*mult)
  221. slowAnchorLen = mult==1 ? slowAnchorLen_ : (slowAnchorLen_*mult)
  222.  
  223. signalLen = not anchorSignal or mult==1 ? signalLen_ : (signalLen_*mult)
  224.  
  225. // Get the two MAs
  226. fastMA = variant(fastType,ma_src, fastLen)
  227. slowMA = variant(slowType,ma_src, slowLen)
  228. signalMA = variant(signalType,ma_src, signalLen)
  229. fastAnchorMA = variant(fastAnchorType,ma_src, fastAnchorLen)
  230. mediumAnchorMA = variant(mediumAnchorType,ma_src, mediumAnchorLen)
  231. slowAnchorMA = variant(slowAnchorType,ma_src, slowAnchorLen)
  232.  
  233. // - PIVOT VARIABLES
  234. //
  235. high_ = uRenko? max(close,open) : high
  236. low_ = uRenko? min(close,open) : low
  237.  
  238.  
  239. // Get High and Low Pivot Points
  240. pvthi = pivothigh(high_,pvtLenL,pvtLenR)
  241. pvtlo = pivotlow(low_,pvtLenL,pvtLenR)
  242.  
  243. // Force Pivot completion before plotting.
  244. //pvthi = pvthi_[1]
  245. //pvtlo = pvtlo_[1]
  246.  
  247. // ||-----------------------------------------------------------------------------------------------------||
  248. // ||--- Higher Highs, Lower Highs, Higher Lows, Lower Lows -------------------------------------------||
  249. higherhigh = pvthi ? ( valuewhen(pvthi, high_[pvtLenR], 1) < valuewhen(pvthi, high_[pvtLenR], 0) ) : pvthi
  250. lowerhigh = pvthi ? ( valuewhen(pvthi, high_[pvtLenR], 1) > valuewhen(pvthi, high_[pvtLenR], 0) ) : pvthi
  251. higherlow = pvtlo ? ( valuewhen(pvtlo, low_[pvtLenR], 1) < valuewhen(pvtlo, low_[pvtLenR], 0) ) : pvtlo
  252. lowerlow = pvtlo ? ( valuewhen(pvtlo, low_[pvtLenR], 1) > valuewhen(pvtlo, low_[pvtLenR], 0) ) : pvtlo
  253.  
  254. // === /SERIES ===
  255.  
  256. // === PLOTTING ===
  257. //
  258. // Colour bars according to the close position relative to the PAC selected.
  259. bColour = open>signalMA and close>signalMA? DODGERBLUE :
  260. open<signalMA and close<signalMA? RED :
  261. YELLOW
  262. bColour := not useGrabClr ? bColour :
  263. open>signalMA and close>signalMA? open>close?GREEN:LIME :
  264. open<signalMA and close<signalMA? open>close?DARKRED:RED :
  265. open>close?BLUE:AQUA
  266. barcolor(ShowBarColor?bColour:na, title = "Signal Bar Colours")
  267.  
  268. // Draw the EMA ribbon
  269. plot(mult>1?fastMA:na, color=aqua,join=true,linewidth=1,transp=10,title="Fast MA")
  270. plot(mult>1?slowMA:na, color=fuchsia,join=true,linewidth=1,transp=10,title="Slow MA")
  271. //
  272. plot(signalMA, color=Gold,join=true,style=circles,linewidth=2,transp=20,title="Signal MA")
  273. //
  274. plot(fastAnchorMA, color=DodgerBlue,join=true,style=circles,linewidth=2,transp=20,title="Fast Anchored MA")
  275. plot(mediumAnchorMA, color=green,join=true,style=circles,linewidth=2,transp=20,title="Medium Anchored MA")
  276. plot(slowAnchorMA, color=gray,join=true,style=circles,linewidth=2,transp=20,title="Slow Anchored MA")
  277.  
  278.  
  279.  
  280. // If selected Display the HH/LL above/below candle.
  281. plotshape(ShowHHLL ? higherhigh : na, title='HH', style=shape.square, location=location.abovebar, color=lime, text="HH", offset=-pvtLenR,transp=20)
  282. plotshape(ShowHHLL ? lowerhigh : na, title='LH', style=shape.square, location=location.abovebar, color=red, text="LH", offset=-pvtLenR,transp=20)
  283. plotshape(ShowHHLL ? higherlow : na, title='HL', style=shape.square, location=location.belowbar, color=lime, text="HL", offset=-pvtLenR,transp=20)
  284. plotshape(ShowHHLL ? lowerlow : na, title='LL', style=shape.square, location=location.belowbar, color=red, text="LL", offset=-pvtLenR,transp=20)
  285.  
  286.  
  287. // If Selected Display Pivot points
  288. plotshape(ShowPivots ? pvthi :na, title='High Pivot *', location=location.abovebar, style=shape.triangleup,color=green, offset=-pvtLenR,transp=0,size=size.auto)
  289. plotshape(ShowPivots ? pvtlo :na, title='Low Pivot *', location=location.belowbar, style=shape.triangledown,color=maroon, offset=-pvtLenR,transp=0,size=size.auto)
  290.  
  291.  
  292.  
  293. //Count How many candles for current Pivot Level, If new reset.
  294. counthi = 0
  295. countlo = 0
  296. counthi := pvthi ? 0 : nz(counthi[1])+1
  297. countlo := pvtlo ? 0 : nz(countlo[1])+1
  298.  
  299. pvthis = 0.0
  300. pvtlos = 0.0
  301. pvthis := pvthi ? high[pvtLenR] : pvthis[1]
  302. pvtlos := pvtlo ? low[pvtLenR] : pvtlos[1]
  303.  
  304. hipc = (pvthis != pvthis[1]) ? na : green
  305. lopc = (pvtlos != pvtlos[1]) ? na : maroon
  306.  
  307. plot(ShowSRLevels and (maxLvlLen==0 or counthi<maxLvlLen)? pvthis : na, color=hipc, transp=0, linewidth=1, offset=-pvtLenR, title="Top Levels")
  308. plot(ShowSRLevels and (maxLvlLen==0 or countlo<maxLvlLen)? pvtlos : na, color=lopc, transp=0, linewidth=1, offset=-pvtLenR, title="Bottom Levels")
  309. plot(ShowSRLevels and (maxLvlLen==0 or counthi<maxLvlLen) ? pvthis : na, color=hipc, transp=0, linewidth=1, offset=0, title="Top Levels 2")
  310. plot(ShowSRLevels and (maxLvlLen==0 or countlo<maxLvlLen) ? pvtlos : na, color=lopc, transp=0, linewidth=1, offset=0, title="Bottom Levels 2")
  311.  
  312. // === /PLOTTING ===
  313. //
  314.  
  315. // === ALERTS ===
  316.  
  317.  
  318.  
  319. // === /ALERTS ===
  320.  
  321. // === eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement