I hope my message finds you well. I am trying to write a strategy which uses the swing indicator and the RSI. I provide the code below:
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 150) // I even incremented the bars here, but still does the error.
return;
Print (Time[0]);
int SwingLow = swing1.SwingLowBar(0, 1, 20);
Print("swingLow :" + SwingLow);
double SwingLowPrice = Low[Math.Max(0,SwingLow)];
Print("PriceLow :" + SwingLowPrice);
int SwingLow1 = swing1.SwingLowBar(0,2,40);
Print("swingLow1 :" + SwingLow1);
double SwingLowPrice1 = Low[Math.Max(0,SwingLow1)];
Print ("SwingLowPrice1 " + SwingLowPrice1);
Entrycondition();
}
private bool _RSIDivergence;
private void Entrycondition()
{
int SwingLow = swing1.SwingLowBar(0, 1, 20);
double SwingLowPrice = Low[Math.Max(0, SwingLow)];
_RSIDivergence = Close[1] < SwingLowPrice;
_RSIDivergence = DavideRSI[1] > DavideRSI[SwingLow];
_RSIDivergence = Close[0] > High[1];
if (_RSIDivergence)
BackBrush = Brushes.Blue;
}
I don't understand because until I wrote the conditions _RSIDivergence the strategy was working fine with Printing the different values for the Swing variables.
I really thank you for your help.
Best Regards
David

Comment