PDA

View Full Version : Getting Historical Values Using DataSeries..


nmussa
10-02-2007, 04:39 PM
Hello-

I am new to Ninja Trader migrating from Tradestation. I am currently converting some code with some success. My programming skills are rudimentary, certainly not great.

I am currently bumping up against some walls in using DataSeries and was hoping someone with greater experience could lend a hand.

Summary:
I am trying to compare values of a data series by referencing the variable and then using the brackets to specify the historical bar.

Example:
if (RSIWeightedAverage[0] < RSI RSIWeightedAverage[1]) &&
(RSIWeightedAverage[1] < RSI RSIWeightedAverage[2])
{
Print("RSIWAvg is falling.");
}


Problem:
Prior to adding this statement or any statement that references historical bars, I am able to print out the values correctly. The problem is that once I try and reference any historical value, it DOES compile, but the value is way off. It is no longer between 1 and 100 and all of my variables equal each other...in this case 825.6.

Example:
In summary, I am able to get the value for this:

RSIWAvg.Set(WMA(_RSI,13)[0]);
Print("WRSI is: " + RSIWAvg);

This prints the number: 36.69 (a valid RSI #)

but get a false value (again, it compiles) for this:

RSIWAvg.Set(WMA(_RSI,13)[0]);
Print("WRSI is: " + RSIWAvg[3]);

This prints the number: 826.6 and all other variables print the same number. (not a valid RSI value)

Any help is greatly appreciated.

Nick

NinjaTrader_Josh
10-02-2007, 09:23 PM
Hi nmussa,

Please check the values of your _RSI DataSeries. I suggest plotting that DataSeries and seeing what it looks like. I suspect the values are off when you set that DataSeries.

Also please check out this link for help with debugging: http://www.ninjatrader-support.com/vb/showthread.php?p=16558#post16558

nmussa
10-03-2007, 06:51 AM
Josh, thanks for responding. _RSI, RSIAvg, and RSIWAvg are established as follows (Code shortened for brevity):

Variables:
private DataSeries _RSI;
private DataSeries _RSI;
private DataSeries RSIAvg;

protected override void Initialize()..
_RSI = new DataSeries(this);
RSIAvg = new DataSeries(this);
RSIWAvg = new DataSeries(this);

protected override void OnBarUpdate()
_RSI.Set(RSI(Close,7,0)[0]);
Print("RSI is: " + _RSI);
//Print("RSI is: " + _RSI[1] + " " + _RSI[2]);

RSIAvg.Set(SMA(_RSI,50)[0]);
Print("RSIAvg: " + RSIAvg);

RSIWAvg.Set(WMA(_RSI,3)[0]);
Print("WRSI is: " + RSIWAvg);

The output of this is:

WRSI is: 1.32105414045233
RSI is: 2.11233505776232
RSIAvg: 42.2158694944319
WRSI is: 1.74686223061979
RSI is: 2.10626399743948
RSIAvg: 41.8393368424933
WRSI is: 1.98747525188672

If I make this change and switch the commented lines to:

//Print("RSI is: " + _RSI);
Print("RSI is: " + _RSI[1] + " " + _RSI[2]);

Then everything compiles and there are no errors, but I recieve no output. I can get a test print statement out of the initialize section. Print("This is a test.); does print once.

Since there is no error, I am at a loss on how to proceed next. Thanks again for your time.

Nick

NinjaTrader_Ray
10-03-2007, 07:05 AM
If an indicator/strategy does not produce output, always look at the Control Center Log tab for runtime errors.

This "Tip" will likely solve your problem.

http://www.ninjatrader-support.com/vb/showthread.php?t=3170

nmussa
10-03-2007, 07:47 AM
That did it. I did not know about the Log tab for development. Good stuff.

Both of your help is much appreciated.