I have to plot entries and exits by simulating a strategy within an indicator. The strategy buys if the candle is green and sells when the RSI indicator is overbought. The script plots each signal but does not follow a real strategy in which a new order is only opened if the previous one is closed. I have to teach my script this; each entry corresponds to an exit. To do this I declared a bool variable "isLong" which becomes "true" when the entry condition is met. Then the close of the trade and the corresponding signal should only be plot if the trade has been opened so I have declared that the close should only occur if "isLong==true".
The script still does not work correctly. Signals are opened and closed without following logic. I cannot find any examples of this online. I would be pleased and grateful if someone could explain to me how to configure this part of the code by explaining the reasoning.
//@version=5
indicator("Test", overlay = false)
isLong = false
entryCondition = close > open
exitCondition = ta.crossover(ta.rsi(close, 14), 70)
if entryCondition
isLong := true
if isLong == true and exitCondition
isLong := false
plotshape(entryCondition, color = color.green)
plotshape(exitCondition, color = color.green)