The issue I'm having is when the previous bars open and close are on opposite sides of the ema. Right now under those conditions after the second bar which opens and closes on opposite sides of the ema, the chart background colour reverts to white.
I'd like to have the indicator perform such that if the open and close are on opposite sides of the ema the chart backgrounds colour remains the same as the most recent bar which opened and closed on the same side of the ema.
I tried creating and calling a setColour() and getColour() function to solve this issue, but was not able to code it properly.
Any help is greatly appreciated. Here is the code I've written:
protected override void OnBarUpdate()
{
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 0)
return;
// bullish trend
if ((Open[0] > EMA1[0])
&& (Close[0] > EMA1[0]))
{
BackBrush = Brushes.Honeydew;
}
// bearish trend
if ((Open[0] < EMA1[0])
&& (Close[0] < EMA1[0]))
{
BackBrush = Brushes.MistyRose;
}
//bar that opens and closes on opposite side of ema
if ((Open[0] > EMA1[0] && Close[0] < EMA1[0])||(Open[0] < EMA1[0] && Close[0] > EMA1[0]))
{
if ((Open[1] > EMA1[1]) && (Close[1] > EMA1[1]))
{
BackBrush = Brushes.Honeydew;
}
if ((Open[1] < EMA1[1]) && (Close[1] < EMA1[1]))
{
BackBrush = Brushes.MistyRose;
}
}
}


Comment