I have got an exploration that filters out stocks if they are below the 200 day MA. Unfortunately this only works when there are at least 200 available bars. What I would like to happen is for the exploration to do this.
If there are more than 200 available bars
Trendup = Close>ma(Close,200);
If there are less than 200 available bars
Trendup = Close>MA(Close,50);
I have tried to write this but I'm getting errors and I haven't managed to find out whats wrong. Could someone please help.
firstBar = BarIndex() == 0;
if(BarsSince(firstBar)>200)
{
Trendup=Close>MA(Close,200);
else
Trendup=Close>MA(Close,50);
}
I am also curious as to why I can plot a 50 period wma on a chart and it will plot from the second bar and yet if I try to plot a 50 period ma I have to wait for 50 bars. Why is this?