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

Comparing previous bar

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

    Comparing previous bar

    Hi,
    I am trying to develop my first indicator and got stuck with simple task -> when the high of the current bar is higher then previous draw an arrow:
    Code:
    protected override void OnBarUpdate() {
          if (High[1]<High[0]) {
    		DrawArrowUp("UpArrow" + CurrentBar, false, 0, Low[0] - 1, Color.DarkGreen);
          }
    }
    But this code does not draw any arrow. On the other hand when I try to compare with the "future" bar it works correctly...
    Code:
    protected override void OnBarUpdate() {
          if (High[0]<High[-1]) {
    		DrawArrowUp("UpArrow" + CurrentBar, false, 0, Low[0] - 1, Color.DarkGreen);
          }
    }
    What am I doing wrong? Thanks

    #2
    antonek,

    I am happy to assist you.

    It is not recommended to plot these by checking future values.

    What about this setup isn't plotting these correctly? Are they plotting 1 bar too early or something similar?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for reply.

      Of course I don't want to check future values - I tried that code just to verify that the syntax is correct...

      So my idea is to check high of current bar with high one bar ago, shouldn't High[1]<High[0] do that? But my indicator doesn't draw any arrow. Enclosed see my indicator.
      Attached Files

      Comment


        #4
        antonek,

        You may want to try :

        if (High[1]<High[0])
        {
        DrawArrowUp("UpArrow" + CurrentBar, false, 0, Low[0] - 1*TickSize, Color.DarkGreen);
        }
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Unfortunately it didnt help... as you can see in enclosed images no arrow is drawn.
          Attached Files

          Comment


            #6
            antonek,

            One thing I just noticed is that you aren't checking to make sure 2 bars are in the high series. There may be a log message about index out of bounds.

            Please add the following to the beginning of your OnBarUpdate() method.

            if ( CurrentBar < 2) return;
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              That is a bit hard nut to crack for me... I don't not understand why do I need to check "2 bars are in the high series" (not to mention the syntax of it). Is there any reference in help? Thanks

              Comment


                #8
                antonek,

                CurrentBar counts the number of OnBarUpdate() calls. When a strategy or indicator is attached to your chart, it begins at the first bar on your chart in the past. At this time, all the dataseries such as High, Low, etc. only have 1 element in them. If you try to look 1 bar into the past it won't exist until the next OnBarUpdate() call. Likely you are getting a run-time error of "Index out of bounds" and it's cancelling your strategy/indicator.





                Adam P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by frslvr, 04-11-2024, 07:26 AM
                9 responses
                123 views
                1 like
                Last Post caryc123  
                Started by rocketman7, Today, 09:41 AM
                4 responses
                15 views
                0 likes
                Last Post rocketman7  
                Started by selu72, Today, 02:01 PM
                1 response
                9 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Started by WHICKED, Today, 02:02 PM
                2 responses
                16 views
                0 likes
                Last Post WHICKED
                by WHICKED
                 
                Started by f.saeidi, Today, 12:14 PM
                8 responses
                21 views
                0 likes
                Last Post f.saeidi  
                Working...
                X