Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicators in different time scale

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

    Indicators in different time scale

    Hi,

    I have historical data minute by minute of some companies. In the strategy i'm creating I need some indicator values (for e.g. EMA) but in days instead of minutes.

    To clarify:

    I know that OnBarUpdate is called, in my case, for each minute and if I call EMA(High, 3)[1], I'll get the ema value (based on 3 minutes) of the previous minute.

    But I want the EMA value based on three days ago (not EMA(High, 3*60)[1]), like a function called Day_EMA(High, 3)[1]

    I imagine can simulate this with a custom array by evaluating SessionBreak value and, if it is false, temporary store the high value of the current day, if it is true, storing the value in the array, and at last, making an average of the three last values in that array.

    So I'm asking if NT has an implementation of this or I must make my own routines.

    ---------

    By the way, another question. Dataseries objects "syncs" the values bar by bar. If I do not set the value of any bar, NT help says that it will contain a dummy value.

    Can I change this behavior? For e.g., can I create a custom class derived from Dataseries and its IDataseries in order to modify this so I can use it with standards indicators that NT has?

    Best regards,
    Mauro.

    #2
    Mauro,

    You will want to add a second bars object for your strategy. Please see this article: http://www.ninjatrader-support.com/H...ameInstruments

    Then you can access EMA of the daily bars.

    DataSeries does indeed sync bar by bar. If you don't set a value you will have a dummy value of the close of the bar.

    I am not sure what you mean by modifying it. What are you hoping to achieve? You can just run your own arrays if you want to go about having some sort of collection yourself.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Hi Josh,

      Thank you for your answer. The page you give about multi-time frame and instruments makes some clarifications and I think that it will help, but I have some doubts (assuming that CalculateOnBarClose is true because I'm using the simulation module):

      1) Why are the first 2 "1-min bars" in blank? They aren't taken into account for calculating the "3-min bar"?

      2) In which order are bars updated? The primary bar first and then the added ones?

      So, for my example code I will need to add Add(PeriodType.Day, 1); to it and then check when BarsInProgress is 0 in OnBarUpdate.

      And the question is: In order to access the close value of the previous day, I need to retrieve the value of Closes[1][1] or Closes[1][0]? and when... after 390 (minutes in a market day) calls to OnBarUpdate?

      Regards, Mauro.

      Comment


        #4
        1. Not sure what you mean by "blank". I suggest you just create yourself a multi-time frame strategy and then in OnBarUpdate() just print the timestamp of each bar along with the BarsInProgress context to get an understanding of how it all fits together.

        2. Yes. Again, best to understand it simply by printing.
        Print(BarsInProgress + " " + Time[0]);

        Closes[1][0] would give you the latest close. This latest close would probably be the close of the previous day. You can decide for yourself after you see the relationship of how bars are added.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Excuse me, the "blanks" i mean the bars painted in white in the page explaining multi-time.

          Comment


            #6
            Hello,

            Are you referring to this link:
            http://www.ninjatrader-support.com/H...helpguide.html

            If so, the white bars are just there for visualization. The example works without them. Compare the real-time verses the historical example and it might make sense.

            I'm kind of jumping in here trying to help, sorry if it is not useful.
            DenNinjaTrader Customer Service

            Comment


              #7
              Hi Ben,

              Yes, the link Josh put above. Going into details:

              a) I have historic data, minute by minute of a company and want to test my strategy on it.

              b) Because I also need "daily" data, I add "Add(PeriodType.Day, 1);" to the Initialize function.

              Well, I have some doubts (including some internal functionallity of NT).

              Suppose backtest simulation starts running, Initialize is called...

              ... at this point, think that the 2 bars dataseries at this point are "empty" (no historic data yet so for e.h. Close[1] and Close[0] will give me some weird value or an exception)

              Then OnBarUpdate is called for the first time. My doubts are the following...

              1) I have 2 bars but BarsInProgress is equal to 0 or 1?

              2) If BarsInProgress is 0 (updating minute-by-minute bar) then accesing data of the second bar is valid? (Closes[1][0]) Because I believe that day-by-day bar is not updated yet.

              3) How are the bars in sync? Let me explain. Imagine that the OnBarUpdate is being called (point "a") for the last minute of a day, Opens[1][0] should have the value of the Open value of the current day... then OnBarUpdate is called for the first minute of the following day (point "b") : At this time Opens[1][0] should have the Open value of the new day, but my doubt arises because if day-by-day bar is not updated between calls "a" and "b", at point "b" we have that Opens[1][0] has the Open value of the previous day... no the current one.

              ------

              For the other side, if the all Bars history are updated before each call to OnBarUpdate, sync is maintained independently if OnBarUpdate is called with BarsInProgress = 0 or 1 first and all the questions above no need to be answered because sync is ok.

              Thanks, Mauro.

              Comment


                #8
                Mauro, first of all please make sure to make sure to call the added series in the proper sequence, i.e. the second or ADDed series should be smaller than the primary one as per this reference sample - http://www.ninjatrader-support2.com/...ead.php?t=6652

                Then in a backtest all OnBarUpdate() calls are done at the bar close, as the intrabar tick formation is known only in realtime.

                To assure proper synching of the bars at the start, you can work with the MinBarsRequired setting in the strategy - http://www.ninjatrader-support.com/H...Required1.html
                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by szferi, Today, 02:04 AM
                0 responses
                1 view
                0 likes
                Last Post szferi
                by szferi
                 
                Started by MidenThur, Today, 12:52 AM
                0 responses
                5 views
                0 likes
                Last Post MidenThur  
                Started by seseoraf, Today, 12:51 AM
                1 response
                6 views
                0 likes
                Last Post charmingishagarg  
                Started by Rosario, Today, 12:50 AM
                0 responses
                3 views
                0 likes
                Last Post Rosario
                by Rosario
                 
                Started by kemoyums, Today, 12:38 AM
                0 responses
                2 views
                0 likes
                Last Post kemoyums  
                Working...
                X