Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Relative Performance Charts Comparing Two Instruments

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

    Relative Performance Charts Comparing Two Instruments

    Hey,

    I was wondering how I can view the relative performance of two instruments. For example, this is achieved on other platforms by entering [Instrument 1]/[Instrument 2], essentially dividing one by the other.

    Thanks

    #2
    Hello Splex,

    You would need to add this calculation to an indicator.

    Open a NinjaScript Editor from the New menu
    Right-click the Indicators folder and select New Indicator
    In the Indicator Wizard on the Additional Data page add a secondary instrument
    On the Plots and Lines page add a plot
    Generate the script

    Within the OnBarUpdate() methods action block add the code
    Code:
    if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
    {
    Values[0] = Closes[0] / Closes[1];
    }
    Then right-click the code and select Compile.
    Next add the indicator to a chart.

    Below is a public link to a post with helpful information about getting started with NinjaScript.


    A link to a Spread indicator which shows the difference between two instruments.


    As well as a few links that discuss dynamically using variables to load a secondary series.



    You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our business development follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3

      Hi When I use the script with NT8 it gives and error during compilation
      myditorIndicator.cs Operator '/' cannot be applied to operands of type 'NinjaTrader.NinjaScript.PriceSeries' and 'NinjaTrader.NinjaScript.PriceSeries' CS0019 59 13
      Values[0] = Closes[0] / Closes[1]; any help with syntax is appreaciated thanks

      Comment


        #4
        Hello 2sureshk,

        Thanks for your post.

        Sorry for the error in the example, please try Values[0][0] = Closes[0][0] / Closes[1][0]; // divide the current bar value of the chart bars by the added data series.
        Last edited by NinjaTrader_PaulH; 09-30-2019, 08:26 AM. Reason: Corrected example to add the current bar index to Values[0]
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello 2sureshk,

          Thanks for your post.

          Sorry for the error in the example, please try Values[0] = Closes[0][0] / Closes[1][0]; // divide the current bar value of the chart bars by the added data series.
          Premise: I'm not a programmer.
          I tried with the code above and it gives an error (I translate from italian): "Impossible convert type double in NinjaTrader.NinjaScript.Series<double>"
          So I tried and modified the script this way: "Values[0][0]= Closes[0][0] / Closes[1][0];"
          Now it gives no syntactic error but when I add the indicator to a chart it doesn't plot anything.
          How can I fix this problem? (please find attached the nt8 editor screenshot)
          Thank you very much
          Attached Files

          Comment


            #6
            Hello Gianni78bari,

            Thanks for your post and welcome to the NinjaTrader forums!

            Your example is correct: Values[0][0]= Closes[0][0] / Closes[1][0]; and I will correct mine in post #4.

            If you do not see an output, please check the "log" tab of the control center for any error messages related to the indicator.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_PaulH View Post
              Hello Gianni78bari,

              Thanks for your post and welcome to the NinjaTrader forums!

              Your example is correct: Values[0][0]= Closes[0][0] / Closes[1][0]; and I will correct mine in post #4.

              If you do not see an output, please check the "log" tab of the control center for any error messages related to the indicator.
              Thanks for your answer.
              That's the message I read in the log tab:
              "Indicator 'MyCustomIndicator1': Error on calling 'OnBarUpdate' method on bar -1: 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"

              As I said, for now I can't program, so I would know if there's an easy way to fix it, 'cause it could be useful for other traders too.
              Last edited by Gianni78bari; 09-30-2019, 10:38 AM.

              Comment


                #8
                Hello Gianni78bari,

                Thanks for your reply.

                I replicated the code you posted and do not see an issue.

                Can you provide further information about the chart/instrument that you are applying the indicator to?

                What data feed are you connecting to?
                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_PaulH View Post
                  Hello Gianni78bari,

                  Thanks for your reply.

                  I replicated the code you posted and do not see an issue.

                  Can you provide further information about the chart/instrument that you are applying the indicator to?

                  What data feed are you connecting to?
                  I'm using NinjaTrader Continuum demo. I'm applying the indicator to ES12-19 and the additional data series for comparing is ZN12-19 which is enabled for real time quotes.
                  that's the code in my editor: AddDataSeries("ZN 12-19", Data.BarsPeriodType.Minute, 1, Data.MarketDataType.Last);

                  Thank you for your kind reply

                  Comment


                    #10
                    Hello Gianni78bari,

                    Thanks for your reply.

                    I've attached a screenshot of the code and the chart output for your review. I'll also add a link to the indicator I used so you can download, install and test on your end.

                    Click image for larger version

Name:	Gianni78bari-1.PNG
Views:	1321
Size:	115.8 KB
ID:	1072634

                    [ATTACH]n1072635[/ATTACH]
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_PaulH View Post
                      Hello Gianni78bari,

                      Thanks for your reply.

                      I've attached a screenshot of the code and the chart output for your review. I'll also add a link to the indicator I used so you can download, install and test on your end.

                      Click image for larger version

Name:	Gianni78bari-1.PNG
Views:	1321
Size:	115.8 KB
ID:	1072634

                      [ATTACH]n1072635[/ATTACH]
                      Perfect.
                      I'll let you know.
                      Thank you very much!

                      Comment


                        #12
                        It works.
                        I missed a "return" in the code
                        Thank you again

                        Comment


                          #13
                          It could be possible modify "Net change indicator" in NT8 in order to plot a line starting at zero at the beginning of the trading session? This would be useful also applied to the indicator "Compare" in this thread.
                          Something like that in this video
                          A simple percentage changed indicator for Ninjatrader 8. Quick demo showing how to setup it up and use it (how I use it). You can download it for free, here ...

                          Maybe it has already been coded??
                          Thanks

                          Comment


                            #14
                            Hello Gianni78bari,

                            Thanks for your post.

                            I noticed in the video that the video provider added a link for you to download what they were displaying, if that is what you want.

                            Paul H.NinjaTrader Customer Service

                            Comment


                              #15
                              Originally posted by NinjaTrader_PaulH View Post
                              Hello Gianni78bari,

                              Thanks for your post.

                              I noticed in the video that the video provider added a link for you to download what they were displaying, if that is what you want.
                              Unfortunately the link doesn't work anymore

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GLFX005, Today, 03:23 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post GLFX005
                              by GLFX005
                               
                              Started by XXtrader, Yesterday, 11:30 PM
                              2 responses
                              11 views
                              0 likes
                              Last Post XXtrader  
                              Started by Waxavi, Today, 02:10 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Started by TradeForge, Today, 02:09 AM
                              0 responses
                              11 views
                              0 likes
                              Last Post TradeForge  
                              Started by Waxavi, Today, 02:00 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Waxavi
                              by Waxavi
                               
                              Working...
                              X