Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Draw.Line does not work as expected

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

    Draw.Line does not work as expected

    Here's my simple calculation:
    Lookback is set as input parameter. int 30

    double avg = SMA(Close, Lookback)[0];
    Draw.Line(this, "SM1", false, Lookback, avg, 0, avg, Brushes.LimeGreen, DashStyleHelper.Dot, 2);

    If I set Lookback to 10, I can see the line but if i set it to 30 there's no lines...

    What I'm trying to do is horizontally draw the final value of SMA last 30 bars.




    #2
    I see that if i set Lookback to 13, nothing drawn. It works until 12

    Comment


      #3
      Hello Atilla,

      May I confirm that you are not attempting to draw more bars back than exist?

      Is CurrentBar greater than the Lookback variable?

      Are any errors appearing in the Log tab of the Control Center?
      If so, what do these say?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Actually when i check CurrentBar this fixed the problem. I didn't know that.

        Here what I'm trying to do is to draw a horizontal line for each given time. For example every 30 bars, i would like to draw first bars open price as horizontal line. But I couldn't do it. I'm using Draw.Line. Last bar is 0 but i don't know what is first bar. Also when i draw an open price with tag, new tag overrides it i think.

        Comment


          #5
          Hello Atilla,

          To draw a horizontal line at the open of a bar on the first bar of a session.

          if (Bars.IsFirstBarOfSession)
          Draw.HorizontalLine(this, "openHLine" + CurrentBar, Open[0], Brushes.LimeGreen);

          You can use a counter to draw something every 30 bars.


          Any barsAgo index used must be less than the number of bars available (CurrentBar).

          if (CurrentBar > 10)
          Draw.Line(this, "myLine" + CurrentBar, 10, Open[0], 0, Open[0], Brushes.LimeGreen);


          Also, a note from the help guide:
          "2.Set unique tag values for each draw object, unless you intend for new draw objects to replace existing objects with the same tag. A common trick is to incorporate the bar number as part of the unique tag identifier. For example, if you wanted to draw a dot that indicated a buying condition above a bar, you could express it:
          Draw.Dot(this, CurrentBar.ToString() + "Buy", false, 0, High[0] + TickSize, Brushes.ForestGreen);"
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hello Atilla,

            To draw a horizontal line at the open of a bar on the first bar of a session.

            if (Bars.IsFirstBarOfSession)
            Draw.HorizontalLine(this, "openHLine" + CurrentBar, Open[0], Brushes.LimeGreen);

            You can use a counter to draw something every 30 bars.


            Any barsAgo index used must be less than the number of bars available (CurrentBar).

            if (CurrentBar > 10)
            Draw.Line(this, "myLine" + CurrentBar, 10, Open[0], 0, Open[0], Brushes.LimeGreen);


            Also, a note from the help guide:
            "2.Set unique tag values for each draw object, unless you intend for new draw objects to replace existing objects with the same tag. A common trick is to incorporate the bar number as part of the unique tag identifier. For example, if you wanted to draw a dot that indicated a buying condition above a bar, you could express it:
            Draw.Dot(this, CurrentBar.ToString() + "Buy", false, 0, High[0] + TickSize, Brushes.ForestGreen);"
            https://ninjatrader.com/support/help...us/drawing.htm
            I will have a look thank you. But there's a problem. Even I set Calculate = Calculate.OnBarClose; "(State == SetDefaults) area", I think NT calculates every tick. It's being slow. I am not actually calculating each update.

            Comment


              #7
              Hello Atilla,

              Defaults are only pulled from State.SetDefaults when a new instance of the script is added. Are you adding a new instance of the script?

              What is Calculate set to in the script parameters?

              Are you adding prints to the script and seeing a print for each tick?

              Is there a 1 tick series added to the script?
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

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