Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to drawline untill the position is open

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

    How to drawline untill the position is open

    Hi

    i want to draw a line showing my stop level... i wrote that script:

    DrawLine(CurrentBar.ToString(),false, 1, stop, 0, stop, Color.Red, DashStyle.Solid,2);

    but i don't know how to say "untill the position is open" to replace the "0"

    If you can help ?

    #2
    Hi Thomas79,

    You could use, for example, a condition that checks you are not flat before drawing the line. Can also attach a removal statement so that it's removed when you are flat. In the example below, I also changed your tag field so that it's just a single value.

    if (Position.MarketPosition != MarketPosition.Flat)
    DrawLine("StopLine", false, 1, stop, 0, stop, Color.Red, DashStyle.Solid,2);

    else
    RemoveDrawObject("StopLine");
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi

      that change nothing... i think this is the "0" on the 5th position...

      the line is drawn 1 bar on the past but not draw on the next bar... it stop at 0

      Comment


        #4
        Sorry, I'm not sure what you're looking for. Can you please clarify what it is you are looking to do or offer more input on your expectations with the code snippet you posted?
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          can you check the picture... i explain.
          Attached Files

          Comment


            #6
            I see, thanks for posting that picture. You'll probably want to make use of BarsSinceEntry().

            Below snippet will work, but is inefficient because it's drawing a new line each bar you're in a position. Ideally you would want to custom code something that provides a "unique per position" tag.

            Code:
            if (Position.MarketPosition != MarketPosition.Flat)
            	DrawLine("StopLine" + CurrentBar, false, BarsSinceEntry(), Position.AvgPrice - TickSize * 10, 0, Position.AvgPrice - TickSize * 10, Color.Red, DashStyle.Solid,2);
            Ryan M.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

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