PDA

View Full Version : Trying to plot a cumulative index


kaywai
01-24-2010, 05:12 AM
Hi,

Trying to create a cumulative index using the formula ((Close[0]-Open[0])/(High[0]-Low[0])).

The code is attached. The error I am getting is "Error on plotting indicator 'pressurecum'. Please check the 'OnBarUpdate' or the Plot method: Overflow error. I suppose when High[0] - Low[0] = 0, that is when the problem happens.

Can someone help with a workaround? Thanks!

NinjaTrader_Ben
01-24-2010, 11:22 AM
Hello,

I didn't look in your zip (we don't really debug for people), but you might want to just build a condition that filters out that 0 occurance:
if(High[0] != Low[0])
{
//plot here
}

kaywai
01-24-2010, 11:39 AM
Ben,

Apart from the Add(new Plot...)line, I only have this line:-

PCum.Set((Close[0]-Open[0])/(High[0]-Low[0]));

Not sure what I can do here to address the issue of (High[0]-Low[0]) = 0.

If I want to keep the previous value in such circumstances, what would I have to write in the script?

PrTester
01-24-2010, 06:33 PM
Ben,

Apart from the Add(new Plot...)line, I only have this line:-

PCum.Set((Close[0]-Open[0])/(High[0]-Low[0]));

Not sure what I can do here to address the issue of (High[0]-Low[0]) = 0.

If I want to keep the previous value in such circumstances, what would I have to write in the script?

Try this http://www.ninjatrader-support2.com/vb/showthread.php?t=3170

kaywai
01-24-2010, 07:05 PM
PrTester, I don't have an issue with insufficient bars. The issue lies with the denominator (High[0]-Low[0])=0. As you know, nothing can be divisible by zero....

PrTester
01-24-2010, 07:15 PM
PrTester, I don't have an issue with insufficient bars. The issue lies with the denominator (High[0]-Low[0])=0. As you know, nothing can be divisible by zero....

double denom = (High[0]-Low[0]);
if( denom <= 0)
denom =1;