06-29-2023 02:54 PM
Hi,
Just returned to TS and I'm trying to code a rule where over the last X bars, price was above EMA 20 for X-Y times - where X-1, or X-2 etc.
On another site, they support a looping rule;
LoopSum("Close(CTR)>SMA(20,0)",10) for example. LoopSum counts the number of time the condition in quotes is true. CTR is a private variable inside LoopSum and the second arg specifies the number of times to loop.
So if I wanted to screen for a stock that closed above SMA20 at least 7 times over the last 10 days, this would work;
LoopSum("Close(CTR)>SMA(20,0)",10)>=7
Can I do the same in TS?
Best,
Walter