Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error: Pen not used in DrawLine()

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

    Error: Pen not used in DrawLine()

    Hi,

    in my strategy I want to draw a line that marks the entry price. To do that I created a green Pen that has a wider dash pattern than what is available by default.

    Unfortunately sometimes the line would not look as defined by the pen, but instead still have the original properties as used in the DrawLine() statement. So far I only noticed that error on charts that were created in realtime.

    Code to draw the line and then assign the Pen:
    Code:
    EntryLineID = "ELP" + BarsInProgress.ToString() + "-" + CurrentBars[0].ToString();
    EntryLineO = DrawLine(EntryLineID, true, Time[0], MyEntryPrice_G, Time[0].AddMinutes(1), MyEntryPrice_G, Color.Black, DashStyle.Solid, 1);
    EntryLineO.Pen = EntryPenP;
    Sometimes that works in realtime (line is green and dashed) and sometimes it doesn't (line is black & solid). Could it be that the change to the Pen happens too quickly and gets ignored? Any other possible reason?

    Thanks,
    NutFlush

    #2
    Hi NutFlush, presently not aware of anything else that could contribute here - so with realtime you mean running the script live and with CalculateOnBarClose = false?

    Comment


      #3
      Originally posted by NinjaTrader_Bertrand View Post
      Hi NutFlush, presently not aware of anything else that could contribute here - so with realtime you mean running the script live and with CalculateOnBarClose = false?
      Yes, that's what I meant.

      BTW, in TradeStation all changes to graphic elements get lost when done on any other tick than the closing tick of a bar. I hope since NT's logic is different that it shouldn't matter when a change is done, right?

      Thanks,
      NutFlush

      Comment


        #4
        NutFlush not exactly aware how TradeStation would work here in comparison - I would however expect the change to the Pen object used to be persisted if it would not be overwritten then be another call in your script. Would you mind sending us a test snippet to support at ninjatrader dot com we could run?

        Comment


          #5
          Originally posted by NinjaTrader_Bertrand View Post
          NutFlush not exactly aware how TradeStation would work here in comparison - I would however expect the change to the Pen object used to be persisted if it would not be overwritten then be another call in your script. Would you mind sending us a test snippet to support at ninjatrader dot com we could run?
          Hi Bertrand,

          thanks for your help.

          I was expecting the same thing: that the changes are persistent. As I said they sometimes are and at other times not. There are no other parts in the code that could overwrite the pen so I guess that for some reason there appears to be a "hickup" so that setting the pen is "forgotten".

          There isn't much more code than what I posted above other than this:
          Code:
          #region Variables
          private string EntryLineID;
          private ILine EntryLineO;
          private Pen EntryPenP = new Pen(Color.SpringGreen);
          #endregion
          
          protected override void Initialize()
                  {
                      CalculateOnBarClose = false;
          
                      // pen for drawing dashed lines
                      EntryPenP.DashPattern = new float[]{3.0F, 3.0F};
                  }
          Just wanted to make sure that the way I assigned the pen wasn't wrong in any way or that I missed any speciality of how to draw.

          Thanks,
          NutFlush

          Comment


            #6
            NutFlush, would this work better in your OnBarUpdate()?

            Code:
            EntryLineID = "ELP" + BarsInProgress.ToString() + "-" + CurrentBars[0].ToString();
            EntryLineO = DrawLine(EntryLineID, true, Time[0], MyEntryPrice_G, Time[0].AddMinutes(1), MyEntryPrice_G, Color.Black, DashStyle.Solid, 1);
            EntryLineO.Pen.Color = Color.SpringGreen;
            EntryLineO.Pen.DashPattern = new float[]{3.0F, 3.0F};

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              NutFlush, would this work better in your OnBarUpdate()?

              Code:
              EntryLineID = "ELP" + BarsInProgress.ToString() + "-" + CurrentBars[0].ToString();
              EntryLineO = DrawLine(EntryLineID, true, Time[0], MyEntryPrice_G, Time[0].AddMinutes(1), MyEntryPrice_G, Color.Black, DashStyle.Solid, 1);
              EntryLineO.Pen.Color = Color.SpringGreen;
              EntryLineO.Pen.DashPattern = new float[]{3.0F, 3.0F};
              Hi Bertrand,

              I can give it a try, but doesn't that defeat the purpose of having a Pen?

              I also want to draw several target lines that should look alike, so I want to be able to change all of their appearances by just changing the Pen definition. Following your suggestion would mean that I would need to find and change stuff all over the whole code...

              Cheers,
              NutFlush

              Comment


                #8
                Originally posted by NutFlush View Post
                Hi Bertrand,

                I can give it a try, but doesn't that defeat the purpose of having a Pen?

                I also want to draw several target lines that should look alike, so I want to be able to change all of their appearances by just changing the Pen definition. Following your suggestion would mean that I would need to find and change stuff all over the whole code...

                Cheers,
                NutFlush
                In that case, you may be better off writing a method that you call to draw and set the properties of the line. You call the method whenever you want to draw or modify such a line, and pass in the parameters when you call the method.

                Comment

                Latest Posts

                Collapse

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