I am chewing my way through Ninja Script codeng and making some progress at last. I have a indicator that simply plots +1 and -1 for given conditions which works fine.
Second step is to find out how many bars ago the last occurence of +1 in the indicator was. In Metastock, this is a standard formula 'BarsSince(condition)' and I am looking for th NS equivalent.
In the attachment, the chart plots bars green when the indicator plots +1. The lowest indicator is my attempt to count # of bars between each green bar for which the coding is below. However, this not working as I expected.
Between occurence 0 and occurence -1 as plotted on the chart, there are 22 bars in between, indicator plots 19.
Between occurence -1 and occurence -2 as plotted on the chart, there are 38 bars in between, indicator plots 16.
Pretty sure this is doable but not quite sure ho to get there.
Any thoughts on this?
Thanks,
leduc
Coding of indicator
{
if (CurrentBar == 0)
Plot0.Set(0);
else
{
double dblPrevClose = Close[1];
double dblAtrVal = ATR(AtrLength)[1];
double dblTriggerUp = dblPrevClose + dblAtrVal;
double dblTriggerDown = dblPrevClose - dblAtrVal;
if (CrossAbove(Close, dblTriggerUp,1))
{
int intNumBarsBack = CountIf(delegate {return CrossAbove(Close, dblTriggerUp,1);}, 999);
Plot0.Set(intNumBarsBack);
Comment