declare lower; input marketThreshold = 0.0025; input timeFrame = {default DAY, "2 DAYS", "3 DAYS", "4 DAYS", WEEK, MONTH, "OPT EXP"}; input showOnlyToday = no; input applyPersonsLevelsFilter = yes; #Persons_Pivots Assert(marketThreshold >= 0, "'market threshold' must not be negative: " + marketThreshold); def marketType = {default DISABLED, NEUTRAL, BEARISH, BULLISH}; def PP2 = high(period = timeFrame)[2] + low(period = timeFrame)[2] + close(period = timeFrame)[2]; marketType = if !applyPersonsLevelsFilter then marketType.DISABLED else if PP2[-1] > (PP2[-1] + PP2 + PP2[1]) / 3 + marketThreshold then marketType.BULLISH else if PP2[-1] < (PP2[-1] + PP2 + PP2[1]) / 3 - marketThreshold then marketType.BEARISH else marketType.NEUTRAL; def R3; def R2; def R1; def RR; def PP; def SS; def S1; def S2; def S3; if showOnlyToday and !IsNaN(close(period = timeFrame)[-1]) then { R1 = Double.NaN; R2 = Double.NaN; R3 = Double.NaN; PP = Double.NaN; S1 = Double.NaN; S2 = Double.NaN; S3 = Double.NaN; } else { PP = (high(period = timeFrame)[1] + low(period = timeFrame)[1] + close(period = timeFrame)[1]) / 3; R1 = 2 * PP - low(period = timeFrame)[1]; R2 = PP + high(period = timeFrame)[1] - low(period = timeFrame)[1]; R3 = R2 + high(period = timeFrame)[1] - low(period = timeFrame)[1]; S1 = 2 * PP - high(period = timeFrame)[1]; S2 = PP - high(period = timeFrame)[1] + low(period = timeFrame)[1]; S3 = S2 - high(period = timeFrame)[1] + low(period = timeFrame)[1]; } RR = if (marketType == marketType.BEARISH or marketType == marketType.NEUTRAL) then R1 else R2; SS = if (marketType == marketType.BULLISH or marketType == marketType.NEUTRAL) then S1 else S2; #Signals plot up = close crosses above pp and (close crosses above ss) within 90 bars; plot down = close crosses below pp and (close crosses below rr) within 90 bars; up.SetPaintingStrategy(paintingStrategy = PaintingStrategy.BOOLEAN_WEDGE_UP); up.SetLineWeight(lineWeight = 5); up.SetDefaultColor(color = Color.BLUE); down.SetPaintingStrategy(paintingStrategy = PaintingStrategy.BOOLEAN_WEDGE_DOWN); down.SetLineWeight(lineWeight = 5); down.SetDefaultColor(color = Color.DARK_RED);