The code paints the bars but I am finding when I look back at historic price bars it is sometimes not painting the first bar where the conditions exists but the next bar.
My code is the following.
protectedoverridevoid Initialize()
{
CalculateOnBarClose = true;
Overlay = false;
PriceTypeSupported = false;
}
///<summary>
/// Called on each bar update event (incoming tick)
///</summary>
protectedoverridevoid OnBarUpdate()
{
value = 0.0008;
if (CurrentBar < 1)
return;
if (EMA (9)[1] - EMA (25) [1] < value && EMA (9)[0] - EMA (25) [0] >= value){
BarColor = Color.White;
} elseif(EMA (25)[1] - EMA (9) [1] < value && EMA (25)[0] - EMA (9) [0] >= value) {
BarColor = Color.Red;
}
}
#region Properties
#endregion
}
}
It should check to see the separation between the two EMA lines, that is EMA 9 minus EMA 25 is greater than or equal to 8 pips for a long and EMA 25 - EMA 9 is greater than or equal to 8 pips for a short. If the previous bar the separation was less than 8 pips and on the current bar the separation is greater than or equal to 8 pips then color the bar.
The attached screenshot shows my problem. I have attached two files with screenshots. As you can see in the first one at the close of the 15:55 bar the 9 period ema is 1.2983 and the 25 period ema is 1.2975 which is equal to 8 pips. The separation on the bar before is less than 8 pips so this bar should be colored white. As you can see it is coloring the next bar white which closed at 16:00 which also has a separation of greater than 8 pips.
I can't figure out why the code is not coloring the 15:55 bar white since the separation is 8 pips?
Thanks for your help.
Will
Comment