Page 1 of 1

Detecting the Last Bearish/Bullish Candle when Condition Trigger ?

Posted: Sun Mar 20, 2022 10:32 am
by Kalmb
Hi everyone,

I'm using one of the amazing lessons that Mathew create for this question (code below)
I want to plot line (hline) whenever condition trigger (As a Stoploss):

If the condition trigger "Long", plot hline (or anything lable or arrow or value) on the low of the last bearish or (red) candle whenever the indicator condition trigger.

If the condition trigger "Short", plot hline (or anything lable or arrow or value) on the high of last bullish or (green) candle whenever the indicator condition trigger.

Please I need someone help and attached screenshot of some example as I added hline manually.

https://ibb.co/JtwkM1R
https://ibb.co/WnWvL1S

Regards,
Kal


Lesson link
https://zenandtheartoftrading.com/pines ... -patterns/

Code:

//@version=5
indicator(title='Lesson 6', shorttitle='RSI Swing Signals', overlay=true)
// Get user input
rsiSource = input(title='RSI Source', defval=close)
rsiLength = input(title='RSI Length', defval=14)
rsiOverbought = input(title='RSI Overbought Level', defval=70)
rsiOversold = input(title='RSI Oversold Level', defval=30)
// Get RSI value
rsiValue = ta.rsi(rsiSource, rsiLength)
rsiOB = rsiValue >= rsiOverbought
rsiOS = rsiValue <= rsiOversold
// Identify engulfing candles
bullishEC = close > open[1] and close[1] < open[1]
bearishEC = close < open[1] and close[1] > open[1]
tradeSignal = (rsiOS or rsiOS[1]) and bullishEC or (rsiOB or rsiOB[1]) and bearishEC
// Plot signals to chart
plotshape(tradeSignal and bullishEC, title='Long', location=location.belowbar, color=color.new(color.green, 0), style=shape.triangleup, text='Long')
plotshape(tradeSignal and bearishEC, title='Short', location=location.abovebar, color=color.new(color.red, 0), style=shape.triangledown, text='Short')
// Send out an alert if this candle meets our conditions
alertcondition(tradeSignal, title='RSI Trade Alert!', message='RSI Swing Signal for XXX')