protected override void OnStateChange() {
if (State == State.SetDefaults) {
AddPlot(new Stroke(Brushes.Black, 1), PlotStyle.Dot, "5 Minute");
AddPlot(new Stroke(Brushes.Black, 1), PlotStyle.Dot, "10 Minute");
AddPlot(new Stroke(Brushes.Black, 1), PlotStyle.Dot, "15 Minute");
AddPlot(new Stroke(Brushes.Black, 1), PlotStyle.Dot, "20 Minute");
}
else if (State == State.Configure) {
AddDataSeries(Data.BarsPeriodType.Minute, 10);
AddDataSeries(Data.BarsPeriodType.Minute, 15);
AddDataSeries(Data.BarsPeriodType.Minute, 20);
}
}
protected override void OnBarUpdate() {
if (CurrentBars[0] <= BarsRequiredToPlot ||
CurrentBars[1] <= BarsRequiredToPlot ||
CurrentBars[2] <= BarsRequiredToPlot ||
CurrentBars[3] <= BarsRequiredToPlot)
return;
// Fixed points for display
Bars5Plot[0] = 0;
Bars10Plot[0] = 5;
Bars15Plot[0] = 10;
Bars20Plot[0] = 15;
var o = Opens[0][0];
var c = Closes[0][0];
var i = CurrentBars[0]; // bar index
if (BarsInProgress == 0) {
SetCurrentBrushColor(i, o, c, Bars5PlotBrush);
My.Draw.Text(this, GetUniqueTag($"5BarText"), $"5 min i: {i} o: {o} c: {c}", Bars5Plot[0] + VerticalOffset, SmallFont);
}
if (BarsInProgress == 1) {
o = Opens[1][0];
c = Closes[1][0];
i = CurrentBars[1];
SetCurrentBrushColor(i, o, c, Bars10PlotBrush);
My.Draw.Text(this, GetUniqueTag($"10BarText"), $"10 min i: {i} o: {o} c: {c}", Bars10Plot[0] + VerticalOffset, SmallFont);
}
if (BarsInProgress == 2) {
o = Opens[2][0];
c = Closes[2][0];
i = CurrentBars[2];
SetCurrentBrushColor(i, o, c, Bars15PlotBrush);
My.Draw.Text(this, GetUniqueTag($"15BarText"), $"15 min i: {i} o: {o} c: {c}", Bars15Plot[0] + VerticalOffset, SmallFont);
}
if (BarsInProgress == 3) {
o = Opens[3][0];
c = Closes[3][0];
i = CurrentBars[3];
SetCurrentBrushColor(i, o, c, Bars20PlotBrush);
My.Draw.Text(this, GetUniqueTag($"b20Text"), $"20 min i: {i} o: {o} c: {c}", Bars20Plot[0] + VerticalOffset, SmallFont);
}
}
private void SetCurrentBrushColor(int index, double open, double close, BrushSeries plotBrush) {
Print($"i: {index} o: {open}, c: {close}, c LT o: {close.LT(open)}, c GT o: {close.GT(open)}");
if (close.LT(open))
plotBrush[0] = Brushes.Red;
else if (close.GT(open))
plotBrush[0] = Brushes.LimeGreen;
else
plotBrush[0] = Brushes.Black;
}
Comment