Indicator plots an SMA over several days - added via ninjascript.
How to, when the 1st bar of "today" prints (only once) get the value of the SMA at yesterday's last bar?
I am trying to use code similar to this but it is not working as expected, it seems top print more than once and the values don't quite match. Any tips on getting this right?
if ( CurrentBar == Bars.BarsSinceNewTradingDay) {
double val = SMA(20)[Bars.BarsSinceNewTradingDay + 1]; // get the value of "last" bar before the new session
Print(val);
}
Why does CurrentBar == Bars.BarsSinceNewTradingDay evaluate to true so many times? I'd expect this to eval true once a day.
Thank you kindly!
Comment