Created a Delta indicator, which should display delta bars in a new panel, everything works, bars are there, but there are no values where the candle's delta was high and low.
Help me figure it out, thanks
code
private Brush barColorDown = Brushes.Red;
private Brush barColorUp = Brushes.Lime;
private Brush shadowColor = Brushes.Gray;
private Pen shadowPen = null;
private int shadowWidth = 1;
AddPlot(Brushes.Gray, "HAOpen");
AddPlot(Brushes.Gray, "HAHigh");
AddPlot(Brushes.Gray, "HALow");
AddPlot(Brushes.Gray, "HAClose");
private void MyDelta //
{
double Vol = buys + sells;
double Delta = buys - sells;
if (CurrentBar == 0)
{
HAOpen[0] = Open[0];
HAHigh[0] = High[0];
HALow[0] = Low[0];
HAClose[0] = Close[0];
return;
}
HAClose[0] = Delta;// Calculate the close
HAOpen[0] = 0; // Calculate the open
HAHigh[0] = (Math.Max(Delta, HAOpen[0])); // Calculate the high
HALow[0] = (Math.Min(Delta, HAOpen[0])); // Calculate the low
}
public override void OnCalculateMinMax()
{
base.OnCalculateMinMax();
if (Bars == null || ChartControl == null)
return;
for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++)
{
double tmpHigh = HAHigh.GetValueAt(idx);
double tmpLow = HALow.GetValueAt(idx);
if (tmpHigh != 0 && tmpHigh > MaxValue)
MaxValue = tmpHigh;
if (tmpLow != 0 && tmpLow < MinValue)
MinValue = tmpLow;
}
}
protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
{
if (Bars == null || ChartControl == null)
return;
int barPaintWidth = Math.Max(3, 1 + 2 * ((int)ChartControl.BarWidth - 1) + 2 * shadowWidth);
for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++)
{
if (idx - Displacement < 0 || idx - Displacement >= BarsArray[0].Count || (idx - Displacement < BarsRequiredToPlot))
continue;
double valH = HAHigh.GetValueAt(idx);
double valL = HALow.GetValueAt(idx);
double valC = HAClose.GetValueAt(idx);
double valO = HAOpen.GetValueAt(idx);
int x = chartControl.GetXByBarIndex(ChartBars, idx); //was chartControl.BarsArray[0]
int y1 = chartScale.GetYByValue(valO);
int y2 = chartScale.GetYByValue(valH);
int y3 = chartScale.GetYByValue(valL);
int y4 = chartScale.GetYByValue(valC);
SharpDX.Direct2D1.Brush shadowColordx = shadowColor.ToDxBrush(RenderTarget); // prepare for the color to use
var xy2 = new Vector2(x, y2);
var xy3 = new Vector2(x, y3);
RenderTarget.DrawLine(xy2, xy3, shadowColordx, shadowWidth);
if (y4 == y1)
RenderTarget.DrawLine(new Vector2(x - barPaintWidth / 2, y1), new Vector2(x + barPaintWidth / 2, y1), shadowColordx, shadowWidth);
else
{
if (y4 > y1)
{
SharpDX.Direct2D1.Brush barColorDowndx = barColorDown.ToDxBrush(RenderTarget); // prepare for the color to use
RenderTarget.FillRectangle(new RectangleF(x - barPaintWidth / 2, y1, barPaintWidth, y4 - y1), barColorDowndx);
barColorDowndx.Dispose();
}
else
{
SharpDX.Direct2D1.Brush barColorUpdx = barColorUp.ToDxBrush(RenderTarget); // prepare for the color to use
RenderTarget.FillRectangle(new RectangleF(x - barPaintWidth / 2, y4, barPaintWidth, y1 - y4), barColorUpdx);
barColorUpdx.Dispose();
}
RenderTarget.DrawRectangle(new RectangleF(x - barPaintWidth / 2 + (float)shadowWidth / 2,
Math.Min(y4, y1), barPaintWidth - (float)shadowWidth, Math.Abs(y4 - y1)), shadowColordx, shadowWidth);
}
shadowColordx.Dispose();
}
}
need to get

Comment