Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=3
- //
- study(title = "Pullback Trading Tool R10.1 by JustUncleL", shorttitle = "PBTOOL R10.1", overlay = true)
- //
- //
- // Revision: R10
- // Original Author: JustUncleL
- //
- // Description:
- // This study is an alternative Pullback trading Tool to my previous R5 version.
- // It incorporates the majority of the indicators needed to analyse trade Trends for Pullbacks and Reversals.
- // The set up utilies, optionally, Heikin Ashi candle charts.
- //
- // NOTE: A Pullback is synomous to Retracement, generally a Pullback refers to a large Retracement of 100pips
- // or more. In the context of this Tool and any comments related to it, a Pullback will be the
- // same as a Retracement.
- //
- // Incorporated within this tool are the following indicators:
- // 1. Three Moving Averages (EMA by default) that can optionally be Anchored to a Higher Time Frame:
- // - DodgerBlue = EMA08 (default)
- // - Green = EMA50 (default)
- // - Gray = EMA200 (default)
- // 2. One Signal Moving Average line Yellow EMA21 (default), optionally Anchored to HTF.
- // 3. Two Un-Anchored Moving Averages, only display when there is an HTF Anchor specified.
- // - Aqua = EMA08 (default)
- // - Fuchsia = EMA21 (default)
- // 4. Display Fractals/Pivots and optional Fractal/Pivot Levels
- // 5. HH, LH, LL, HL finder to help with drawing Trend lines and mini Trend Lines.
- // 6. Coloured coded Bar based on the signal MA:
- // the Standard candle colours:
- // - Blue = candle open and closed above signal MA.
- // - Red = candle open and closed below signal MA.
- // - Yellow = Candle stradle across signal MA.
- // the Grab candles scheme:
- // - Lime = Bull candle open and closed above signal MA.
- // - Green = Bear candle open and closed above signal MA.
- // - Red = Bull candle open and closed below signal MA.
- // - DarkRed = Bear candle open and closed below signal MA.
- // - Aqua = Bull candle closed across signal MA.
- // - Blue = Bear candle stradle across signal MA.
- //
- //
- // Setup and hints:
- // I cannot go into a full description, as Pullback trading incorporates a full trading Methodology,
- // there are many articles and books written on the subject.
- //
- // - I also add a "Sweetspot Gold RN" indicator to the chart as well to help with support and resistance
- // finding and shows where the important "00" lines are.
- // - First on a weekly basis say Sunday night or Monday morning, analyse the Daily and Weekly charts
- // to establish overall trends, and support/resistant levels. Draw significant trend lines,
- // vertical trend lines (VTL) and S/R levels. Use Pivots option to guide VTL drawing and use Fractals
- // to help guide TL drawing.
- // - Once the trend direction and any potential major reversals highlighted, drop down to the 4hr chart
- // and draw appropriate mini Trend line matching the established momentum direction. Take note of
- // potential pull backs from and of the EMAs, in particular the 36EMA and the 200EMA. Can use the
- // Fractals and HH/LL points to guide your TL drawing.
- // - Check to see if the TL is broken and is pulling back off one of the EMA lines, then trade
- // that alert, or drop down to lower time frames (TF) and perform the same analysis there and trade at the lower
- // TF. Trading at lower TF you will be able to get tighter Stop loss settings.
- // - Other than the SweetSpot Gold RN indicator, you should not require any other indicator to trade trends
- // for pull backs and reversals.
- //
- // Revisions:
- //
- // R1 to R7 Original Versions by JustUncleL
- //
- // R10 Alternate version by JustUncleL.
- //
- // References:
- // - Scalp Jockey v2 by Jay Rogers
- // - [RS]Fractals V8 by RicardoSantos
- // - SweetSpot Gold RN by JustUncleL
- // - Price Action Trading System v0.3 by JustUncleL
- // - http://www.swing-trade-stocks.com/pullbacks.html
- //
- //
- // -----------------------------------------------------------------------------
- // Copyright 2017 JustUncleL
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // The GNU General Public License can be found here
- // <http://www.gnu.org/licenses/>.
- //
- // -----------------------------------------------------------------------------
- //
- // === INPUTS ===
- // Un-Anchored Fast + Slow MA - Type and Length
- fastType = input(defval="EMA", title="Fast Un-Anchored MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"], type=string)
- fastLen = input(defval=8, title="Fast Un-Anchored MA Length:", minval=1)
- slowType = input(defval="EMA", title="Slow Un-Anchored MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"], type=string)
- slowLen = input(defval=21, title="Slow Un-Anchored MA Length:", minval=1)
- //
- // Anchor Higher Time Frame
- anchorTF = input(0,minval=0,maxval=1440,title="Anchor TimeFrame (0=none, max=1440 (mins,D,W)")
- //
- // Anchored Fast+ Medium + Slow MA - type, length
- fastAnchorType = input(defval="EMA", title="Fast Anchored MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"], type=string)
- fastAnchorLen_ = input(defval=8, title="Fast Anchored MA Length:", minval=1)
- mediumAnchorType = input(defval="EMA", title="Medium Anchored MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"], type=string)
- mediumAnchorLen_ = input(defval=50, title="Medium Anchored MA Length:", minval=1)
- slowAnchorType = input(defval="EMA", title="Slow Anchored MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"], type=string)
- slowAnchorLen_ = input(defval=200, title="Slow Anchored MA Length:", minval=1)
- // Signal MA
- anchorSignal = input(true,title="Anchor the Signal MA:")
- signalType = input(defval="EMA", title="Signal MA Type: ", options=["SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "ZEMA", "TMA", "SSMA"], type=string)
- signalLen_ = input(defval=21, title="Signal MA Length:", minval=1)
- //
- ShowBarColor = input(true, title="Show coloured Bars close relative to Signal MA")
- useGrabClr = input(false, title="Use Grab Candle (6-tone) Colouring, instead of Standard (3-tone)")
- // Pivots
- ShowPivots = input(true,title="Show Pivot Points")
- pvtLenL = input(2,minval=1,title="Pivot Length Left Hand Side")
- pvtLenR = input(2,minval=1,title="Pivot Length Right Hand Side")
- ShowSRLevels = input(false,title="Show S/R Level Extensions")
- maxLvlLen = input(0,minval=0, title="Maximum S/R Level Extension Length")
- uRenko = input(false, title="Use Renko Style Pivots (open/close for high/low)")
- ShowHHLL = input(false)
- ma_src = input(close,title="Source for Moving Averages")
- //
- //
- // --- CONSTANTS ---
- DodgerBlue = #1E90FF
- Gold = #FFD700
- // --- /CONTANTS ---
- //
- // Constants colours that include fully non-transparent option.
- GREEN = #008000FF
- LIME = #00FF00FF
- RED = #FF0000FF
- BLUE = #0000FFFF
- AQUA = #00FFFFFF
- DARKRED = #8B0000FF
- GRAY = #808080FF
- YELLOW = #FFFF00FF
- GOLD = #FFD700FF
- DODGERBLUE = #1E90FFFF
- //
- // === /INPUTS ===
- // === FUNCTIONS ===
- // - variant(type, src, len)
- // Returns MA input selection variant, default to SMA if blank or typo.
- // SuperSmoother filter
- // © 2013 John F. Ehlers
- variant_supersmoother(src,len) =>
- a1 = exp(-1.414*3.14159 / len)
- b1 = 2*a1*cos(1.414*3.14159 / len)
- c2 = b1
- c3 = (-a1)*a1
- c1 = 1 - c2 - c3
- v9 = 0.0
- v9 := c1*(src + nz(src[1])) / 2 + c2*nz(v9[1]) + c3*nz(v9[2])
- v9
- variant_smoothed(src,len) =>
- v5 = 0.0
- v5 := na(v5[1]) ? sma(src, len) : (v5[1] * (len - 1) + src) / len
- v5
- variant_zerolagema(src,len) =>
- ema1 = ema(src, len)
- ema2 = ema(ema1, len)
- v10 = ema1+(ema1-ema2)
- v10
- variant_doubleema(src,len) =>
- v2 = ema(src, len)
- v6 = 2 * v2 - ema(v2, len)
- v6
- variant_tripleema(src,len) =>
- v2 = ema(src, len)
- v7 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
- v7
- // return variant, defaults to SMA
- variant(type, src, len) =>
- type=="EMA" ? ema(src,len) :
- type=="WMA" ? wma(src,len):
- type=="VWMA" ? vwma(src,len) :
- type=="SMMA" ? variant_smoothed(src,len) :
- type=="DEMA" ? variant_doubleema(src,len):
- type=="TEMA" ? variant_tripleema(src,len):
- type=="HullMA"? wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) :
- type=="SSMA" ? variant_supersmoother(src,len) :
- type=="ZEMA" ? variant_zerolagema(src,len) :
- type=="TMA" ? sma(sma(src,len),len) :
- sma(src,len)
- // - /variant
- // === /FUNCTIONS ===
- // === SERIES ===
- // If this is 5min or less Time Frame select EMAs
- mult = not isintraday or anchorTF==0 or interval<=0 or interval>=anchorTF or anchorTF>1440 ? 1 : round(anchorTF/interval)>1? round(anchorTF/interval) : 1
- mult := isintraday or anchorTF==0 or interval<=0 or interval>=anchorTF or anchorTF>52 ? mult : round(anchorTF/interval)>1? round(anchorTF/interval) : 1
- fastAnchorLen = mult==1 ? fastAnchorLen_ : (fastAnchorLen_*mult)
- mediumAnchorLen = mult==1 ? mediumAnchorLen_ : (mediumAnchorLen_*mult)
- slowAnchorLen = mult==1 ? slowAnchorLen_ : (slowAnchorLen_*mult)
- signalLen = not anchorSignal or mult==1 ? signalLen_ : (signalLen_*mult)
- // Get the two MAs
- fastMA = variant(fastType,ma_src, fastLen)
- slowMA = variant(slowType,ma_src, slowLen)
- signalMA = variant(signalType,ma_src, signalLen)
- fastAnchorMA = variant(fastAnchorType,ma_src, fastAnchorLen)
- mediumAnchorMA = variant(mediumAnchorType,ma_src, mediumAnchorLen)
- slowAnchorMA = variant(slowAnchorType,ma_src, slowAnchorLen)
- // - PIVOT VARIABLES
- //
- high_ = uRenko? max(close,open) : high
- low_ = uRenko? min(close,open) : low
- // Get High and Low Pivot Points
- pvthi = pivothigh(high_,pvtLenL,pvtLenR)
- pvtlo = pivotlow(low_,pvtLenL,pvtLenR)
- // Force Pivot completion before plotting.
- //pvthi = pvthi_[1]
- //pvtlo = pvtlo_[1]
- // ||-----------------------------------------------------------------------------------------------------||
- // ||--- Higher Highs, Lower Highs, Higher Lows, Lower Lows -------------------------------------------||
- higherhigh = pvthi ? ( valuewhen(pvthi, high_[pvtLenR], 1) < valuewhen(pvthi, high_[pvtLenR], 0) ) : pvthi
- lowerhigh = pvthi ? ( valuewhen(pvthi, high_[pvtLenR], 1) > valuewhen(pvthi, high_[pvtLenR], 0) ) : pvthi
- higherlow = pvtlo ? ( valuewhen(pvtlo, low_[pvtLenR], 1) < valuewhen(pvtlo, low_[pvtLenR], 0) ) : pvtlo
- lowerlow = pvtlo ? ( valuewhen(pvtlo, low_[pvtLenR], 1) > valuewhen(pvtlo, low_[pvtLenR], 0) ) : pvtlo
- // === /SERIES ===
- // === PLOTTING ===
- //
- // Colour bars according to the close position relative to the PAC selected.
- bColour = open>signalMA and close>signalMA? DODGERBLUE :
- open<signalMA and close<signalMA? RED :
- YELLOW
- bColour := not useGrabClr ? bColour :
- open>signalMA and close>signalMA? open>close?GREEN:LIME :
- open<signalMA and close<signalMA? open>close?DARKRED:RED :
- open>close?BLUE:AQUA
- barcolor(ShowBarColor?bColour:na, title = "Signal Bar Colours")
- // Draw the EMA ribbon
- plot(mult>1?fastMA:na, color=aqua,join=true,linewidth=1,transp=10,title="Fast MA")
- plot(mult>1?slowMA:na, color=fuchsia,join=true,linewidth=1,transp=10,title="Slow MA")
- //
- plot(signalMA, color=Gold,join=true,style=circles,linewidth=2,transp=20,title="Signal MA")
- //
- plot(fastAnchorMA, color=DodgerBlue,join=true,style=circles,linewidth=2,transp=20,title="Fast Anchored MA")
- plot(mediumAnchorMA, color=green,join=true,style=circles,linewidth=2,transp=20,title="Medium Anchored MA")
- plot(slowAnchorMA, color=gray,join=true,style=circles,linewidth=2,transp=20,title="Slow Anchored MA")
- // If selected Display the HH/LL above/below candle.
- plotshape(ShowHHLL ? higherhigh : na, title='HH', style=shape.square, location=location.abovebar, color=lime, text="HH", offset=-pvtLenR,transp=20)
- plotshape(ShowHHLL ? lowerhigh : na, title='LH', style=shape.square, location=location.abovebar, color=red, text="LH", offset=-pvtLenR,transp=20)
- plotshape(ShowHHLL ? higherlow : na, title='HL', style=shape.square, location=location.belowbar, color=lime, text="HL", offset=-pvtLenR,transp=20)
- plotshape(ShowHHLL ? lowerlow : na, title='LL', style=shape.square, location=location.belowbar, color=red, text="LL", offset=-pvtLenR,transp=20)
- // If Selected Display Pivot points
- plotshape(ShowPivots ? pvthi :na, title='High Pivot *', location=location.abovebar, style=shape.triangleup,color=green, offset=-pvtLenR,transp=0,size=size.auto)
- plotshape(ShowPivots ? pvtlo :na, title='Low Pivot *', location=location.belowbar, style=shape.triangledown,color=maroon, offset=-pvtLenR,transp=0,size=size.auto)
- //Count How many candles for current Pivot Level, If new reset.
- counthi = 0
- countlo = 0
- counthi := pvthi ? 0 : nz(counthi[1])+1
- countlo := pvtlo ? 0 : nz(countlo[1])+1
- pvthis = 0.0
- pvtlos = 0.0
- pvthis := pvthi ? high[pvtLenR] : pvthis[1]
- pvtlos := pvtlo ? low[pvtLenR] : pvtlos[1]
- hipc = (pvthis != pvthis[1]) ? na : green
- lopc = (pvtlos != pvtlos[1]) ? na : maroon
- plot(ShowSRLevels and (maxLvlLen==0 or counthi<maxLvlLen)? pvthis : na, color=hipc, transp=0, linewidth=1, offset=-pvtLenR, title="Top Levels")
- plot(ShowSRLevels and (maxLvlLen==0 or countlo<maxLvlLen)? pvtlos : na, color=lopc, transp=0, linewidth=1, offset=-pvtLenR, title="Bottom Levels")
- plot(ShowSRLevels and (maxLvlLen==0 or counthi<maxLvlLen) ? pvthis : na, color=hipc, transp=0, linewidth=1, offset=0, title="Top Levels 2")
- plot(ShowSRLevels and (maxLvlLen==0 or countlo<maxLvlLen) ? pvtlos : na, color=lopc, transp=0, linewidth=1, offset=0, title="Bottom Levels 2")
- // === /PLOTTING ===
- //
- // === ALERTS ===
- // === /ALERTS ===
- // === eof
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement