Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What is the exact difference between these two Compares

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

    What is the exact difference between these two Compares

    What is the exact difference between these two Compares


    Code:
    ...
    if (BarsArray[0].Instrument.MasterInstrument.Compare(Close[0], Open[0]) == 0)
    ...
    AND

    Code:
    ...
    if (Bars.Instrument.MasterInstrument.Compare(Close[0], Open[0]) == 0) 
    ...
    And in what kind of scenarios, would I need either Bars or BarsArray[0] to
    access the Instrument.MasterInstrument instead of going directly to Instrument.MasterInstrument?

    #2
    cdjindia, one would point specifically to a BarsArray / index to use, while the other would work in the called context then. The suggestion would be generally to use the Instrument class we have documented, as the Bars object would not be in supported scope.

    Comment


      #3
      Bertrand

      I cannot understand the differnce but given that you said something about context, I checked Initialize() and this is all I can find in the Initialize() method.

      Code:
      Add(new Plot(pen, PlotStyle.Dot, "Dots"));
      PeriodType maBarType = PeriodType.Minute;
      int maBarPeriod = 5;
      Add(maBarType, maBarPeriod);
      In the actual code, parameters to Add(..) are properties which I've represented as local variables to make it clear for you folks

      Therefore

      Please confirm that BarsArray[0] in this context is completely irrelevant because nothing in Initialize() is impacting MasterInstrument at all
      Please confirm that BarsArray[0] would make it always point to the primary chart series.
      Please confirm that for BarsArray with non zero indice to work, Indicator's Initialize() method would need to have few more Add(...) calls in it.

      Can you at least provide one example (or point to URL having example) in which two earlier statements would yield different results ?
      Last edited by cdjindia; 01-08-2014, 08:46 AM.

      Comment


        #4
        cdjindia, with context I referred to in which OnBarUpdate / BarsInProgress you use the statements - for a single series script I would not expect differences as both would be tied to the primary and only series.

        Comment


          #5
          Why are you expecting different results?

          Please post the different results you are seeing if you are. Why are we playing hypothetical here?

          Compare is compare is compare.

          You might throw an out of index if you had something other than 0 in BarsArray. But that is well documented here and is more of a run time error.



          Originally posted by cdjindia View Post
          Bertrand

          I cannot understand the differnce but given that you said something about context, I checked Initialize() and this is all I can find in the Initialize() method.

          Code:
          Add(new Plot(pen, PlotStyle.Dot, "Dots"));
          PeriodType maBarType = PeriodType.Minute;
          int maBarPeriod = 5;
          Add(maBarType, maBarPeriod);
          In the actual code, parameters to Add(..) are properties which I've represented as local variables to make it clear for you folks

          Therefore

          Please confirm that BarsArray[0] in this context is completely irrelevant because nothing in Initialize() is impacting MasterInstrument at all
          Please confirm that BarsArray[0] would make it always point to the primary chart series.
          Please confirm that for BarsArray with non zero indice to work, Indicator's Initialize() method would need to have few more Add(...) calls in it.

          Can you at least provide one example (or point to URL having example) in which two earlier statements would yield different results ?

          Comment


            #6
            Bertrand

            Sorry for being hypothetical but this body of code was inherited by me (as in written by some1 else who has left). Client has mentioned that it has too many errors and missing signals.

            So, I am screening each and every if statement and compare. In fact, I've grep'd all of them out and then sorted and collated them into a list (hit-list, you may call that) for me to examine one by one.

            This pair has struck me as odd and has been used alternatively at many places. There were few others where earlier fellow was referring to different plot which I've fixed.

            Comment


              #7
              Sorry. . Yeah that would be confusing then. Sounds like he used whatever he felt like.

              You could match them together in the code to prove out their equivalence.

              Lots of prints to output window for tracking down missed signals.





              Originally posted by cdjindia View Post
              Bertrand

              Sorry for being hypothetical but this body of code was inherited by me (as in written by some1 else who has left). Client has mentioned that it has too many errors and missing signals.

              So, I am screening each and every if statement and compare. In fact, I've grep'd all of them out and then sorted and collated them into a list (hit-list, you may call that) for me to examine one by one.

              This pair has struck me as odd and has been used alternatively at many places. There were few others where earlier fellow was referring to different plot which I've fixed.

              Comment


                #8
                Thanks sledge, that would be my recommendation as well, trying to simplify and streamline the code even if that means going one by one to make sure it prints / calculates exactly as expected. Replacing parts with 'true' NinjaScript like directly from the Instrument class would be helpful likely as well to minimize potential for side effects from the non documented.

                Comment


                  #9
                  Sorry, It got worse.

                  It seems that the Add(maBarType, maBarPeriod) was meant to be a Higher time frame Moving Average which was to be used as filter and I am unable to find any reference anywhere to BarsArray[1]

                  There is one place where if (BarsInProgress == 1) is being used but it simply calls SMA twice like this
                  mFast = SMA(Close, 20).Value[0]

                  Comment


                    #10
                    Correct, looks like it adds in a 5 min chart per default.

                    maBarType = PeriodType.Minute;
                    int maBarPeriod = 5;

                    Comment


                      #11
                      So, unless I find reference to BarsArray[1], it is safe to assume that Moving average added on higher time frame is not actually being used, Correct?

                      Comment


                        #12
                        No, if you work in BarsInProgress one context that would always be the higher timeframe.

                        Comment


                          #13
                          Originally posted by NinjaTrader_Bertrand View Post
                          No, if you work in BarsInProgress one context that would always be the higher timeframe.
                          You mean this as BarsInProgress one context?
                          Code:
                           if (BarsInProgress == 1)
                           {
                              // You mean this as BarsInProgress one context?
                           }

                          Comment


                            #14
                            Correct, here you work on updates from your added series. BarsInProgress == 0 primary, == 1 secondary and so on...

                            Comment


                              #15
                              So as conclusion to this thread, following 3 if statements (verbatim) will never ever a cause different result

                              Code:
                              if (BarsArray[0].Instrument.MasterInstrument.Compare(Close[0], Open[0]) == 0)
                              VS

                              Code:
                              if (Bars.Instrument.MasterInstrument.Compare(Close[0], Open[0]) == 0)
                              VS

                              Code:
                              if (Instrument.MasterInstrument.Compare(Close[0], Open[0]) == 0)
                              Naturally, I understand that the last one is the recommended one

                              Comment

                              Latest Posts

                              Collapse

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