• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Correlation indicator: instrument vs. itself

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

    Correlation indicator: instrument vs. itself

    Hi. Please see example of correlation between SPY and SPY. I would expect it to be 1 (continuous. irrespective of period). What am I missing?

    Click image for larger version

Name:	chart.png
Views:	53
Size:	45.1 KB
ID:	1108444

    #2
    Hello digibob,

    Thanks for your post.

    The Correlation indicator adds a data series for the secondary instrument and then compares this with the primary. Since the data series are not processed at the same time, comparing the same instrument will result in the added data series being a bar behind.

    We can observe if we modify the indicator so the previous bar value of the primary series is used instead of what is read from the secondary, we will see the same results as the Correlation indicator when comparing the same data series.

    We can also observe if we modify the indicator so that the current bar value of the secondary series is used and the previous value of the primary data series is used, we will get the flat line which you expect.

    We look forward to assisting.
    Attached Files
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim. Thanks for explaining and providing examples. It's clear now, I'm just not sure the implementation of the indicator is what one would expect. At least I didn't. You could argue for leading-lagging correlation but then how is the user expected to know there is leading-lagging here and which of the two instruments is which without looking in the code, and why one bar and not two bars or three, etc. it's all rather arbitrary. Is there a doc page explaining this?

      More to the point, is there a way to compare the current bars of both series without having to modify the indicator? I mean via the way of passing in the series parameters. I'm guessing there is no way.

      Comment


        #4
        Hello digibob,

        There wouldn't be documentation specifically warning users of this, but this would be a general understanding involving Multi Time Frame or Multi Instrument scripts where additional data series are processed in a script sequentially and are not processed simultaneously.

        As indicators work in general, we should expect that plots are synchronized to the primary data series, and each data series is processed in a separate update in OnBarUpdate. If we involve another data series for comparisons and assign plots on the primary data series, one data series will have a bar before the other.

        More to the point, is there a way to compare the current bars of both series without having to modify the indicator? I mean via the way of passing in the series parameters. I'm guessing there is no way.
        No, there is not. Since each data series is processed separately, you would have to modify it like I have if you are comparing the same data series. However, comparing the primary data series to the same data series wouldn't give us anything useful, and with the way the indicator works now, it compares the primary data series value with the most recent value processed from the secondary series.

        Let us know if you have any additional questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          Hi Jim. From experience working with multi instruments and time frames I know it's possible to compare bars across different series when all the bars involved are current, same timestamp, none is prior. I simply do all the work on the last BarsInProgress and if needed I use SessionIterator. The point is it's doable, but it's too small a point for discussion. All I'm saying is the Correlation indicator's current implementation may be lost on some users. More often than not correlation is used without leading-lagging, meaning each pair of price values share the same timestamp. This is what people expect by default from a Correlation indicator.

          Anyway I appreciate your help. Thanks.

          Comment


            #6
            Hello all,

            Is it possible to modify the NT8 correlation to compare a security to an indicator rather than another security?
            For example, compare CL to a 20 period ema. I'd expect them to be positively correlated most of the time.
            When they are negatively correlated (or no correlation) that is at a minimum a pause in the market.
            No correlation or negative values are what reversals will look like too though.

            The price will reverse before the correlation plot catches up. It tends to show up glaringly on sharp reversals.

            I had something that did this in NT7 and it was effective at finding reversals. I haven't been able to find an NT8 version.
            Seems to me to be an easy upgrade, the code is already there. It just needs to be able
            to add an indicator instead of a security. Easy fix, right? Or is it more complicated?

            I'd appreciate any guidance on this point.
            I thank you & good day, JM

            Comment


              #7
              Hello johnnymustard,

              The indicator does compare the two data series using an SMA. You could change Each SMA so an EMA is used if you like, or use another indicator all together.

              The SMA is called on line 66 and 76.

              EMA syntax - https://ninjatrader.com/support/help...onential_e.htm

              If you would like to change it so the first SMA uses the primary data series, you can change the BarsArray it uses to BarsArray[0] and have it processed on BarsInProgress 0.

              Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

              We look forward to assisting.
              Last edited by NinjaTrader_Jim; 07-13-2020, 07:52 AM.
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Unsuitable, Today, 07:26 AM
              1 response
              2 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by bumbledbee, Today, 04:28 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Marco  
              Started by Tmaninc, Today, 02:13 AM
              3 responses
              12 views
              0 likes
              Last Post Tmaninc
              by Tmaninc
               
              Started by rexmie888, Yesterday, 09:37 PM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_ChrisSch  
              Started by larkmail, Yesterday, 06:19 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Marco  
              Working...
              X