Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

draw line using stroke property

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    draw line using stroke property

    Hi, I am trying to draw a line using Draw.Line and stroke property. I found the contractor:
    Draw.Line(NinjaScriptBase owner, string tag, bool isAutoScale, DateTime startTime, double startY, DateTime endTime, double endY, Brush brush, DashStyleHelper dashStyle, int width, bool drawOnPricePanel)

    Iam getting compilation error of:
    The best overloaded method match for 'NinjaTrader.NinjaScript.DrawingTools.Draw.Line(Ni njaTrader.NinjaScript.NinjaScriptBase, string, bool, int, double, int, double, System.Windows.Media.Brush, NinjaTrader.Gui.DashStyleHelper, int, bool)' has some invalid arguments
    Code:
    protected void DrawTrend(TrendDrawType drawObj, string objName, int dir, int bar1, double price1, int bar2, double price2, double distance,
    
    Brush upBrush, Brush downBrush, Stroke upStroke, Stroke downStroke, int opacity)
    
    {
    
    switch (drawObj)
    
    {
    
    case TrendDrawType.TrendLine:
    
    Draw.Line(this,objName,false,CurrentBar-bar1,price1,CurrentBar-bar2,price2,(dir<0?downStroke.Brush:upStroke.Brush ),
    
    (dir<0?downStroke.DashStyleHelper:upStroke.DashSty leHelper),(dir<0?downStroke.Width:upStroke.Width), true);
    
    break;
    
    case TrendDrawType.TouchZone: case TrendDrawType.TerminateZone: case TrendDrawType.TrendSignalZone: case TrendDrawType.BreakSignalZone:
    
    List<ChartAnchor> anchors = new List<ChartAnchor>();
    
    anchors.Add(new ChartAnchor(Time[CurrentBar-bar1], price1-distance, ChartControl));
    
    anchors.Add(new ChartAnchor(Time[CurrentBar-bar1], price1+distance, ChartControl));
    
    anchors.Add(new ChartAnchor(Time[CurrentBar-bar2], price2+distance, ChartControl));
    
    anchors.Add(new ChartAnchor(Time[CurrentBar-bar2], price2-distance, ChartControl));
    
    Draw.Polygon(this, objName, false, anchors, Brushes.Transparent, DashStyleHelper.Solid, (dir<0?upBrush:downBrush), opacity);
    
    
    break;
    
    }
    
    }
    Last edited by Shai Samuel; 05-26-2022, 10:17 AM.

    #2
    Hello Shai Samuel,

    Thank you for your reply.

    You're definitely on the right track. I'm seeing the following example compile successfully:

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 10) return;

    Stroke myStroke = new Stroke(Brushes.Green,DashStyleHelper.Solid, 4);
    Draw.Line(this, "myLine", false, Time[10], Close[10], Time[0], Close[0], myStroke.Brush, myStroke.DashStyleHelper, (int)myStroke.Width, true);
    }

    This code will draw a green line between the closes of the current bar and the bar 10 bars ago. Do you see the same?

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Thank you Kate. I was missing the int casting for the width

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      648 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      369 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      108 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      572 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      574 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X