Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 elirion, Today, 01:36 AM
              0 responses
              3 views
              0 likes
              Last Post elirion
              by elirion
               
              Started by gentlebenthebear, Today, 01:30 AM
              0 responses
              2 views
              0 likes
              Last Post gentlebenthebear  
              Started by samish18, Yesterday, 08:31 AM
              2 responses
              9 views
              0 likes
              Last Post elirion
              by elirion
               
              Started by Mestor, 03-10-2023, 01:50 AM
              16 responses
              389 views
              0 likes
              Last Post z.franck  
              Started by rtwave, 04-12-2024, 09:30 AM
              4 responses
              31 views
              0 likes
              Last Post rtwave
              by rtwave
               
              Working...
              X