Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

New here - How to subtract two Indicators?

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

    New here - How to subtract two Indicators?

    Hi everyone,

    Just installed NJ and loving it.

    I tried to build a simple custom indicator, based on the difference of two RSI (on different length), but I cannot build it using the double function:
    double RS1 = RSI...
    double RS2 = RSI...
    double diff = RS1 - RS2

    I get "Cannot implicitly convert type Ninjatrader.Indicator.RSI to double CS0029.

    I understand I cannot use double to subtract two indicators, but how am I supposed to do?

    Thank you everyone for help

    #2
    Unfortunately this is not supported. You would need to implement a custom indicator which subtracts these values data point by data point and stuffs the result in its own plot/data series.

    Comment


      #3
      Originally posted by NinjaTrader_Dierk View Post
      Unfortunately this is not supported. You would need to implement a custom indicator which subtracts these values data point by data point and stuffs the result in its own plot/data series.
      Thank you NJ_Dierk

      Could you explain (with an example or with a similar indicator) how to do that?
      Otherwise I don't think I will manage to move forward...

      Comment


        #4
        I suggest ripping through our indicator code samples and the references and tips here:

        Comment


          #5
          Following the tutorials:

          1) I introduced the variables:
          #region Variables

          private DataTimeSeries RSI1;
          DataTimeSeries RSI2;

          #endregion

          2) I declared the variables:

          RSI1.Set(RSI(...));
          RSI2.Set(RSI(...));
          RSI1 = new DateTimeSeries(this);
          RSI2 = new DateTimeSeries(this);

          double diff = RSI1 - RSI2;


          Yet, it doesn't work!

          Who can help me with an example?

          Thank you everyone

          Comment


            #6
            Please import the attached via Files > Utilities and review the source code.
            Attached Files
            RayNinjaTrader Customer Service

            Comment


              #7
              Thank you, Ray, but it doesn't work yet!
              #region Variables
              private DataSeries mySeries1;
              DataSeries mySeries2;
              #endregion

              mySeries1 = new DataSeries(this);
              mySeries2 = new DataSeries(this);

              protected override void OnBarUpdate()
              {
              double myValue1 = RSI(Close, x, y);
              double myValue2 = RSI(Close, x, z);
              mySeries1.Set(myValue1);
              mySeries2.Set(myValue2);
              double Diff = myValue1 - myValue2;
              Plot0.Set(Diff);
              }


              Please anyone can tell me what's wrong? I'm spending sooooooo much time on it, I'm getting desperate!

              Comment


                #8
                Try this:

                protected override void OnBarUpdate()
                {
                double myValue1 = RSI(Close, x, y)[0];
                double myValue2 = RSI(Close, x, z)[0];
                mySeries1.Set(myValue1);
                mySeries2.Set(myValue2);
                double Diff = myValue1 - myValue2;
                Plot0.Set(Diff);
                }

                however, what you are doing is redundant, I would do this and skip using any DataSeries object:

                protected override void OnBarUpdate()
                {
                Plot0.Set(RSI(Close, x, y)[0] - RSI(Close, x, z)[0]);
                }
                RayNinjaTrader Customer Service

                Comment


                  #9
                  I finally generated the indicator (using the latter expression you suggested), but I get a 0 flat line as indicator. Why?

                  Thank you

                  Comment


                    #10
                    Since the value of the calculation is likely zero. You will need to debug it.

                    Here is some guidance - http://www.ninjatrader-support.com/v...ead.php?t=3418
                    RayNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by kujista, Today, 06:23 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post kujista
                    by kujista
                     
                    Started by traderqz, Yesterday, 04:32 PM
                    1 response
                    11 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by f.saeidi, Today, 05:56 AM
                    1 response
                    4 views
                    0 likes
                    Last Post Jltarrau  
                    Started by Jltarrau, Today, 05:57 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post Jltarrau  
                    Started by Stanfillirenfro, Yesterday, 09:19 AM
                    7 responses
                    53 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Working...
                    X