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

CurrentBar processing wrong?

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

    CurrentBar processing wrong?

    Hi,

    The attached code doesnt seem to be processing CurrentBar as I would expect. It is supposed to process each bar in a chart from left to right to detect price gaps.

    When I apply this indicator to a chart (daily chart from Yahoo data) it appears (from looking at the output window) that 'CurrentBar' isnt updating after each loop. The indicator gets stuck on the first pair of bars. What am I doing wrong? I have added "prints" so I can see what the code is doing.

    Thanks!
    Last edited by BillyRayValentine; 09-09-2010, 05:15 AM.

    #2
    Hello,

    Thank you for your first forum post!

    Most likely you need to make sure you have enough bars before you start to calculate.

    Please do the following to make sure that you have at lease 10 bars for example before you start calculating.



    Let me know if I can be of further assistance.

    Comment


      #3
      Hi Brett,

      Thanks for the reply.
      I believe I am checking for case of first bar of data (indicator requires at least two bars to determine a gap).
      Also, I tried this on a chart of 365 days data. No matter how many days of data are in my chart, the code processes the first two bars in the wrong order then uses the same data for each iteration of the loop for all remaining days. It it looping for the correct number of days I think, its just that the local variables are not being updated with the data from the current bar - it keeps using the price data from the first bar.

      Comment


        #4
        BillyRayValentine,

        In your code you cannot access [] index values until those bars actually exist. Each bar is processed starting from the left to right. When you are on the very very first bar of the chart no such index of [1] exists and you cannot access it. This is what you need to be mindful of in your code through the tip Brett linked. Please add checks in your code to ensure you have enough bars prior to trying to access the index values.

        If you are trying to access the prior bar that means you need at least 2 bars on your chart before your code should ever do anything. That means
        Code:
        if (CurrentBar < 1)
             return;
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Ok, got it working now.

          I was checking for 'CurrentBar == 0' but as you pointed out I was assigning my variables before this check.
          Also, I found that I had to replace the CurrentBar dataseries with 0 and 1 for current period and previous period.

          Thanks for the responses guys!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by funk10101, Today, 08:14 AM
          3 responses
          4 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by frankthearm, Today, 09:08 AM
          0 responses
          1 view
          0 likes
          Last Post frankthearm  
          Started by samish18, Yesterday, 08:57 AM
          11 responses
          28 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by yertle, Today, 08:38 AM
          1 response
          6 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by love2code2trade, Yesterday, 01:45 PM
          3 responses
          22 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X