I am trying to write code to let me know when the RSI value rises above 30 at the end of the last day's trading but only when it was below 30 on the day before that. So I am basically trying to find stocks where the RSI goes from below to above 30 looking at 2 days worth of trading.
I am using end of day data for my calculations so my bars are a single day.
The code I am using is as follows:
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
// Use this method for calculating your indicator values. Assign a value to each
// plot below by replacing 'Close[0]' with your own formula.
if (RSI(14, 3).Avg[0] > 30)
{
Value.Set(Variable0 = +1);
}
if (RSI(14, 3).Avg[1] < 30)
{
Value.Set(Variable0 = +1);
}
else
{
Value.Set(0.0);
}
}
The above code compiles fine but I am not sure it will give me what I need. Can someone please confirm whether my code is correct based on my requirement and please let me know what I need to change if it isn't.
I want to be able to output a value of +1 if it meets the 2 criteria and output 0 if it doesn't meet the 2 criteria.
I have used 2 consecutive if statements. I don't know if that is correct.
Hopefully one of you will be able to kindly assist me further.
Many thanks,
Evan
Comment