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

Multi-Instrument Indicator

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

    Multi-Instrument Indicator

    Hello Support,

    I am creating an indicator that will plot the ratio of EMAs of 2 separate instruments. What i am doing is that i put the dataseries of the 2 instruments on the chart. In my code:

    double ema1 = EMA(BarsArray[0],_ema1Length)[0];
    double ema2 = EMA(ChartControl.BarsArray[1],_ema2Length)[0];


    I calculate the ratio and then plot it.

    I get some very peculiar and inconsistent behaviour. The above code somethimes work and sometimes it doesnt. Changing the 2nd line to:

    double ema2 = EMA(ChartControl.BarsArray[1],_ema2Length)[-1];

    works. And then after some time of running, it stops working again. And when i change the statement to 0 offset, it starts to work.

    The exception that i get is:

    4/17/2013 7:36:11 PM|3|4|Error on calling 'OnBarUpdate' method for indicator 'EMARatio' 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.

    Can you please explain the behaviour or what i am supposed to do.

    Thanks.
    Umer

    #2
    Hello Umer,

    ChartControl, is not a supported method by NinjaTrader.

    With that said, the error message means that you are accessing a Data Series that does not have enough data loaded. Since you are accessing a Secondary Series on a chart rather than inside of the Indicator itself you would have to create a check to make sure that it has enough bars before you start your calculations like in the following thread post.

    JCNinjaTrader Customer Service

    Comment


      #3
      Hello JC,

      Thanks for your reply.

      I have put in all those checks. And the exception is on the EMA dataseries. Please advice. I can share the indicator as well

      Thanks.
      Umer

      Comment


        #4
        Hello Umer,

        It looks like on one of your EMA Data Series you are passing it the "ChartControl.BarsArray[1]" which can be accessing data that is not valid since you are checking "-1" BarsAgo.

        If you would like to share the indicator, I can take a look at it to see if anything stands out to me or any other member that comes across this thread.
        JCNinjaTrader Customer Service

        Comment


          #5
          Originally posted by Master.Aurora View Post
          Hello Support,

          I am creating an indicator that will plot the ratio of EMAs of 2 separate instruments. What i am doing is that i put the dataseries of the 2 instruments on the chart. In my code:

          double ema1 = EMA(BarsArray[0],_ema1Length)[0];
          double ema2 = EMA(ChartControl.BarsArray[1],_ema2Length)[0];

          I calculate the ratio and then plot it.

          I get some very peculiar and inconsistent behaviour. The above code somethimes work and sometimes it doesnt. Changing the 2nd line to:

          double ema2 = EMA(ChartControl.BarsArray[1],_ema2Length)[-1];

          works. And then after some time of running, it stops working again. And when i change the statement to 0 offset, it starts to work.

          The exception that i get is:

          4/17/2013 7:36:11 PM|3|4|Error on calling 'OnBarUpdate' method for indicator 'EMARatio' 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.

          Can you please explain the behaviour or what i am supposed to do.

          Thanks.
          Umer
          You need a CurrentBars validity check for each and every barSeries that you are loading.

          Comment


            #6
            JC, if you read my original message completely, i have specifically mentioned that using -1 works for me sometimes and then it stops working.

            I am attaching the indicator. Please advise.

            Thanks.
            Umer
            Attached Files

            Comment


              #7
              Hello Master.Aurora,

              Thank you for your response.

              As the ChartControl.BarsArray is unsupported in NinjaScript, can you describe why you are using ChartControl.BarsArray over BarsArray and ChartControl.BarsArray[0].Count over CurrentBars?

              I look forward to your response.

              Comment


                #8
                Originally posted by Master.Aurora View Post
                JC, if you read my original message completely, i have specifically mentioned that using -1 works for me sometimes and then it stops working.

                I am attaching the indicator. Please advise.

                Thanks.
                Umer
                This should help you see what is going on:

                Code:
                  protected override void OnBarUpdate()
                        {
                            // Use this method for calculating your indicator values. Assign a value to each
                            // plot below by replacing 'Close[0]' with your own formula.
                
                [COLOR="Blue"][B][I]Print ( "BarsArray[0].Count=" +  BarsArray[0].Count);
                Print ( "ChartControl.BarsArray[0].Count=" +  ChartControl.BarsArray[0].Count);
                Print ( "BarsArray[1].Count=" +  BarsArray[1].Count); //might not be valid?
                Print ( "ChartControl.BarsArray[1].Count=" +  ChartControl.BarsArray[1].Count);
                Print ( "BarsRequired = " + BarsRequired );[/I][/B][/COLOR]
                
                
                			if(ChartControl.BarsArray[0].Count<= BarsRequired || ChartControl.BarsArray[1].Count<= BarsRequired)
                				return;

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by gbourque, Today, 06:39 AM
                2 responses
                14 views
                0 likes
                Last Post gbourque  
                Started by rexsole, Today, 08:39 AM
                0 responses
                4 views
                0 likes
                Last Post rexsole
                by rexsole
                 
                Started by trilliantrader, Yesterday, 03:01 PM
                3 responses
                30 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by cmtjoancolmenero, Yesterday, 03:58 PM
                4 responses
                26 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by Brevo, Today, 01:45 AM
                1 response
                14 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X