mat
Pine Script Rookie
Pine Script Rookie
Posts: 1
Joined: September 26th, 2023

market structure x day breakout withconditions

this is what i wanted from the script

- when the closing price is above yesterday's value of the indicator then the indcator today the is the minimum of the last 3 days and so continues until a maximum greater than highestsinceevent is made; when instead a maximum greater than highestsinceevent is not made then the indcator today is the value of the indicator yesterday
-when the closing price is below yesterday's value of the indicator then the indcator today is the maximum of the last 3 days and so continues until a minimum lower than lowestsinceevent is made; when a minimum lower than lowestsinceevent is not made then the indcator today is the value of the indicator yesterday

however it does not plot anything...can someone help me?? Thanksss :)

CODE-------------------------------------------------------

//@version=5
indicator(title="Median", overlay=true, timeframe="", timeframe_gaps=true)

// 3-days price breakout

length = input.int(title = "Length2", defval=3, minval=1)
highest = ta.highest(close,length)
lowest = ta.lowest(close,length)
var float trail2= low

cond1 = close[1] < trail2[2] and close > trail2[1]
cond2 = close > trail2[1] and close[1] > trail2[2]
cond3 = close < trail2[1] and close[1] < trail2[1]
cond4 = close[1] > trail2[2] and close < trail2[2]

eventCondition = cond1

var float highestSinceEvent = na

// Calculate the highest value since the event occurred
if eventCondition
highestSinceEvent := high
else if not na(highestSinceEvent) and high > highestSinceEvent
highestSinceEvent := high

//plot(highestSinceEvent, title="Highest Since Event", color=color.blue)


eventCondition2 = cond4

var float lowestSinceEvent = na

// Calculate the lowest value since the event occurred
if eventCondition2
lowestSinceEvent := low
else if not na(lowestSinceEvent) and low < lowestSinceEvent
lowestSinceEvent := low

//


trail2 := if cond1
lowest
else if cond2 and high > highestSinceEvent
lowest
else if cond2 and high < highestSinceEvent
trail2[1]
else if cond4
highest
else if cond3 and low < lowestSinceEvent
highest
else if cond3 and low > lowestSinceEvent
trail2[1]


//



uptrend2 = close > trail2[1]

p3 = plot(trail2, color=uptrend2 ? color.green : color.red ,linewidth=3)

Return to “Request Scripts”