PDA

View Full Version : Reading RSI value xx bar ago


vincentleaw
06-29-2010, 09:50 PM
I am new to C# and I hope someone can help me out on this.....

I am trying to create an indicator and part of the code requires reading the RSI value xx bars ago. I have the following code(below) but somehow when I try to debug it in the output window, the script doesn't seem to run past the initial section where I check to ensure there's enough bars on the chart

-----------------------------------------------


#region Variables
#endregion

protected override void Initialize() {
CalculateOnBarClose = false;
Overlay = false;
PriceTypeSupported = true;
}

/// Called on each bar update event (incoming tick)
protected override void OnBarUpdate() {
//Check to ensure there's enough bars on the chart
if(CurrentBar < 1)
{
Print("Not enough Bars");
return;
}
//Read the RSI value 10 bars ago
double RSI10 = RSIFunc(10);
Print(RSI10.ToString()); //prints to output window
}
private double RSIFunc(int Shift) {
double RSIValue = RSI(Close, 14, 1)[Shift];
return(RSIValue);
}

#region Properties
#endregion


-----------------------------------------------

Please Help:). Thanks in advance

NinjaTrader_Bertrand
06-30-2010, 03:18 AM
vincentleaw, welcome to our forums - I think this snippet will work if you tie your currentBars check to the Shift used, i.e. a check for 1 bar is too short to satisfy a shift of 10 like in your example.

vincentleaw
06-30-2010, 03:32 AM
Dear Bertrand,

Thank you for the reply. It works.

Cheers!!