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

Using indicator on my own DataSeries does not work as it should

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

    Using indicator on my own DataSeries does not work as it should

    I am trying to paint a daily RSI on a fifteen minute chart with the daily RSI calculated with the current close so far also included.

    I tried to do this by copying the daily closing bars to my own DataSeries with DataSeries[1] = yesterdays Close DataSeries[2]=close before yesterday's etc and then make DataSeries [0] equal to the current close. I then used RSI() on my DataSeries.

    Here is some code to illustrate the problem that I ran into. It just copies the daily closes to another DataSeries and then uses RSI on that DataSeries.

    Code:
    for(int i=0;i<255;i++)
    {
    // BarsArray[1] contains the daily bars
    DailyClosesWithIncomplete.Set(i,BarsArray[1][i]);
    
    // These print statements verify that both contain the same values as they are supposed
    // to do				
    Print("BarsArray[1]["+i+"]=" + BarsArray[1][i]);
    Print("DailyClosesWithIncomplete["+i+"]=" + DailyClosesWithIncomplete[i]);
    }
    
    //Plot0.Set(RSI(BarsArray[1],14,3)[0]);
    Plot0.Set(RSI(DailyClosesWithIncomplete,14,3)[0]);
    Now if I plot the RSI of DailyClosesWithIncomplete and the RSI of BarsArray[1], they should look the same, right? (They both contain exactly the same values)

    That was not the case, here are the screenshots:



    RSI of BarsArray[1]




    RSI of DailyClosesWithIncomplete


    So, what gives? Is there another way of doing what I am trying to accomplish which avoids this problem?
    Last edited by nsbz1; 05-10-2012, 08:13 AM.

    #2
    Hello,

    Thanks for the forum post and welcome to the NinjaTrader forums.

    Are you doing BarsInProgress filtering? As OnBarUpdate() is called for both series.

    Bars In progress filtering: http://www.ninjatrader.com/support/h...nstruments.htm

    What is you just print RSI(rsiValue)[0]; with BarsInProgress filtering.

    if (BarsInProgress == 1)
    {
    //Calculate on the secondary daily series

    Plot0.Set(RSI(rsiValue)[0]);
    }

    That should do the trick. You can then use Plot0 in your calculations in the primary if needed.

    Comment


      #3
      Thanks for the fast reply.

      I have this line at the beginning of OnBarUpdate():

      Code:
      if (BarsInProgress != 0 || CurrentBars[0] < BarsRequired || CurrentBars[1] < BarsRequired ) return;
      I want the daily RSI calculated on every bar of the 15min series so I do think that line is as it is supposed to be. I do not want to do any calculations when the secondary data series is updated.

      Comment


        #4
        Now, I am thinking maybe the Ninjatrader RSI indicator does not take into account that the previous bar values of the DataSeries have changed and therefore the RSI must be calculated entirely from beginning of the dataseries at each new bar. Could that be the problem?

        Tradestation/Multicharts does this to save some clockcycles, that is, the indicators are not calculated from the beginning of the time series at each new bar, they are just "updated". But then, easylanguage does not allow changes to the TimeSeries (the equivalent of ninjatrader DataSeries) of the previous bars. What were the programmers of ninjalanguage thinking when they allowed changes of the indicator values of previous bars? What were they expecting it to be used for?
        Last edited by nsbz1; 05-10-2012, 09:05 AM.

        Comment


          #5
          Thanks for that.

          In that case you should be ok there then.

          If you have run though and tried to troubleshoot the coding error with Print statements with the following guide already I would need you to post your code and although we do not debug code I can take a quick look to see if I can help you out.



          -Brett

          Comment


            #6
            Here is the source code.
            Attached Files

            Comment


              #7
              Thanks for posting that.

              I believe I have isolate what you are missing.

              You are using a data series which has an array size of the primary input. You need a data series that is tied to the secondary bar object. This is known as syncing the data series object. Currently you have it synced to the primary bars, we needed it synced to the secondary bars.

              Please see this sample on how to do this:

              Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series&lt;T&gt; (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for


              -Brett

              Comment


                #8
                When I synch it to BarsArray[1] it does plot it the same as in the RSI of BarsArray[1] screenshot.

                But it does not work when I try to do what I originally intended to do.

                I think the RSI should be synched to the 15 min chart not the 1 day chart because it recalculates every 15min. Now RSI ignores changes to the final value in the DataSeries except when a new 1 day bar arrives.

                So the question is, how do I get Ninjatrader to recognize that the DataSeries has changed and it needs to recalculate the indicator?

                Comment


                  #9
                  you cannot take an RSI value from a daily period and sync it to an intra day period. If you just want the 15 minute RSI value then no need to add in the secondary daily series?

                  You have to pick one or the other you cannot combine them to have both.

                  -Brett

                  Comment


                    #10
                    I want to calculate an RSI that consists of the current intraday price, yesterday's daily close, day before yesterday's daily close etc etc.

                    I only have daily bars so I can get the daily closes from it.

                    So why should I not able to do that? It should be a piece of cake to do but this bug makes it hard.
                    Last edited by nsbz1; 05-10-2012, 01:13 PM.

                    Comment


                      #11
                      Ok, so you want the following:

                      2 Day ago : RSI VALUE
                      1 Day ago: RSI VALUE
                      Current Day: RSI VALUE (Updates over and over during the day until the bar fully closes at end of day)

                      In this case you just need the daily series and setting calculate on bar close to false.

                      Once you set calculate on bar close setting to false this will update the current price in the indicator and not wait for the bar to close. No special programming needed.


                      -Brett

                      Comment


                        #12
                        True, but that doesnt work in backtest according to documentation.

                        Is there a way to backtest using only 1 day bars with fill price as the close of the bar?
                        Last edited by nsbz1; 05-10-2012, 02:12 PM.

                        Comment


                          #13
                          correct does not work in back testing with NinjaTrader. Backtesting is calculate on bar close = true only.

                          Yes you can add in a secondary series for more granularity, but this is a completely separate series. Not one that you can merge into the primary to simulate Calculate On Bar Close = false.

                          The closest you can get to filling at the close of the bar in NinjaTrader is to add a 1 tick secondary series and close on the first tick of the next series. However this comes at a great cost to backtesting time and resources due to tick data coming in.

                          NinjaTrader uses a more conservative approach we believe positions should open on the open of the next bat.

                          -Brett

                          Comment


                            #14
                            I figured out a workaround. The trick is to create a new instance of the DataSeries for each primary bar. That way, the indicator cannot cheat on the calculations since it hasn't seen that instance of the DataSeries before.

                            This is a bad way of doing things, it takes a while to apply the indicator to the chart. It would be a lot better if the bug was fixed.

                            Here is the relevant code:
                            Code:
                            			
                            DailyClosesWithIncomplete= new   DataSeries(this,MaximumBarsLookBack.TwoHundredFiftySix);
                            				for(int i=0;i<254;i++)
                            				{
                            				// copy daily closes to my DataSeries
                            				DailyClosesWithIncomplete.Set(i+1,BarsArray[1][i]);
                            				
                            				}		
                            		        // put current intraday close as last value
                            			DailyClosesWithIncomplete.Set(BarsArray[0][0]);
                            		        
                            			DailyRSIWithIncomplete.Set(RSI(DailyClosesWithIncomplete,14,3)[0]);

                            Comment


                              #15
                              Thanks for the workaround.

                              This is the general idea of what you would need to do to do this. You are correct it uses a lot of extra resources and this is why NinjaTrader does not do this.

                              -Brett

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by GussJ, 03-04-2020, 03:11 PM
                              13 responses
                              3,244 views
                              0 likes
                              Last Post GussJ
                              by GussJ
                               
                              Started by lorem, Today, 09:18 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post lorem
                              by lorem
                               
                              Started by hazylizard, Today, 08:38 AM
                              4 responses
                              11 views
                              0 likes
                              Last Post hazylizard  
                              Started by geddyisodin, Today, 05:20 AM
                              2 responses
                              20 views
                              0 likes
                              Last Post geddyisodin  
                              Started by Max238, Today, 01:28 AM
                              5 responses
                              47 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Working...
                              X