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

CHange of RSI calculation

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

    CHange of RSI calculation

    Hi,

    I'm trying to code the below logic from ThinkorSwim in Ninja trader. It calculates the change of RSI from current bar to previous bar,
    c1 means current bar, c1[1] means previous bar, n is RSI period length

    def c1 = close(period= myTrendperiod);

    def NetChgAvg1 = ExpAverage(c1 - c1[1], n);

    def TotChgAvg1 = ExpAverage(AbsValue(c1 - c1[1]), n);

    def ChgRatio1 = if TotChgAvg1 != 0

    then NetChgAvg1 / TotChgAvg1

    else 0;

    rec RSI1 = 50 * (ChgRatio1 + 1);


    However, I do not see the same result in Ninja.
    Wondering if the calculations got to be different for getting the same result. The reason is that in TradeStation I had to use the below formula for RSI
    netChange in TS = (X-Xn)/n for getting the same result.

    Appreciate any feedback

    #2
    Hi ark, thanks for posting.

    We have an RateOfChange utility and you can pass the RSI series into this e.g.

    Print(ROC(RSI(14, 3), 2)[0]); //gives a rate of change of 2 periods.

    To know where the difference between the two codes you would need to add prints to each line of the think script to find the difference.

    Kind regards,
    -ChrisL

    Chris L.NinjaTrader Customer Service

    Comment


      #3
      I'm little confused on how to use this for the above logic if c1 is 60 min bar close price and n is 14.
      Appreciate if you can help

      Comment


        #4
        Hi ark,

        The code I showed previously can run on any bar type and bar period. So to run this code on a 60 minute chart, simply apply this code to a 60 minute chart. "n" is the period, so there are two periods being used, one for the ROC (2) and the other for the RSI (14).




        Kind regards,
        -ChrisL
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          the challenge I've is that I need to refer RSI value on 60 min chart on a 5 min chart. So, is there a way to pass 60 min time period?

          Comment


            #6
            Hi Ark, thanks for your reply.

            You will need to add the 60 minute time series with AddDataSeries() and pass the BarsArray to RSI. I attached an example for reference.

            Kind regards.

            Attached Files
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              This is great. Thanks a lot for the reference code.

              Comment


                #8
                I've been trying this but having some issues.. I was able to produce 60 min RSI trend on lower time frame chart (in this example 5 min) using the sample code that you provided. However, the graph looks different and the values look different and still can't match the RSI graph in thinkorswim. Appreciate if you can take a look at this indicator code [lines 360-380 ]. Attached is the screen shot of the difference. Thanks for your help
                Attached Files

                Comment


                  #9
                  Hi ark321 , thanks for your reply.

                  Unfortunately, I have no experience using think script. You will need to print out each line in the TOS script to see what values it is producing.

                  Kind regards,
                  -ChrisL
                  Chris L.NinjaTrader Customer Service

                  Comment


                    #10
                    Is the updated code for calculating ROC for 60 RSI (as per your example) looks correct?

                    Comment


                      #11
                      HI ark321,

                      The most recent code is just showing how to set up a 60 minute time series and applying an RSI to it. To take the ROC you need to use the RSI60 object as the input series for ROC e.g.

                      Print(ROC(RSI60, 2)[0]);





                      Chris L.NinjaTrader Customer Service

                      Comment


                        #12
                        any idea where can i see the log for backtesting results? It doesnt show the log messages in Documents\NinjaTrader 8\log

                        Comment


                          #13
                          Let me clarify - I've kept Print("test") message inside the strategy and wondering if i can see those messages when I run the back test

                          Comment


                            #14
                            Hi ark,

                            The Print method outputs to the Control Center>New>NinjaScript output window. Use Log() method if you want to log some event from the strategy. We recommend using Prints for things that do not need to be saved for later sessions like script debugging.




                            Kind regards,
                            -ChrisL
                            Chris L.NinjaTrader Customer Service

                            Comment


                              #15
                              thanks.. That helps

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cre8able, Yesterday, 04:22 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by stafe, 04-15-2024, 08:34 PM
                              5 responses
                              28 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by StrongLikeBull, Yesterday, 04:05 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by Mestor, 03-10-2023, 01:50 AM
                              14 responses
                              375 views
                              0 likes
                              Last Post z.franck  
                              Started by molecool, 10-09-2017, 10:48 AM
                              5 responses
                              1,621 views
                              0 likes
                              Last Post trader-ap  
                              Working...
                              X