Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Access to multiple bars under certain conditions

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

    Access to multiple bars under certain conditions

    Hi, dear NinjaSupport Team


    I want to use the DataSeries to store the bars that are as a whole above and below the SMA.
    Unfortunately I do not know how to do this calculation.
    I want to take from these DataSeries the highest or lowest bar for example: High(GetValueAt(HighBar)
    HighBar = MAX(int period)[int barsAgo]

    I want to store these values in a DataSeries which I can access and get the values. HIGH of the period and LOW of the period or the current high or low.

    I have now made some progress.
    I have the span, the start and end candle.
    Unfortunately I cannot work with highSeries[0] = MAX(startBarLong, spanLong)[0];.
    I can't compile it. How can I access the highest values within the span?


    Click image for larger version  Name:	Code, span, start, end.JPG Views:	0 Size:	34.0 KB ID:	1183039Click image for larger version

Name:	Brush low, above.JPG
Views:	201
Size:	8.1 KB
ID:	1183040
    Click image for larger version  Name:	image_70987.jpg Views:	3 Size:	106.7 KB ID:	1183037



    Merry christmas and happy new year from Germany


    With kind regards
    Tradeer
    Last edited by Tradeer; 12-26-2021, 11:00 AM.

    #2
    Hello Tradeer,

    Perhaps?
    highSeries[0] = MAX(spanLong)[startBarLong];
    Print("highSeries[0]: " + highSeries[0]);
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Tradeer,

      Perhaps?
      highSeries[0] = MAX(spanLong)[startBarLong];
      Print("highSeries[0]: " + highSeries[0]);
      Awesome thanks it worked !

      I had to change only additionally int series in double series.
      And set if (Low[0] <= SMA1[0]){spanLong = 1;}; to 1 because with 0 an error message appears.
      Thanks Chelsea, I appreciate it
      Last edited by Tradeer; 12-26-2021, 06:56 PM.

      Comment


        #4
        Originally posted by Tradeer View Post

        Awesome thanks it worked !

        I had to change only additionally int series in double series.
        And set if (Low[0] <= SMA1[0]){spanLong = 1;}; to 1 because with 0 an error message appears.
        Thanks Chelsea I am mega happy right now. I appreciate it
        Unfortunately the values are wrong I do not know why any idea?

        Click image for larger version  Name:	compare highs.JPG Views:	0 Size:	76.0 KB ID:	1183069
        Click image for larger version

Name:	Code highSeries.JPG
Views:	153
Size:	33.1 KB
ID:	1183073
        Last edited by Tradeer; 12-26-2021, 04:40 PM.

        Comment


          #5
          Hello Tradeer,

          Is this printed before or after the bar closed?

          If you print the High[0] does this match the chart?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_ChelseaB View Post
            Hello Tradeer,

            Is this printed before or after the bar closed?

            If you print the High[0] does this match the chart?
            The High[0] matches with the bars it is correct. It is printed on bar close, after the bar closed.

            Hmm strange I am trying to find the error.

            Thanks for your fast reply



            Click image for larger version  Name:	HIGH matched.JPG Views:	0 Size:	124.5 KB ID:	1183078
            Last edited by Tradeer; 12-26-2021, 04:52 PM.

            Comment


              #7
              Hello Tradeer,

              Can you print the time of the bar, and print the values being supplied to the MAX indicator?

              Print(string.Format("{0} | MAX({1})[{2}]: {3}", Time[0], spanLong, startBarLong, MAX(spanLong)[startBarLong]));
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_ChelseaB View Post
                Hello Tradeer,

                Can you print the time of the bar, and print the values being supplied to the MAX indicator?

                Print(string.Format("{0} | MAX({1})[{2}]: {3}", Time[0], spanLong, startBarLong, MAX(spanLong)[startBarLong]));
                I think something is wrong with the period and barsAgo

                if I print it with this value highSeries[0] = High.GetValueAt(startBarLong); the startBar high matches.

                There is something wrong with the values I think. I am trying to fix that. Thank you for your help



                Click image for larger version  Name:	Print Time.JPG Views:	0 Size:	153.8 KB ID:	1183083
                Last edited by Tradeer; 12-26-2021, 05:31 PM.

                Comment


                  #9
                  Tradeer,

                  Are you using the High series for the input to MAX()?

                  MAX(High, spanLong)[startBarLong]
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by NinjaTrader_ChelseaB View Post
                    Tradeer,

                    Are you using the High series for the input to MAX()?

                    MAX(High, spanLong)[startBarLong]
                    Hey Chelsea,

                    ah no I was not using the High series. That was one of the problems. Something was wrong with the startBarLong it was not needed.
                    So this highSeries[0] = MAX(High, spanLong)[0]; works right now.
                    Awesome thank you for your patience and useful help.
                    It should work now
                    Last edited by Tradeer; 12-26-2021, 06:59 PM.

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Tradeer,

                      Are you using the High series for the input to MAX()?

                      MAX(High, spanLong)[startBarLong]
                      Hello Chelsea,

                      so the values are correct now. The highSeries are now accurate and show the high of the span.
                      Now I have the following problem. When creating an entry logic, the positions are executed incorrectly.
                      The error should be in the entry logic, because the values are correct, unfortunately I do not know what should be wrong with the the entryCondition code. Maybe you can help me further. Thank you.

                      Condition 1: spanLong >= 2 // (At least 2 lows above or equal the SMA)
                      Condition 2: High[0] >= highSeries[1] // (The current high should be higher, as the last high of the highSeries)

                      entryConditionLong = true;

                      With kind regards
                      Tradeer


                      Click image for larger version

Name:	entrCondition.JPG
Views:	141
Size:	36.5 KB
ID:	1183165
                      Click image for larger version

Name:	Picture wrong execution.JPG
Views:	170
Size:	194.3 KB
ID:	1183167

                      Attached Files

                      Comment


                        #12
                        Hello Tradeer,

                        May I have the output from the output window saved to a text file for the prints that print the values in the condition that set this bool?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ChelseaB View Post
                          Hello Tradeer,

                          May I have the output from the output window saved to a text file for the prints that print the values in the condition that set this bool?
                          Hey Chelsea,

                          thanks for the quick reply.
                          I have saved the values from the output window to a text file and attached it.
                          I have also attached the complete code.

                          Best regards
                          Tradeer

                          Code:
                           highSeries[0] = MAX(High, spanLong)[0];
                          
                          
                          if (spanLong >= 2 && High[0] >= highSeries[1])
                          {
                          entryConditionLong = true;
                          
                          }
                          
                          
                          Print("-------------------------------------------------------------");
                          Print("highSeries[1]: " + highSeries[1]);
                          Print("highSeries[0]: " + highSeries[0]);
                          Print("High: " + High[0]);
                          
                          Print("startBarLong: " + startBarLong);
                          Print("endBarLong: " + endBarLong);
                          Print("spanLong: " + spanLong);
                          Print("-------------------------------------------------------------");
                          Attached Files

                          Comment


                            #14
                            Hello Tradeer,

                            I'd like to help you write a more insightful print.

                            Have a look at the example print and output in this forum post.


                            Start by printing the time of the bar, this important to find where (when) a condition is evaluating unexpectedly.

                            I encourage you to use string.Format(), but you can also catenate strings and variable tostring values with plus signs '+'.

                            In the print have this look like the condition itself, and add labels to the values and comparisons symbols so we know what is being compared.

                            The condition is 'if (spanLong >= 2 && High[0] >= highSeries[1])'

                            I'd like to start with the time of the bar and the first condition:
                            Print(string.Format("{0} | spanLong: {1} >= 2 &&", Time[0], spanLong));

                            Try completing this print with the second half of this condition.
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_ChelseaB View Post
                              Hello Tradeer,

                              I'd like to help you write a more insightful print.

                              Have a look at the example print and output in this forum post.
                              https://ninjatrader.com/support/foru...121#post791121

                              Start by printing the time of the bar, this important to find where (when) a condition is evaluating unexpectedly.

                              I encourage you to use string.Format(), but you can also catenate strings and variable tostring values with plus signs '+'.

                              In the print have this look like the condition itself, and add labels to the values and comparisons symbols so we know what is being compared.

                              The condition is 'if (spanLong >= 2 && High[0] >= highSeries[1])'

                              I'd like to start with the time of the bar and the first condition:
                              Print(string.Format("{0} | spanLong: {1} >= 2 &&", Time[0], spanLong));

                              Try completing this print with the second half of this condition.
                              Ah okay I get it. I hope this print is more detailed, the times may differ as they are German times.
                              I'll go through it again and see if I can find the error.
                              I have set the time range to 23.12 and used only 1 day.

                              I went through again it seems to be due to the execution of the orders that when the profit or stop is reached a new position is entered. Is there any solution to this?

                              Code:
                              Print(string.Format("{0} | spanLong: {1} >= 2 && High[0]: {2} >= highSeries[1]: {3}", Time[0], spanLong, High[0], highSeries[1]));

                              Kind regards

                              Tradeer
                              Attached Files
                              Last edited by Tradeer; 12-27-2021, 09:52 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              72 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              143 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              76 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              47 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              51 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X