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

How to refer to a specefic bar

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

    How to refer to a specefic bar

    I am trying to DrawText on a specific bar but how do I refer to that bar, I have tried many things but with no success

    Code:
    DrawText("7",true,"T", 2    ,High[2],0,Color.Blue,new Font("Arial", 8),StringAlignment.Center,Color.Black,Color.Yellow,10 );
    0 and 1 in the barsAgo parameter are drawing but 2 and above (3,4,....)aren't drawing, please tell me what am I missing

    #2
    Hello,

    This line of code is correct however you will need to add an additional check to ensure enough bars have been loaded before hand. If you go to tools -> output window you would see an error message

    This can be avoided with a current bar check at the start of your OnBarUpdate()

    example
    if(CurrentBar < 2)
    return;



    Let me know if I can further assist.
    LanceNinjaTrader Customer Service

    Comment


      #3
      Thank you for the very fast reply,

      when I enter the if statement it worked fine for 2 bars ago, and then I modified it to

      Code:
      if  (CurrentBar < 200) return;
      now I can refer from 0 to 200 bars ago, what is the secret of the CurrentBar < number since the chart already having 247 bars as per the Count value

      Comment


        #4
        You are correct in noticing Count will be the total number of bars on the chart.

        However when an indicator is run it starts processing on bar 0 and will evaluate from left to right. The error is then being generated because it's trying to place a drawing object where there is no data at the very start

        CurrentBar allows you to see the current bar that's being processed where as Count give total bars on the chart

        Let me know if I can further assist.
        LanceNinjaTrader Customer Service

        Comment


          #5
          Thank you I got it. ,

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by helpwanted, Today, 03:06 AM
          1 response
          16 views
          0 likes
          Last Post sarafuenonly123  
          Started by Brevo, Today, 01:45 AM
          0 responses
          11 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          6 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          244 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          387 views
          1 like
          Last Post Gavini
          by Gavini
           
          Working...
          X