I'm programming a custom MACD with the Avg plotted as a colored line and the MACD plotted as colored histogram.
I use identical code for the color-coding of each plot, but the histogram seems to be one bar out. Take a look at the attached screenshot which compares my indicator with another successfully coded one, my Falling lines colors for the histogram seems to change a bar too late. The Rising() line seems to be OK though.
Here's my code:
{
Macdline.Set(MACD(Fast, Slow, Smooth).Value[0]);
if (CurrentBar < 1)
return;
if (Rising(MACD(Fast, Slow, Smooth).Avg))
{
RisingPlot.Set(1, MACD(Fast, Slow, Smooth).Avg[1]); RisingPlot.Set(MACD(Fast, Slow, Smooth).Avg[0]);
}
else if (Falling(MACD(Fast, Slow, Smooth).Avg))
{
FallingPlot.Set(1, MACD(Fast, Slow, Smooth).Avg[1]);
FallingPlot.Set(MACD(Fast, Slow, Smooth).Avg[0]);
}
// Plot yellow if the %D is neutral
else
{
NeutralPlot.Set(1, MACD(Fast, Slow, Smooth).Avg[1]);
NeutralPlot.Set(MACD(Fast, Slow, Smooth).Avg[0]);
}
if (Rising(MACD(Fast, Slow, Smooth).Value))
{
RisingMacd.Set(1, MACD(Fast, Slow, Smooth).Value[1]);
RisingMacd.Set(MACD(Fast, Slow, Smooth).Value[0]);
}
else if (Falling(MACD(Fast, Slow, Smooth).Value))
{
FallingMacd.Set(1, MACD(Fast, Slow, Smooth).Value[1]);
FallingMacd.Set(MACD(Fast, Slow, Smooth).Value[0]);
}
else
{
NeutralMacd.Set(1, MACD(Fast, Slow, Smooth).Value[1]);
NeutralMacd.Set(MACD(Fast, Slow, Smooth).Value[0]);
}
}
Thanks for your help,
Jeremy
Comment