Here is the code:
midBand = SMA(Close, Period)[0];
double offset = OffsetMultiplier * ATR(Period)[0];
upperBand = midBand + offset;
lowerBand = midBand - offset;
double openPrice = Open[0];
double closePrice = Close[0];
if(closePrice > openPrice) {
trendDirection = 1;
} else if(closePrice < openPrice) {
trendDirection = -1;
} else {
trendDirection = 0;
}
// Update the plots for the bands
Values[0][0] = upperBand;
Values[1][0] = lowerBand;
Plots[0].Width = 3;
Plots[1].Width = 3;
Plots[2].Width = 6;
// Plot the mid band on the chart
if (trendDirection == 1)
{
PlotBrushes[2][0] = Brushes.Green; // MidlineUp
upBackgroundColor = new SolidColorBrush(Color.FromArgb(50, 0, 255, 0));
upBackgroundColor.Freeze();
BackBrush = upBackgroundColor;
Draw.TextFixed(this, "TrendInfo",
trendDirection == 1 ? "Bullish" : "Bearish",
TextPos,
Brushes.White,
new Gui.Tools.SimpleFont("Arial", 12) { Bold = true },
Brushes.Transparent,
Brushes.Transparent, 0);
}
else if (trendDirection == -1)
{
PlotBrushes[2][0] = Brushes.Magenta; // MidlineDown
downBackgroundColor = new SolidColorBrush(Color.FromArgb(50, 255, 0, 0));
downBackgroundColor.Freeze();
BackBrush = downBackgroundColor;
Draw.TextFixed(this, "TrendInfo",
trendDirection == 1 ? "Bullish" : "Bearish",
TextPos,
Brushes.White,
new Gui.Tools.SimpleFont("Arial", 12) { Bold = true },
Brushes.Transparent,
Brushes.Transparent, 0);
}
else
{
//BackBrush = Brushes.Transparent;
PlotBrushes[2][0] = Brushes.Transparent;
}
Values[2][0] = midBand;

Comment