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

New Basic Indicator converted from Strategy

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

    New Basic Indicator converted from Strategy

    Hi there,

    I have simple bits of code that I created a strategy with. It compiles & works as planned. I learned with templates that it would be better suited as an indicator like a moving average so I copied the code and made it an indicator.

    The indicator was working earlier this week during market hours but now for some reason isn't. However the other predefined indicators are (MA, etc.)

    There is no "Enable = True" with indicators so I can't figure out what could be the issue?
    Something in Data Series?

    IJ

    Attached is a screenshot of the indicator properties.
    Attached Files

    #2
    Originally posted by ij001 View Post
    Hi there,

    I have simple bits of code that I created a strategy with. It compiles & works as planned. I learned with templates that it would be better suited as an indicator like a moving average so I copied the code and made it an indicator.

    The indicator was working earlier this week during market hours but now for some reason isn't. However the other predefined indicators are (MA, etc.)

    There is no "Enable = True" with indicators so I can't figure out what could be the issue?
    Something in Data Series?

    IJ

    Attached is a screenshot of the indicator properties.
    The indicator's properties do not tell much. You may want to post any errors in the log instead.

    Comment


      #3
      ij001, as koganam has said, can you please post the error messages you're receiving in the logs (right-most tab of Control Center)? You could also post the code if you want.
      AustinNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Austin View Post
        ij001, as koganam has said, can you please post the error messages you're receiving in the logs (right-most tab of Control Center)? You could also post the code if you want.
        There was something in the log:

        Error on calling 'OnBarUpdate' method for indicator 'NR7' 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 the chart.

        The code is for a 'NR7':

        protected override void Initialize()
        {
        Overlay = true;
        CalculateOnBarClose = true;
        }

        protected override void OnBarUpdate()
        {

        if (

        Math.Abs(High[0]-Low[0]) <= Math.Abs(High[1]-Low[1]) &&
        Math.Abs(High[0]-Low[0]) <= Math.Abs(High[2]-Low[2]) &&

        Math.Abs(High[0]-Low[0]) <= Math.Abs(High[3]-Low[3]) &&

        Math.Abs(High[0]-Low[0]) <= Math.Abs(High[4]-Low[4]) &&

        Math.Abs(High[0]-Low[0]) <= Math.Abs(High[5]-Low[5]) &&

        Math.Abs(High[0]-Low[0]) <= Math.Abs(High[6]-Low[6]) &&

        Math.Abs(High[0]-Low[0]) <= Math.Abs(High[7]-Low[7])
        )
        BarColor = Color.Purple;

        }

        Comment


          #5
          Originally posted by ij001 View Post
          There was something in the log:

          Error on calling 'OnBarUpdate' method for indicator 'NR7' 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 the chart.

          The code is for a 'NR7':

          protected override void Initialize()
          {
          Overlay = true;
          CalculateOnBarClose = true;
          }

          protected override void OnBarUpdate()
          {

          if (

          Math.Abs(High[0]-Low[0]) <= Math.Abs(High[1]-Low[1]) &&
          Math.Abs(High[0]-Low[0]) <= Math.Abs(High[2]-Low[2]) &&

          Math.Abs(High[0]-Low[0]) <= Math.Abs(High[3]-Low[3]) &&

          Math.Abs(High[0]-Low[0]) <= Math.Abs(High[4]-Low[4]) &&

          Math.Abs(High[0]-Low[0]) <= Math.Abs(High[5]-Low[5]) &&

          Math.Abs(High[0]-Low[0]) <= Math.Abs(High[6]-Low[6]) &&

          Math.Abs(High[0]-Low[0]) <= Math.Abs(High[7]-Low[7])
          )
          BarColor = Color.Purple;

          }
          You are trying to process bars that do not yet exist. The simplest solution is to escape the initial bars thus:

          Code:
          protected override void OnBarUpdate()
          {
          [COLOR="Red"]if (CurrentBar < 7) return;[/COLOR]
          if ( ...

          Comment


            #6
            ij001, please try koganam's suggestion and let us know if it doesn't work.
            AustinNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by inanazsocial, Today, 01:15 AM
            0 responses
            2 views
            0 likes
            Last Post inanazsocial  
            Started by trilliantrader, 04-18-2024, 08:16 AM
            5 responses
            22 views
            0 likes
            Last Post trilliantrader  
            Started by Davidtowleii, Today, 12:15 AM
            0 responses
            3 views
            0 likes
            Last Post Davidtowleii  
            Started by guillembm, Yesterday, 11:25 AM
            2 responses
            9 views
            0 likes
            Last Post guillembm  
            Started by junkone, 04-21-2024, 07:17 AM
            9 responses
            70 views
            0 likes
            Last Post jeronymite  
            Working...
            X