Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=2
- study(title="Fractals and Pivots R1 by JustUncleL", shorttitle="FRACTAL R1", overlay=true)
- // By: JustUncleL
- // Date: 13-Feb-2017
- // Version: R1
- //
- // Description:
- // This indicator display fractals, fractal levels, Pivot Points and HH/LL points.
- //
- // references:
- // - [RS]Fractal Levels by RicardoSantos
- //
- // Modifications:
- // R1 - original.
- //
- //
- //
- ShowPivots = input(true)
- ShowPivotLabels = input(false)
- ShowPivotNumbers = input(false)
- ShowFractals = input(true)
- ShowFractalLevels= input(false)
- ShowHHLL_ = input(false)
- ShowHHLL = ShowPivots?false:ShowHHLL_
- filterBW_ = input(false,"Show Ideal Fractals Only")
- //
- //
- // --- CONSTANTS ---
- DodgerBlue = #1E90FF
- filterBW = ShowPivots?true: filterBW_
- // --- /CONTANTS ---
- close_ = security(ticker, period, close)
- open_ = security(ticker, period, open)
- high_ = security(ticker, period, high)
- low_ = security(ticker, period, low)
- // ||--- Fractal Recognition Functions: ---------------------------------------------------------------||
- // ||-----------------------------------------------------------------------------------------------------||
- // ||--- Fractal Recognition Functions: ---------------------------------------------------------------||
- isIdealFractal(mode) =>
- ret = mode == 1 ? high_[5] < high_[4] and high_[4] < high_[3] and high_[3] > high_[2] and high_[2] > high_[1] :
- mode == -1 ? low_[5] > low_[4] and low_[4] > low_[3] and low_[3] < low_[2] and low_[2] < low_[1] : false
- isRegularFractal(mode) =>
- ret = mode == 1 ? high_[5] < high_[3] and high_[4] < high_[3] and high_[3] > high_[2] and high_[3] > high_[1] :
- mode == -1 ? low_[5] > low_[3] and low_[4] > low_[3] and low_[3] < low_[2] and low_[3] < low_[1] : false
- // ||-----------------------------------------------------------------------------------------------------||
- filteredtopf = filterBW ? isIdealFractal(1) : isRegularFractal(1)
- filteredbotf = filterBW ? isIdealFractal(-1) : isRegularFractal(-1)
- //plotshape(ShowFractals? filteredtopf :na, title='Filtered Top Fractals', style=shape.triangleup, location=location.abovebar, color=green, offset=-3, transp=20)
- //plotshape(ShowFractals? filteredbotf :na, title='Filtered Bottom Fractals', style=shape.triangledown, location=location.belowbar, color=red, offset=-3, transp=20)
- topf = isRegularFractal(1)
- botf = isRegularFractal(-1)
- topfractals = filteredtopf ? high_[3] : topfractals[1]
- botfractals = filteredbotf ? low_[3] : botfractals[1]
- topfcolor = topfractals != topfractals[1] ? na : green
- botfcolor = botfractals != botfractals[1] ? na : red
- // ||-----------------------------------------------------------------------------------------------------||
- // ||--- Higher Highs, Lower Highs, Higher Lows, Lower Lows -------------------------------------------||
- higherhigh = filteredtopf == false ? false : ( valuewhen(filteredtopf == true, high_[3], 1) < valuewhen(filteredtopf == true, high_[3], 0) and
- (ShowPivots or valuewhen(filteredtopf == true, high_[3], 2) < valuewhen(filteredtopf == true, high_[3], 0)))
- lowerhigh = filteredtopf == false ? false : ( valuewhen(filteredtopf == true, high_[3], 1) > valuewhen(filteredtopf == true, high_[3], 0) and
- (ShowPivots or valuewhen(filteredtopf == true, high_[3], 2) > valuewhen(filteredtopf == true, high_[3], 0)))
- higherlow = filteredbotf == false ? false : ( valuewhen(filteredbotf == true, low_[3], 1) < valuewhen(filteredbotf == true, low_[3], 0) and
- (ShowPivots or valuewhen(filteredbotf == true, low_[3], 2) < valuewhen(filteredbotf == true, low_[3], 0)))
- lowerlow = filteredbotf == false ? false : ( valuewhen(filteredbotf == true, low_[3], 1) > valuewhen(filteredbotf == true, low_[3], 0) and
- (ShowPivots or valuewhen(filteredbotf == true, low_[3], 2) > valuewhen(filteredbotf == true, low_[3], 0)))
- // If selected Display the HH/LL above/below candle.
- plotshape(ShowHHLL ? higherhigh : na, title='HH', style=shape.square, location=location.abovebar, color=maroon, text="[HH]", offset=-3,transp=0)
- plotshape(ShowHHLL ? lowerhigh : na, title='LH', style=shape.square, location=location.abovebar, color=maroon, text="[LH]", offset=-3,transp=0)
- plotshape(ShowHHLL ? higherlow : na, title='HL', style=shape.square, location=location.belowbar, color=green, text="[HL]", offset=-3,transp=0)
- plotshape(ShowHHLL ? lowerlow : na, title='LL', style=shape.square, location=location.belowbar, color=green, text="[LL]", offset=-3,transp=0)
- // If Selected Display Pivot points
- plotshape(ShowPivots and ShowPivotLabels? higherhigh : na, title='Higher High', style=shape.cross, location=location.abovebar, color=maroon, text="[HH]", offset=-3,transp=0)
- plotshape(ShowPivots and not ShowPivotLabels? higherhigh? high :na : na, title='Higher High+', style=shape.cross, location=location.abovebar, color=maroon, offset=-3,transp=0)
- plotshape(ShowPivots and ShowPivotLabels? lowerhigh : na, title='Lower High', style=shape.cross, location=location.abovebar, color=maroon, text="[LH]", offset=-3,transp=0)
- plotshape(ShowPivots and not ShowPivotLabels? lowerhigh? high : na : na, title='Lower High+', style=shape.cross, location=location.abovebar, color=maroon, offset=-3,transp=0)
- //
- plotshape(ShowPivots and ShowPivotLabels? higherlow : na, title='Higher Low', style=shape.cross, location=location.belowbar, color=green, text="[HL]", offset=-3,transp=0)
- plotshape(ShowPivots and not ShowPivotLabels? higherlow? low: na : na, title='Higher Low+', style=shape.cross, location=location.belowbar, color=green, offset=-3,transp=0)
- //
- plotshape(ShowPivots and ShowPivotLabels? lowerlow : na, title='Lower Low', style=shape.cross, location=location.belowbar, color=green, text="[LL]", offset=-3,transp=0)
- plotshape(ShowPivots and not ShowPivotLabels? lowerlow? low : na : na, title='Lower Low+', style=shape.cross, location=location.belowbar, color=green, offset=-3,transp=0)
- //
- // Number the Pivot candle fractal positions above or below candles
- plotchar(ShowPivots and ShowPivotNumbers? filteredtopf: na, title='High 1u', location=location.abovebar, color=maroon, char="1", offset=-5,transp=0)
- plotchar(ShowPivots and ShowPivotNumbers? filteredtopf: na, title='High 2u', location=location.abovebar, color=maroon, char="2", offset=-4,transp=0)
- plotchar(ShowPivots and ShowPivotNumbers ? filteredtopf: na, title='High 2d', location=location.abovebar, color=maroon, char="2", offset=-2,transp=0)
- plotchar(ShowPivots and ShowPivotNumbers ? filteredtopf: na, title='High 1d', location=location.abovebar, color=maroon, char="1", offset=-1,transp=0)
- //
- plotchar(ShowPivots and ShowPivotNumbers ? filteredbotf: na, title='Low 1d', location=location.belowbar, color=green, char="1", offset=-5,transp=0)
- plotchar(ShowPivots and ShowPivotNumbers ? filteredbotf: na, title='Low 2d', location=location.belowbar, color=green, char="2", offset=-4,transp=0)
- plotchar(ShowPivots and ShowPivotNumbers ? filteredbotf: na, title='Low 2u', location=location.belowbar, color=green, char="2", offset=-2,transp=0)
- plotchar(ShowPivots and ShowPivotNumbers ? filteredbotf: na, title='Low 1u', location=location.belowbar, color=green, char="1", offset=-1,transp=0)
- havespot = not ShowPivots or (ShowPivots and not(higherhigh or lowerhigh or higherlow or lowerlow))
- plotshape(havespot and ShowFractals? topf :na, title='Regular Top Fractals', style=shape.triangleup, location=location.abovebar, color=red, offset=-3,transp=0)
- plotshape(havespot and ShowFractals? botf :na, title='Regular Bottom Fractals', style=shape.triangledown, location=location.belowbar, color=green, offset=-3,transp=0)
- plot(ShowFractalLevels? topfractals : na, color=topfcolor, transp=0, linewidth=2)
- plot(ShowFractalLevels? botfractals : na, color=botfcolor, transp=0, linewidth=2)
- //
- //EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement