I am trying to get my script to draw lines on the chart panel but, while it prints the right start and end bars in the drawing objects window, the lines are drawn towards the beginning of the chart.
For instance, a bar with a start bar index of 930 is drawn at bar 13, but not only that: the end time is before the start time, so the bars are sloped the opposite way to what they should be, as in the second screenshot.
C, S, E are the CurrentBar, StartBar, EndBar
Please see my code below
public class Divergence5min : Strategy { private DashStyleHelper divDashStyle = DashStyleHelper.Solid; private Brush divColour = Brushes.Magenta; private Brush hiddenDivColour = Brushes.DodgerBlue; ... protected override void OnBarUpdate() { ........... NegativeDivergence(); ........... } private void NegativeDivergence() { if (HSwDMI.Count != lastListCountH) { if (!hidNegDiv && ((LastHSwDMI[j - 1] - LastHSwDMI[j - 2] > 0.01 && LastHSwDMIprice[j - 2] > LastHSwDMIprice[j - 1] && LastHSwDMIprice[j - 2] - LastHSwDMIprice[j - 1] <= (int)HidDivOffset * TickSize) || (HSwDMI[b - 1] - LastHSwDMI[j - 1] > 0.01 && LastHSwDMIprice[j - 1] > HSwDMIprice[b - 1] && LastHSwDMIprice[j - 1] - HSwDMIprice[b - 1] <= (int)HidDivOffset * TickSize))) { if((HSwDMI[b - 1] - LastHSwDMI[j - 1] > 0.01 && LastHSwDMIprice[j - 1] > HSwDMIprice[b - 1] && LastHSwDMIprice[j - 1] - HSwDMIprice[b - 1] <= (int)HidDivOffset * TickSize)) Draw.Line(this, "hidNegDiv1" + " / C " + CurrentBar.ToString() + " / S " + LastHSwDMIpriceBar[j - 1].ToString() + " / E " + PriceHighBar[b - 1], false, LastHSwDMIpriceBar[j - 1], LastHSwDMIprice[j - 1] + TickSize, PriceHighBar[b - 1], HSwDMIprice[b - 1] + TickSize, hiddenDivColour, divDashStyle, 2, true); ........... } } }
Comment