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

Problems with Math.Sign

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

    Problems with Math.Sign

    Hi guys

    I'm working on an indicator and I'm experiencing the following problem:

    The code that works (i.e. it appears on the chart) is:

    Code:
    A = Math.Sign(Close[[B]0[/B]] - Open[[B]0[/B]])
    but when I replace the [0]'s by [1]'s to get:

    Code:
    A = Math.Sign(Close[[B]1[/B]] - Open[[B]1[/B]])
    then nothing appears on the chart!

    I can't see why Math.Sign should fail to work just because the previous bar is being tested.

    Any advice on how to solve this problem will be much appreciated.

    #2
    Hello arbuthnot,

    Thank you for your post.

    Please go to the Log tab of the NinjaTrader Control Center after adding your indicator to your chart and advise if there are any errors listed in Yellow.

    If so, please detail these errors in your response.

    I look forward to your response.

    Comment


      #3
      Originally posted by arbuthnot View Post
      Hi guys

      I'm working on an indicator and I'm experiencing the following problem:

      The code that works (i.e. it appears on the chart) is:

      Code:
      A = Math.Sign(Close[[B]0[/B]] - Open[[B]0[/B]])
      but when I replace the [0]'s by [1]'s to get:

      Code:
      A = Math.Sign(Close[[B]1[/B]] - Open[[B]1[/B]])
      then nothing appears on the chart!

      I can't see why Math.Sign should fail to work just because the previous bar is being tested.

      Any advice on how to solve this problem will be much appreciated.
      ref: this post: http://www.ninjatrader.com/support/f...d.php?p=291077 in this thread: http://www.ninjatrader.com/support/f...d.php?p=291066

      Comment


        #4
        Thanks very much, Patrick.

        There are lots of errors in Yellow. They all read:

        Error on calling OBU method for indicator … on bar 0: You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on chart.
        My chart has hundreds of bars!

        Looking forward to your further advice.

        Comment


          #5
          Hello arbuthnot,

          Thank you for your response.

          You will need to make sure there are enough bars on your chart before calculating the values.

          On the first bar of a chart you would only have one bar and that bar would be considered Close[0], so Close[1] does not exist at that point.

          Try using the following or similiar at the beginning of the OnBarUpdate() method:

          Code:
          protected override void OnBarUpdate()
          {
          if (CurrentBar < 1) return;
          For information on making sure you have enough bars on your chart please visit the following link: http://www.ninjatrader.com/support/f...ead.php?t=3170

          Please let me know if I may be of further assistance.

          Comment


            #6
            Thanks so much, Patrick. To say that I knew this and have kept it in my head every day but today is no excuse.

            It's as if you've spent days preparing and packing for a vacation. You get in the car to set off and find that you've mislaid the car keys...

            Putting
            Code:
            if (CurrentBar < 1) return;
            is the 'car keys' of coding any indicator!

            Much obliged.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Tim-c, Today, 02:10 PM
            0 responses
            1 view
            0 likes
            Last Post Tim-c
            by Tim-c
             
            Started by cre8able, Today, 01:16 PM
            2 responses
            9 views
            0 likes
            Last Post cre8able  
            Started by chbruno, 04-24-2024, 04:10 PM
            3 responses
            48 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by samish18, Today, 01:01 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_LuisH  
            Started by WHICKED, Today, 12:56 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X