Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw Horizontal Line

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

    Draw Horizontal Line

    Hi All,

    I am new to Ninjascript, I am trying to draw a horizontal line at last close price:

    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.

    // create custom Courier New, make it big and bold
    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 12) { Size = 20, Bold = false };

    double my_last_price =Close[0];

    Draw.Line(this, "myLastLine", false, 50, Close[0], 0, Close[0], Brushes.Black, DashStyleHelper.Solid, 1);
    }
    No line was drawn, if I replaced Draw.Line() with:
    Draw.HorizontalLine(this, "myTag" + 1, Close[0], Brushes.Black, DashStyleHelper.Solid, 1, true);
    then there will be an horizontal line cross the whole chart window, I was hoping I am able to control the starting/ending points of the line

    Not sure what I did wrong

    Thanks so much.
    Last edited by warpinator; 03-30-2024, 03:21 PM.

    #2
    Hello warpinator,

    Thanks for your notes.

    The Draw.HorizontalLine() method only take a single argument for the price you want to draw the horizontal line at. You cannot control the start point and end point of a horizontal line draw object.

    Draw.HorizontalLine(this, "myTag", false, Close[0], Brushes.Black, DashStyleHelper.Solid, 1);would draw a black horizontal line on the chart window at the last Close price.

    If you want to control the start point and end point of a line you would need to use the Draw.Line() method to draw a line drawing object on the chart window from a specific start point to a specific end point.

    Further, keep an eye on the Log tab of the Control Center for any errors that might appear when testing the script.

    See the help guide documentation below for more information.

    Draw.HorizontalLine(): https://ninjatrader.com/support/help...zontalline.htm
    Draw.Line(): https://ninjatrader.com/support/help.../draw_line.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    591 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    343 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    103 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    556 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    553 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X