I want to wait untill a condition is met before the strategy begins trading.
Trying to make code that waits for the 15 sma to cross below the 12 sma (the Start Trading condition), and then once that happens the strategy can begin trading, but only once the start trading condition is met.
How can I do this ?
--
I tryed to use a switch but this did not work
--
The code so far:
//@version=5
strategy("My script", overlay=true)
fifteensma = ta.sma(close, 15)
twelvesma = ta.sma(close, 12)
sevensma = ta.sma(close, 7)
fourteensma = ta.sma(close, 14)
starttrading = (fifteensma[0] < twelvesma[0] ) and (fifteensma[1] > twelvesma[1] )
longcondition = (sevensma[0] > fourteensma[0] ) and (sevensma[1] < fourteensma[1] )
starttradingsignalsoccurred = 0.0
//Wait untill a start trading signal occurs
if (starttrading)
//when a starttrading signal happens add 1 to the starttrading signal variable
starttradingsignalsoccurred := starttradingsignalsoccurred[1] + 1
if starttradingsignalsoccurred > 0
if ( longcondition)
//Enter Trade Long
strategy.entry("Long", strategy.long, qty=10)
plot(fifteensma, color=color.red)
plot(twelvesma, color=color.green)
plot(sevensma, color=color.orange)
plot(fourteensma, color=color.blue)