Advertisement
xmd79

Scalping PullBack Tool R1.1 by JustUncleL

May 1st, 2021
1,696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.81 KB | None | 0 0
  1. //@version=4
  2. //
  3.  
  4. study(title="Scalping PullBack Tool R1.1 by JustUncleL", shorttitle="SCALPTOOL R1.1", overlay=true)
  5.  
  6. //
  7. // Revision: 1.1
  8. // Original Author: JustUncleL
  9. //
  10. // Description:
  11. // This study project is a Scalping Pullback trading Tool that incorporates the majority of the indicators
  12. // needed to analyse and scalp Trends for Pull Backs and reversals intended for lower time frame
  13. // charts upto 15min, but it should work just as well on higher time frame charts for
  14. // longer term trades.
  15. //
  16. // This Tool can be used with Heikin Ashi (HA) candle charts or normal candle charts, HA candles
  17. // will show a cleaner/smoother looking candle trend but not show true prices.
  18. //
  19. // Incorporated within this tool are the following indicators:
  20. // 1. Trader selectable important EMAs in an EMA style Ribbon:
  21. // - Green = fast EMA (default=89)
  22. // - Blue = medium EMA (default=200)
  23. // - Black = slow EMA (default=600)
  24. // 2. The PAC EMA (default=34) High/Low+Close creates the Price Action Channel (PAC).
  25. // 3. Fractals
  26. // 4. HH, LH, LL, HL finder may help with drawing Trend lines and mini Trend Lines.
  27. // 5. Coloured coded Bar high lighting based on the PAC:
  28. // - blue = bar closed above PAC
  29. // - red = bar closed below PAC
  30. // - gray = bar closed inside PAC
  31. // - red line = PAC EMA (34) of bar close
  32. // 6. Coloured chart Background to indicate Trend direction
  33. // (NOTE: slow EMA(600) is not used in this Algo):
  34. // - green = Trend direction is up when PAC and fast EMA(89) are above medium EMA(200).
  35. // - red = Trend direction is down when PAC and fast EMA(89) are below medium EMA(200).
  36. // - yellow = Trend direction is in transition.
  37. // 7. Pullback is defined as Price starts outside the PAC and then pulls back into the PAC
  38. // closing the opposite side of the PAC centre line, then a recovery arrow can occur.
  39. // 8. Coloured Alert Arrows:
  40. // - maroon down arrow = Pullback recovery Sell alert
  41. // - green up arrow = Pullback recovery Buy alert
  42. // 9. Option to force Heikin Ashi candles in Algo calculations.
  43. //
  44. // Setup and hints:
  45. //
  46. // - I also add "Sweetspot Gold RN" indicator to the chart as well to help with support and resistance
  47. // finding and shows where the important "00" and "0" lines are.
  48. // - When price is above the PAC(blue bars) we are only looking to buy as price comes back to the PAC
  49. // When price is below the PAC(red bars), we are only looking to sell when price comes back to the PAC
  50. // - What we’re looking for when price comes back into the PAC we draw mini Trendlines (TL) uitilising the
  51. // Fractals and HH/LL points to guide your TL drawing.
  52. // - Now look for the trend to pull back and break the drawn mini TL. That's is where we can place the scalp
  53. // trade.
  54. // - So we are looking for continuation signals in terms of a strong, momentum driven pullbacks
  55. // of the PAC EMA(34).
  56. // - The other EMAs are there to check for other Pullbacks when PAC EMA (34) is broken.
  57. // - Other than the "SweetSpot Gold RN" indicator, you should not need any other indicator to scalp
  58. // for pullbacks.
  59. // - If you want to trade shallower Pullbacks for quicker scalps, try reducing the
  60. // PAC and EMA combination lengths for example:
  61. // * 21 PAC and 55, 144, 377 for fast, medium, slow EMAs
  62. // * 13 PAC and 34, 89, 233 for fast, medium, slow EMAs
  63. // - Each alert should be evaluated on it's own merits, the alerts are designed to highlight possible
  64. // scalping trades from Pullback recoveries around the PAC.
  65. //
  66. // References:
  67. // - [RS]Fractals V8 by RicardoSantos
  68. // - Price Action Trading System v0.3 by JustUncleL
  69. // - SweetSpot Gold RN by JustUncleL
  70. // - http://www.swing-trade-stocks.com/pullbacks.html
  71. // - https://www.forexstrategiesresources.com/scalping-forex-strategies/106-1-min-scalping-with-34-exponential-moving-average-channel/
  72. //
  73. // Modifications:
  74. // 4-Feb-2020 Release R1.1 changes made to provide a more versitile tool
  75. // - Upgraded to Pinescript R4
  76. // - Reodered code into more logical blocks
  77. // - Added option for PAC filtered Alerts and Alarms.
  78. // - Added option to alter the default EMA lengths.
  79. // - Added option to Show each EMA line.
  80. // - Added option to use Heikin Ashi candles for Algo calculations
  81. // even when normal candles are displayed on chart.
  82. //
  83.  
  84. // === INPUTS ===
  85. HiLoLen = input(34, minval=2, title="High Low PAC channel Length")
  86. fastEMAlength = input(89, minval=2)
  87. mediumEMAlength = input(200, minval=2)
  88. slowEMAlength = input(600, minval=2)
  89. ShowFastEMA = input(true)
  90. ShowMediumEMA = input(true)
  91. ShowSlowEMA = input(false)
  92. ShowHHLL = input(false)
  93. ShowFractals = input(true)
  94. filterBW = input(false, title="Show Ideal Fractals Only")
  95. ShowBarColor = input(true, title="Show coloured Bars around PAC")
  96. ShowBuySell = input(true, title="Show Buy/Sell Alert Arrows")
  97. Lookback = input(3, minval=1, title="Pullback Lookback for PAC Cross Check")
  98. DelayArrow = input(false, title="Show Alert Arrows Only on Closed Candles")
  99. Delay = DelayArrow ? 1 : 0
  100. ShowTrendBGcolor= input(true)
  101. UseHAcandles = input(true, title="Use Heikin Ashi Candles in Algo Calculations")
  102. //
  103. // === /INPUTS ===
  104.  
  105. // === BASE FUNCTIONS ===
  106.  
  107. haClose = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, close) : close
  108. haOpen = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, open) : open
  109. haHigh = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, high) : high
  110. haLow = UseHAcandles ? security(heikinashi(syminfo.tickerid), timeframe.period, low) : low
  111.  
  112.  
  113. // ||--- Fractal Recognition Functions: ---------------------------------------------------------------||
  114. isRegularFractal(mode) =>
  115. ret = mode == 1 ? high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and
  116. high[1] > high[0] : mode == -1 ?
  117. low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0] :
  118. false
  119. ret
  120.  
  121. isBWFractal(mode) =>
  122. ret = mode == 1 ? high[4] < high[2] and high[3] <= high[2] and high[2] >= high[1] and
  123. high[2] > high[0] : mode == -1 ?
  124. low[4] > low[2] and low[3] >= low[2] and low[2] <= low[1] and low[2] < low[0] :
  125. false
  126. ret
  127. // ||-----------------------------------------------------------------------------------------------------||
  128.  
  129. //
  130. // === /BASE FUNCTIONS ===
  131.  
  132. // === SERIES SETUP ===
  133. //
  134.  
  135. // ||--- Setup Moving Averages and PAC channel:
  136. // ||-----------------------------------------------------------------------------------------------------||
  137. fastEMA = ema(haClose, fastEMAlength)
  138. mediumEMA = ema(haClose, mediumEMAlength)
  139. slowEMA = ema(haClose, slowEMAlength)
  140. pacC = ema(haClose, HiLoLen)
  141. pacL = ema(haLow, HiLoLen)
  142. pacU = ema(haHigh, HiLoLen)
  143. TrendDirection = fastEMA > mediumEMA and pacL > mediumEMA ? 1 :
  144. fastEMA < mediumEMA and pacU < mediumEMA ? -1 : 0
  145.  
  146. // ||--- Fractal Recognition:
  147. // ||-----------------------------------------------------------------------------------------------------||
  148. filteredtopf = filterBW ? isRegularFractal(1) : isBWFractal(1)
  149. filteredbotf = filterBW ? isRegularFractal(-1) : isBWFractal(-1)
  150. // ||-----------------------------------------------------------------------------------------------------||
  151. // ||--- Higher Highs, Lower Highs, Higher Lows, Lower Lows -------------------------------------------||
  152. valuewhen_H0 = valuewhen(filteredtopf == true, high[2], 0)
  153. valuewhen_H1 = valuewhen(filteredtopf == true, high[2], 1)
  154. valuewhen_H2 = valuewhen(filteredtopf == true, high[2], 2)
  155. //
  156. higherhigh = filteredtopf == false ? false :
  157. valuewhen_H1 < valuewhen_H0 and valuewhen_H2 < valuewhen_H0
  158. lowerhigh = filteredtopf == false ? false :
  159. valuewhen_H1 > valuewhen_H0 and valuewhen_H2 > valuewhen_H0
  160. valuewhen_L0 = valuewhen(filteredbotf == true, low[2], 0)
  161. valuewhen_L1 = valuewhen(filteredbotf == true, low[2], 1)
  162. valuewhen_L2 = valuewhen(filteredbotf == true, low[2], 2)
  163. //
  164. higherlow = filteredbotf == false ? false :
  165. valuewhen_L1 < valuewhen_L0 and valuewhen_L2 < valuewhen_L0
  166. lowerlow = filteredbotf == false ? false :
  167. valuewhen_L1 > valuewhen_L0 and valuewhen_L2 > valuewhen_L0
  168.  
  169. //
  170. // === /SERIES ===
  171.  
  172. //
  173. // === PLOTTING ===
  174. //
  175. // Plot the Price Action Channel (PAC) base on EMA high,low and close
  176. L = plot(pacL, color=color.gray, linewidth=1, title="High PAC EMA", transp=50)
  177. U = plot(pacU, color=color.gray, linewidth=1, title="Low PAC EMA", transp=50)
  178. C = plot(pacC, color=color.red, linewidth=2, title="Close PAC EMA", transp=0)
  179. fill(L, U, color=color.gray, transp=90, title="Fill HiLo PAC")
  180.  
  181. // Colour bars according to the close position relative to the PAC selected.
  182. BARcolor = haClose > pacU ? color.blue : haClose < pacL ? color.red : color.gray
  183. barcolor(ShowBarColor ? BARcolor : na, title="Bar Colours")
  184. //
  185. BGcolor = TrendDirection == 1 ? color.green :
  186. TrendDirection == -1 ? color.red : color.yellow
  187. bgcolor(ShowTrendBGcolor ? BGcolor : na, transp=90, title="Trend BG Color")
  188.  
  189. // Draw the EMA ribbon
  190. plot(ShowFastEMA ? fastEMA : na, color=color.green, linewidth=2, transp=20, title="fastEMA")
  191. plot(ShowMediumEMA ? mediumEMA : na, color=color.blue, linewidth=3, transp=20, title="mediumEMA")
  192. plot(ShowSlowEMA ? slowEMA : na, color=color.black, linewidth=4, transp=20, title="slowEMA")
  193. //
  194. plotshape(ShowFractals ? filteredtopf : na, title='Filtered Top Fractals', style=shape.triangledown, location=location.abovebar, color=color.red, offset=-2)
  195. plotshape(ShowFractals ? filteredbotf : na, title='Filtered Bottom Fractals', style=shape.triangleup, location=location.belowbar, color=color.lime, offset=-2)
  196. //
  197. plotshape(ShowHHLL ? higherhigh : na, title='Higher High', style=shape.square, location=location.abovebar, color=color.maroon, text="[HH]", offset=-2)
  198. plotshape(ShowHHLL ? lowerhigh : na, title='Lower High', style=shape.square, location=location.abovebar, color=color.maroon, text="[LH]", offset=-2)
  199. plotshape(ShowHHLL ? higherlow : na, title='High Low', style=shape.square, location=location.belowbar, color=color.green, text="[HL]", offset=-2)
  200. plotshape(ShowHHLL ? lowerlow : na, title='Lower Low', style=shape.square, location=location.belowbar, color=color.green, text="[LL]", offset=-2)
  201. //
  202. // === /PLOTTING ===
  203.  
  204.  
  205. // === ALERTING ===
  206. //
  207.  
  208. // Initialise Trading state.
  209. TradeDirection = 0
  210. TradeDirection := nz(TradeDirection[1])
  211. //
  212. pacExitU = haOpen < pacU and haClose > pacU and barssince(haClose<pacC)<=Lookback
  213. pacExitL = haOpen > pacL and haClose < pacL and barssince(haClose>pacC)<=Lookback
  214. plotshape(barssince(haClose<pacC),color=na,location=location.bottom,title="barssince(haClose<pacC)")
  215. plotshape(barssince(close>pacC),color=na,location=location.bottom,title="barssince(haClose>pacC)")
  216. //
  217. Buy = TrendDirection == 1 and pacExitU
  218. Sell = TrendDirection == -1 and pacExitL
  219. //
  220. // Keep Current trading state until Pullback occurs or New Recovery.
  221. TradeDirection := TradeDirection == 1 and haClose<pacC ? 0 :
  222. TradeDirection == -1 and haClose>pacC ? 0 :
  223. TradeDirection == 0 and Buy ? 1 :
  224. TradeDirection == 0 and Sell ? -1 : TradeDirection
  225.  
  226. // Show buy/sell arrows
  227. plotarrow(ShowBuySell and nz(TradeDirection[1+Delay]) == 0 and TradeDirection[Delay] != 0 ? TradeDirection[Delay] : na, offset=-Delay,
  228. colorup=color.green, colordown=color.maroon, transp=20, minheight=20, maxheight=50, title="Buy/Sell Arrow")
  229. //
  230. // Create alerts for TradingView Alarm subsystem.
  231. Long = nz(TradeDirection[1]) == 0 and TradeDirection == 1
  232. Short = nz(TradeDirection[1]) == 0 and TradeDirection == -1
  233. alertcondition(Long, title="Buy Condition", message="BUY")
  234. alertcondition(Short, title="Sell Condition", message="SELL")
  235. //
  236. // === /ALERTING ===
  237.  
  238. // === eof.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement