I have come across this once before - Fortunately, after 30 minutes of scratching my head, I remembered and put in the fix which made it all work. I would appreciate it if someone could explain to me why this is the case so I can understand this better.
I have some code which calls another indicator. Nothing complex, so indie1 = SMA(50) for example.
Exact code below
i = pjsRSI(Input,false);
Print("wins1="+i.tradestat_wins);
Print(i.tradestat_ready);
Print("wins2="+i.tradestat_wins);
Print(i.tradestat_ticks);
Print("Result : Total trades = "+ (i.tradestat_wins+i.tradestat_losses).ToString()+" , w/l = "+i.tradestat_wins.ToString()+"/"+i.tradestat_losses.ToString()+", MFETotal = "+i. tradestat_mfe.ToString()+", MFEAvg = "+(i.tradesta t_mfe/(i.tradestat_wins+i.tradestat_losses)).ToString("N 2")+", Maxticks = " + i.tradestat_ticks +", r = " + i.tradestat_r +", wr = %" + i.tradestat_wr +", i dx #" +d.ToString());
Print("wins3="+i.tradestat_wins);
You will see in the above code, I am printing the same variable i.tradestat_wins 3 times, wins1, wins2, and wins3, e.g. Print("wins1="+i.tradestat_wins);
This is the full code example. Bizarrely (to me!), this produces this output
wins1=0
False
wins2=0
-364
Result : Total trades = 88, w/l = 47/41, MFETotal = 418, MFEAvg = 4.75, Maxticks = -364, r = 0.6, wr = %53.4, idx #49
wins3=47
Note - The first 2 times I try to print the variable i.tradestat_wins, which is a publicly exposed value on the indicator, it reports a zero value. This had me confused! I recalled I'd had this before. The solution was simple.
Change the above code to this
i = pjsRSI(Input,false);
double dummy = i[0];
Print(dummy);
Print("wins1="+i.tradestat_wins);
Print(i.tradestat_ready);
Print("wins2="+i.tradestat_wins);
Print(i.tradestat_ticks);
PPrint("Result : Total trades = "+ (i.tradestat_wins+i.tradestat_losses).ToString()+" , w/l = "+i.tradestat_wins.ToString()+"/"+i.tradestat_losses.ToString()+", MFETotal = "+i. tradestat_mfe.ToString()+", MFEAvg = "+(i.tradesta t_mfe/(i.tradestat_wins+i.tradestat_losses)).ToString("N 2")+", Maxticks = " + i.tradestat_ticks +", r = " + i.tradestat_r +", wr = %" + i.tradestat_wr +", i dx #" +d.ToString());
Print("wins3="+i.tradestat_wins);
Note the addition of the 2nd and 3rd lines. Then, the output changes to this, as you would expect.
wins1=47
False
wins2=47
-364
Result : Total trades = 88, w/l = 47/41, MFETotal = 418, MFEAvg = 4.75, Maxticks = -364, r = 0.6, wr = %53.4, idx #49
wins3=47
I can recall I had this once before (which is why I tried the fix). It seems the instance of the indicator is perhaps not fully initialised until you try to access a series from it? In any case, I am sure I am missing some fundamental concept of how Ninja is working here, so if you could explain this seemingly bizarre behaviour to me or point me to some reference material, I would appreciate it.
Thanks
Comment