Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MTF + out range index value + BarsRequiredToTrade : problem

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

    #16
    Hey Chelsea, thanks

    Code:
    08/01/2020 01:27:19 | BarsInProgress: 3, 197 41449 MGC 08-21 540 Tick
    08/01/2020 01:27:34 | BarsInProgress: 0, 1177 247814 MGC 08-21 90 Tick
    08/01/2020 01:27:34 | BarsInProgress: 1, 1177 247814 MGC 08-21 90 Tick
    08/01/2020 01:27:49 | BarsInProgress: 0, 1178 247814 MGC 08-21 90 Tick
    08/01/2020 01:27:49 | BarsInProgress: 1, 1178 247814 MGC 08-21 90 Tick
    08/01/2020 01:28:02 | BarsInProgress: 0, 1179 247814 MGC 08-21 90 Tick
    08/01/2020 01:28:02 | BarsInProgress: 1, 1179 247814 MGC 08-21 90 Tick
    08/01/2020 01:28:02 | BarsInProgress: 2, 393 82724 MGC 08-21 270 Tick
    08/01/2020 01:28:21 | BarsInProgress: 0, 1180 247814 MGC 08-21 90 Tick
    08/01/2020 01:28:21 | BarsInProgress: 1, 1180 247814 MGC 08-21 90 Tick
    08/01/2020 01:28:58 | BarsInProgress: 0, 1181 247814 MGC 08-21 90 Tick
    08/01/2020 01:28:58 | BarsInProgress: 1, 1181 247814 MGC 08-21 90 Tick
    08/01/2020 01:29:12 | BarsInProgress: 0, 1182 247814 MGC 08-21 90 Tick
    08/01/2020 01:29:12 | BarsInProgress: 1, 1182 247814 MGC 08-21 90 Tick
    Strategy 'aaaaaaaaaaaaaaaaaarrrrrrrrrrrrreeee': Error on calling 'OnBarUpdate' method on bar 1182: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    By looking at our output, the last Bar from series3 to be seen is the 197th.
    meaning error occurs during the 198th.
    CurrentBar[3]'s value is 198. Correct me if Iam wrong but this would be the case if process was RealTime.

    Since this is Historical, CurrentBar[3] 's value at the error is 197.
    Last edited by Amedeus; 06-16-2021, 07:41 AM.

    Comment


      #17
      Hello Amedeus,

      Looks like it might be a few bars short of 200. Do you have condition to require CurrentBars[3] to be greater than 200 before attempting to call 200 bars in the past?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        hey Chelsea, thanks,

        This is actually the 1st line in OnBarUpdate involving CurrentBars[3],
        after beeing asked to be < BarsRequiredToTrade and < 1
        Last edited by Amedeus; 06-16-2021, 08:16 AM.

        Comment


          #19
          Hello Amedeus,

          That is not making sense to me.

          How could the error be occurring when CurrentBars[3] is 197 if the code cannot be reached until CurrentBars[3] is 200 or greater.

          I think perhaps take another look at the condition that places the order and double confirm that if (CurrentBars[3] > 200) is in that condition.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            Hey Chelsea

            just to be sure,
            I think I did edit post 18 (adding the 2nd line : after beeing asked to be < BarsRequiredToTrade and < 1)
            while you were sending post19.

            we are in the configuration post6.
            we should expect the error because CurrentBars[3] is not asked to look that much far back, this error occurs when in the analyzer, I take it is ok to have this error.
            But it should not work on the chart either, and it does.
            To me the question was : How come it works on the chart and not in the analyzer.

            if the code cannot be reached until CurrentBars[3] is 200 or greater.
            reading this tells me it is expected to have CurrentBars[3] < 200 (instead of the current configuration where CurrentBars[3] < BarsRequiredToTrade)

            It has become a big question because the original of this script (in the configuration post 6) has been bactested many times before the error occured, In both the analyzer or charts of different frames.
            Last edited by Amedeus; 06-16-2021, 08:47 AM.

            Comment


              #21
              Hello Amedeus,

              If an error is being hit in the Strategy Analyzer, then it would be necessary to determine what is causing the error to give any information on why this would be different in a chart.

              All of the errors will need to be corrected, and then it should work for both the chart and the strategy analyzer.

              On a chart the ChartControl is not null, in the Strategy Analyzer the ChartControl will be null. Any code that references that will have differences.

              If the Data Series information is different this would also have differences.

              Determine the cause the error, move that specific code to a new test script (without any other logic) and this will be enough to show why the script is behaving differently when loaded in different windows.

              Try using if (CurrentBars[3] > 200) in the condition set that places the order.

              This would prevent BarsRequiredToTrade, which may have a value of less than 200, from allowing logic to be evaluated before CurrentBars[3] has reached 200.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                Hey Chelsea, thanks,

                Code:
                protected override void OnBarUpdate()
                {
                Print(string.Format("{0} | BarsInProgress: {1}, {2} {3} {4} {5} {6}", Time[0], BarsInProgress, CurrentBar, Bars.Count , Instrument.FullName , BarsPeriod.Value, BarsPeriod.BarsPeriodType));
                
                if (BarsInProgress == 0)
                {}
                
                if (CurrentBars[0] < BarsRequiredToTrade
                || CurrentBars[1] < BarsRequiredToTrade
                || CurrentBars[2] < BarsRequiredToTrade
                || CurrentBars[3] < BarsRequiredToTrade
                || CurrentBars[4] < BarsRequiredToTrade)
                return;
                
                if (CurrentBars[0] < 1 || CurrentBars[1] < 1 || CurrentBars[2] < 1 || CurrentBars[3] < 1 || CurrentBars[4] < 1)
                return;
                
                if (BarsInProgress == 1)
                {
                
                
                // Set
                if (
                (CrossAbove(MyIndic3.Default, -13 , 200) == true )
                (CurrentBars[3] > 200)
                )
                {
                EnterLongLimit(Convert.ToInt32(DefaultQuantity), Somewhere.Lower[0], "");
                }
                
                } // BarsInProgress1 CurlyB
                Thats all that remains.


                this is causing the error
                Code:
                if (
                (CrossAbove(MyIndic3.Default, -13 , 200) == true )
                && (CurrentBars[3] > 200)
                )
                This is not causing the error
                Code:
                if ((CurrentBars[3] > 200)
                )
                Last edited by Amedeus; 06-16-2021, 09:32 AM.

                Comment


                  #23
                  and there is some new that I did not mentionned

                  on the chart, now with this totally stripped script, even
                  (CrossAbove(MyIndic3.Default, -13 , 200) == true )
                  make the strategy not want to work.

                  Comment


                    #24
                    Hello Amedeus,

                    In a new test script does:
                    if (CurrentBars[3] > 200)
                    {
                    Print(MyIndic3.Default[200]);
                    }

                    cause an error?

                    What about:
                    if (CurrentBars[3] > 200)
                    {
                    Print(CrossAbove(MyIndic3.Default, -13 , 200));
                    }

                    If yes, please provide an export of the simple test script.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #25
                      Hey Chelsea, thanks,

                      here is a recap of the all tests since post22
                      I just put it here in one place for an easy compare, while I keep examining it for a lil bit
                      Code:
                      //if (
                      //(CrossAbove(MyIndic3.Default, -13 , 200) == true )
                      //)
                      //{ EnterLong(Convert.ToInt32(DefaultQuantity), ""); }//analyzer error - chart error
                      
                      
                      //if (
                      //(CrossAbove(MyIndic3.Default, -13 , 200) == true )
                      //&& (CurrentBars[3] > 200)
                      //)
                      //{ EnterLong(Convert.ToInt32(DefaultQuantity), ""); }//analyzer error - chart error
                      
                      
                      //if (CurrentBars[3] > 200)
                      //{ EnterLong(Convert.ToInt32(DefaultQuantity), ""); } //analyzer working - chart working yellow
                      
                      
                      //if (CurrentBars[3] > 200)
                      //{
                      //Print(MyIndic3.Default[200]);
                      //} //analyzer working - chart working
                      
                      
                      //if (CurrentBars[3] > 200)
                      //{
                      //Print(CrossAbove(MyIndic3.Default, -13 , 200));
                      //} //analyzer working - chart working

                      it appears this is the problem
                      (CrossAbove(MyIndic3.Default, -13 , 200) == true )

                      I take it the export is not necessary yet.


                      Last edited by Amedeus; 06-16-2021, 11:05 AM.

                      Comment


                        #26
                        Hello Amedeus,

                        If the reduced code with only what is necessary to reproduce the error can reproduce.

                        The CurrentBar check will need to be before the call.

                        if ((CrossAbove(MyIndic3.Default, -13 , 200) == true )
                        && (CurrentBars[3] > 200)

                        This does the call before the check. You need to the check that there are enough bars before doing the call.

                        But you written that you have found the solution.

                        //if (CurrentBars[3] > 200) //{ //Print(CrossAbove(MyIndic3.Default, -13 , 200)); //} //analyzer working - chart working

                        So checking there are 200 bars first, then printing the crossabove works. So when there are enough bars there is not an error.

                        Further, you also wrote there are no differences between the chart and the Strategy Analyzer.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #27
                          Hey Chelsea, thanks,

                          ​​​​​
                          Code:
                          Further, you also wrote there are no differences between the chart and the Strategy Analyzer.
                          Well first, I am not joking but the strategy "post6" which tested positive on the chart all day, has stopped working on the chart since the few copies that we did lately. As it always should have..

                          it looks like all is working or erroring accordingly.

                          Then I try again the Original script of all this (the one with new CurrenBars[3]<250 configuration) : working on both, as expected.
                          Then, this same script is given back his initial wrong lines : CurrenBars[3]<BarsRequiredToTrade : working in analyzer , not working on chart.. (like in post2)

                          So... I will have to dig this again,
                          any idea before I start ?





                          Comment


                            #28
                            Hello Amedeus,

                            CurrentBars[3] has to be greater than 200.
                            If its not you get the error.
                            If it is, then no error.

                            Just make sure CurrentBars[3] is 200 or greater before attempting to call MyIndic3.Default 200 bars ago.

                            This should also make it clear that BarsRequiredToTrade is not 200 or that condition is not written as you are wanting.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #29
                              Hey Chelsea, thanks,

                              Please import the attached sample.

                              In this sample we can see the configuration of post6

                              At no time was CurrentBar[2] asked to check for 300 bars of lookBack.
                              Actually, from what I understand, this sample should not be able to lookback more than 256 bars of any CurrentBars.

                              Why/how is this condition able access to such a far back CurrentBar ?
                              why is there no index error when running it ? neither on analyzer or chart.

                              If we request the only condition to be lesser than 100 like this :
                              Code:
                              if (
                              (CurrentBars[2] < 100)
                              && (CrossAbove(Closes[2], KC2.Lower, 200) == true)
                              )// working
                              what about the 100 CurrentBar (of our CurrentBars[2] collection) in the Crossabove condition that can not be accessed ?
                              Is this not the same as asking our calculation : "you can process with a sight of 100, but consider what is not in your sight too, (and for the double of it)" ?
                              Should we find this allright ?

                              Attached Files
                              Last edited by Amedeus; 06-17-2021, 05:48 AM.

                              Comment


                                #30
                                Hey Chelsea,

                                In addition to the post 29 essential questions,
                                this condition causes an error in analyzer but not in the chart
                                Code:
                                if (CurrentBars[3] < 201)
                                {
                                Print(CrossAbove(Closes[3], KC3.Lower, 200) == true);
                                } //analyzer error - chart Working
                                this condition needs a new Private so you will find attached a .txt with an updated version of our sample, as well as what has become of our sample.

                                This condition performs as yesterday : //analyzer error - chart Working

                                We should be super close of figuring out what I could not catch about CurrentBars[] processing.
                                Attached Files
                                Last edited by Amedeus; 06-17-2021, 07:20 AM.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Yesterday, 05:17 AM
                                0 responses
                                65 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                139 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                75 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                45 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                50 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X