Department
New member
Hello,
I was wondering if someone knew how to code a price level that starts and ends on a condition? I have certain bars I'd like to trigger a price level. This level would then stop at the point were price touched it again.
My current code is below with the level indicated but I don't know how to make the line appear and only extend to the next time that price is touched.
This would ideally result in a graph as shown below:
I was wondering if someone knew how to code a price level that starts and ends on a condition? I have certain bars I'd like to trigger a price level. This level would then stop at the point were price touched it again.
My current code is below with the level indicated but I don't know how to make the line appear and only extend to the next time that price is touched.
Code:
input history = 10;
input multiplier = 1.5;
def highLow = high - low;
def body = bodyHeight();
def greenCandle = open < close;
def redCandle = close < open;
def volatility = atr(history);
def significantBar = volatility * multiplier;
def imBody = (body > highLow* 0.5) and (highLow >= significantBar);
assignPriceColor(if imBody and greenCandle then Color.dark_green else Color.Current);
assignPriceColor(if imBody and redCandle then Color.dark_red else Color.Current);
#These would be the price levels drawn on the chart.
#They start at the previous candle's high/low and end once price returns to that price.
#Green Candles
plot supportLevel = if imBody and greenCandle then high[1] else double.NaN;
supportLevel.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
#Red Candles
plot resistenceLevel = if imBody and redCandle then low[1] else double.NaN;
resistenceLevel.setPaintingStrategy(PaintingStrategy.VALUES_ABOVE);
This would ideally result in a graph as shown below: