Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Current Most Recent Occurrence vs previous

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

    Current Most Recent Occurrence vs previous

    Hi,

    I am trying to do a script that will compare the value of the low of the current pivot low with the previous value of the low of the previous pivot low.
    For it I try to use the MRO() but I am unable to retrieve the value of the previous low
    The idea is to say that if the current low of the pivot low is higher than it's a Lower High if the low of the value is lower than it's a Lower Low

    Expected output : Look at Screenshot 1

    In final i need to understand the occurrence and the barsback as i will be doing a count that reset or increment depending on if it's a lower low ( resets on lower low) or lower high ( increment on lower high ) But I first need to understand the lower low and lower high concept ( Screenshot 2 )




    Here is my code Attempt and as you will see i am able to output the current Pivot Low Low but the previous one doesn't output correctly . I am unsure what is the problem



    Code:
                //Check to make sure that the Chart as at least one Bar before we compute anything
                if(CurrentBars[0] < 1 )
                    return;
    
                //Define some variable
                double iOffset = 0.25;
    
                // Definition of pivot
                // I go up to 9 equal lows in case            
                bool pivotlow1 = (Low[0] > Low[1]) &&  (Low[1] < Low[2]);
                bool pivotlow2 = (Low[0] > Low[1]) &&  (Low[1] == Low[2]) && (Low[2] < Low[3]) ;
                bool pivotlow3 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] < Low[4]);
                bool pivotlow4 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] < Low[5]);
                bool pivotlow5 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] < Low[6]) ;
                bool pivotlow6 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] == Low[6]) && (Low[5] < Low[6]) ;
                bool pivotlow7 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] == Low[6]) && (Low[5] == Low[6]) && (Low[6] < Low[7]);
                bool pivotlow8 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] == Low[6]) && (Low[5] == Low[6]) && (Low[6] == Low[7]) && (Low[7] < Low[8]);
                bool pivotlow9 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] == Low[6]) && (Low[5] == Low[6]) && (Low[6] == Low[7]) && (Low[7] == Low[8]) && (Low[9] < Low[10]);
    
    //            Definition of a pivot low
                bool pl = (pivotlow1) || (pivotlow2) || (pivotlow3) || (pivotlow4) || (pivotlow5) || (pivotlow6) || (pivotlow7) || (pivotlow8) || (pivotlow9) ;
    
    //            Get the bar index at which the pivot is happening
                int CurrentPivotLow = MRO(() => pl , 1 , CurrentBar) ;
                int PrevioustPivotLow = MRO(() => pl , 2 , CurrentBar) ;
    
    
    //            Plot The Pivot
                if (pl) {            
                Draw.Text(this, "Even"+CurrentBar, "PivotLow" , 1 , Low[1] - iOffset);
                Print(string.Format("The Time: {0} | CurrentBar: {1} | LowCurrentPivotLow : {2} | LowPreviousPivotLow : {3} " ,Time[0],CurrentBar,Low[CurrentPivotLow + 1 ], Low[PrevioustPivotLow + 1 ] ) );
    //            Draw.Text(this, "Even"+CurrentBar, CurrentPivotLowBarValue.ToString() , 1 , Low[1] - 1  );
                }
    Print output screenshot 3 ( the value are always equal between current and previous)


    Edit1 : Trying to do another methodology than the MRO

    I also try to do it via another methodology where i try to track of the low value and compare it to the previous but the previous value keep resetting to zero. So I am unsure how to reassign a new value to the double within the if statement. I guess i might be missing something on the documentation. I did see the Series<T> object on the documentation but I am unable to understand how to make it work. IF someone could apply the T series object to my example maybe i can figure out then how to access values


    Code:
                if(CurrentBars[0] < 1 )
                    return;
    
                //Define some variable
                double iOffset = 0.25;
    
                // Definition of pivot
                // I go up to 9 equal lows in case            
                bool pivotlow1 = (Low[0] > Low[1]) &&  (Low[1] < Low[2]);
                bool pivotlow2 = (Low[0] > Low[1]) &&  (Low[1] == Low[2]) && (Low[2] < Low[3]) ;
                bool pivotlow3 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] < Low[4]);
                bool pivotlow4 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] < Low[5]);
                bool pivotlow5 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] < Low[6]) ;
                bool pivotlow6 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] == Low[6]) && (Low[5] < Low[6]) ;
                bool pivotlow7 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] == Low[6]) && (Low[5] == Low[6]) && (Low[6] < Low[7]);
                bool pivotlow8 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] == Low[6]) && (Low[5] == Low[6]) && (Low[6] == Low[7]) && (Low[7] < Low[8]);
                bool pivotlow9 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] == Low[6]) && (Low[5] == Low[6]) && (Low[6] == Low[7]) && (Low[7] == Low[8]) && (Low[9] < Low[10]);
    
    ////            Definition of a pivot low
                bool pl = (pivotlow1) || (pivotlow2) || (pivotlow3) || (pivotlow4) || (pivotlow5) || (pivotlow6) || (pivotlow7) || (pivotlow8) || (pivotlow9) ;
    
    ////            Get the bar index at which the pivot is happening
    //            int CurrentPivotLow = MRO(() => pl , 1 , CurrentBar) ;
    //            int PrevioustPivotLow = MRO(() => pl , 2 , CurrentBar) ;
    
    
    ////            Plot The Pivot
    //            if (pl) {            
    //            Draw.Text(this, "Even"+CurrentBar, "PivotLow" , 1 , Low[1] - iOffset);
    //            Print(string.Format("The Time: {0} | CurrentBar: {1} | LowCurrentPivotLow : {2} | LowPreviousPivotLow  : {3} " ,Time[0],CurrentBar,Low[CurrentPivotLow + 1 ], Low[PrevioustPivotLow + 1 ] ) );
    ////            Draw.Text(this, "Even"+CurrentBar, CurrentPivotLowBarValue.ToString() , 1 , Low[1] - 1  );
    //            }
    
    
    
                //Other method
                    double PivotCurrentlow = 0 ;
                    double PreviousPivotlow = 0 ;
                if (pl) {
    
                    PivotCurrentlow = Low[1] ;
                    Print(string.Format("The Time: {0} | CurrentBar: {1} | PivotCurrentlow:{2} | PreviousPivotlow : {3}  " ,Time[0],CurrentBar, PivotCurrentlow , PreviousPivotlow ) );
    
                    if (  PivotCurrentlow > PreviousPivotlow ) {
                        PreviousPivotlow = PivotCurrentlow ;
    
                    Draw.Text(this, "Even"+CurrentBar, "Lower High" , 1 , Low[1] - iOffset);                    
                    }
    
                    if ( PivotCurrentlow <= PreviousPivotlow ) {
                        PreviousPivotlow = PivotCurrentlow ;
                    Draw.Text(this, "Even"+CurrentBar, "Lower Low" , 1 , Low[1] - iOffset);                    
                    }
    
                }

    Edit 2: I found one solution to my question using the Edit 1 methodology


    Code:
                //Other method
    
                if (pl) {
    
                    double PivotCurrentlow = Low[1] ;
                    Print(string.Format("The Time: {0} | CurrentBar: {1} | PivotCurrentlow:{2} | PreviousPivotlow : {3} | " ,Time[0],CurrentBar, PivotCurrentlow , PreviousPivotlow) );
                    if (  PivotCurrentlow > PreviousPivotlow ) {
                        Draw.Text(this, "Higher Low"+CurrentBar, "[HL]" , 1 , Low[1] - iOffset2);
                    }
    
                    if ( PivotCurrentlow < PreviousPivotlow ) {
                        Draw.Text(this, "Lower Low"+CurrentBar, "[LL]" , 1 , Low[1] - iOffset2);
                    }
                    if ( PivotCurrentlow == PreviousPivotlow ) {
                        CountPivotLowABCDE = 1 ;
                        Draw.Text(this, "Equal Low"+CurrentBar, "[EQL]" , 1 , Low[1] - iOffset2);
                    }
    
                    PreviousPivotlow = Low[1] ;    
    
                }

    But I am still interested to understand why the MRO solution is not working if you guys can guide on what i am doing wrong as in my opinion it could be much easier for me to keep track of previous values

    Thanks in advance



    Last edited by papaoutai; 07-19-2020, 11:12 AM.

    #2
    Hello papaoutai,

    MRO is expecting that you supply a condition (one that will be true on some bars and not true on other as it evaluates your condition on each bar in the period).


    It appears you are supplying a bool that already has a value and you are not supplying a condition for it to test. In other words, the bool value you are using is the same value for every bar as there is no condition to test.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for your answer. I am not sure to still fully understand the answer and what will solve the problem as for me my bool is a condition
      Basically my bool is searching for the condition of being a pivot low

      Code:
       
       bool pl = (pivotlow1) || (pivotlow2) || (pivotlow3) || (pivotlow4) || (pivotlow5) || (pivotlow6) || (pivotlow7) || (pivotlow8) || (pivotlow9) ;
      I could have written this to make it appear as a condition

      Code:
                
       int CurrentPivotLow = MRO(() => (pivotlow1) || (pivotlow2) || (pivotlow3) || (pivotlow4) || (pivotlow5) || (pivotlow6) || (pivotlow7) || (pivotlow8) || (pivotlow9) , 1 , 50) ;
       int PrevioustPivotLow = MRO(() => (pivotlow1) || (pivotlow2) || (pivotlow3) || (pivotlow4) || (pivotlow5) || (pivotlow6) || (pivotlow7) || (pivotlow8) || (pivotlow9) , 2 , 50) ;
      Normally this condition is not true on each BAR as a Pivot low as a specific definition . Anyway it's fine maybe I will just forget about this MRO and stick to some if else condition keeping track of the previous value with a private variable

      Thanks,

      Comment


        #4
        Hello papaoutai,

        Yes, calling MRO() and supplying the condition, instead of supplying a bool, allows that condition to be tested on each bar.

        Are you finding that the MRO() method is not returning the bar number of when that condition was true within the period?

        On what bar are you finding the condition is true?
        What is the value returned by MRO()?

        Using the custom conditions would work just as well. This MRO() is just a method that has some prewritten logic that you could indeed directly code in to the script without using this method.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi ,

          Unfortunately it is always returning 0 or 1 but not the MRO() is not returning the bar index at which it is happening for the current and the previous

          Attach a screenshot

          The code I have done


          Code:
                      //Check to make sure that the Chart as at least one Bar before we compute anything
                      if(CurrentBars[0] < 11 )
                          return;
          
          
          
          
                      //Define some variable
                      double iOffset = 0.2;
                      double iOffset2 = 0.3;
                      double iOffset3 = 0.6;
          
          
                      // Definition of pivot
                      // I go up to 9 equal lows in case            
                      bool pivotlow1 = (Low[0] > Low[1]) &&  (Low[1] < Low[2]);
                      bool pivotlow2 = (Low[0] > Low[1]) &&  (Low[1] == Low[2]) && (Low[2] < Low[3]) ;
                      bool pivotlow3 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] < Low[4]);
                      bool pivotlow4 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] < Low[5]);
                      bool pivotlow5 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] < Low[6]) ;
                      bool pivotlow6 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] == Low[6]) && (Low[5] < Low[6]) ;
                      bool pivotlow7 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] == Low[6]) && (Low[5] == Low[6]) && (Low[6] < Low[7]);
                      bool pivotlow8 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] == Low[6]) && (Low[5] == Low[6]) && (Low[6] == Low[7]) && (Low[7] < Low[8]);
                      bool pivotlow9 = (Low[0] > Low[1]) &&  (Low[1] == Low[2])  && (Low[2] == Low[3]) && (Low[3] == Low[4]) && (Low[4] == Low[5]) && (Low[5] == Low[6]) && (Low[5] == Low[6]) && (Low[6] == Low[7]) && (Low[7] == Low[8]) && (Low[9] < Low[10]);
          
          ////            Definition of a pivot low
                      bool pl = (pivotlow1) || (pivotlow2) || (pivotlow3) || (pivotlow4) || (pivotlow5) || (pivotlow6) || (pivotlow7) || (pivotlow8) || (pivotlow9) ;
          
          
          
          // My first attempt using MRO that I am nt able to make it work    
          
          //            Get the bar index at which the pivot is happening
                  int totalbarsonChart = ChartBars.Count;    
                  int CurrentPivotLow = MRO(() => (pivotlow1) || (pivotlow2) || (pivotlow3) || (pivotlow4) || (pivotlow5) || (pivotlow6) || (pivotlow7) || (pivotlow8) || (pivotlow9) , 1 , 50) ;
                  int PrevioustPivotLow = MRO(() => (pivotlow1) || (pivotlow2) || (pivotlow3) || (pivotlow4) || (pivotlow5) || (pivotlow6) || (pivotlow7) || (pivotlow8) || (pivotlow9) , 2 , 50) ;
                  Print(string.Format("The Time: {0} | CurrentBar: {1} | CurrentPivotLow : {2} | PrevioustPivotLow  : {3} | TotalBars {4} " ,Time[0],CurrentBar,CurrentPivotLow,PrevioustPivotLow ,totalbarsonChart )  );

          If the MRO gave me the barindex of the previous and the current i could maybe play with the totalbarsonChart the CurrentBar but I don't see a possible escape to this MRO as 0 1 doesn't really help me Maybe there is something again that i don't understand to be able to retrieve the Bar number

          Last edited by papaoutai; 07-19-2020, 09:54 PM.

          Comment


            #6
            Hello papaoutai,

            Print the values from the condition, and then print the value of MRO(). This is so we can see on what bars the condition is true and see on which bars MRO() is giving a value of 1 (meaning it found the condition true 1 bar ago).
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            581 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            338 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            554 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            552 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X