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 Hwop38, 05-04-2026, 07:02 PM
            0 responses
            166 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Started by CaptainJack, 04-24-2026, 11:07 PM
            0 responses
            320 views
            0 likes
            Last Post CaptainJack  
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            246 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by M4ndoo, 04-20-2026, 05:21 PM
            0 responses
            350 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Started by M4ndoo, 04-19-2026, 05:54 PM
            0 responses
            179 views
            0 likes
            Last Post M4ndoo
            by M4ndoo
             
            Working...
            X