Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi-Timeframe use in a Strategy

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

    Multi-Timeframe use in a Strategy

    Hi all,

    Please be easy on me this is only my second strategy. The first was much easier and very easy to program using the Strategy Anlayzer. Here goes;

    I have an indicator that when a signal is received on the 30 minute bar you enter a trade. That works fine in the Analyzer. Now what I'd like to do is add another condition that when the 30 minute signal is received, the same indicator is run on the 2 minute chart of the same instrument and if I get a signal on that as well then I enter the trade. Long timeframe projects general direction and short timeframe the entry.

    Is there a way to do this in the Strategy Analyzer? I think it has to do with "Input Series" but I cannot find a way to add an additional input series.

    thx in advance for the help,

    Fred





    #2
    imported post

    Sorry, this is not supported right now. Indicators (e.g. on market analyzer columns) only support one timeframe.

    Comment


      #3
      imported post

      Dierk,

      If it is not supported then what is the "Multi-Time Frame & Instruments" in the help section for NT6? It states "A NinjaScript strategy supports multi-time frame and instruments in a single strategy." Is that only if you write it in a strategy but cannot be done in the Strategy Analyzer unless youapply the written strategy as part of the conditions in the Strategy Analyzer?

      Corrrect me if I'm wrong here as I'm pretty green on this programming but it looks like you can use multi timeframes and more than one instrument in a strategy. Is that correct?

      But what you are telling me is that it can't be done or run in the Analyzer?

      Still quite confused.

      Freddie




      Comment


        #4
        imported post

        Oops, my apologies. My comment was about market analyzer.

        Yes, multi timeframes and multi instruments on a strategy are supported in strategy analyzer.

        Does the sample provided in the docs make sense to you?

        Comment


          #5
          imported post

          The sample in the docs does make sense I think. You need to somehow define a second data series if I recall. Not sure how to do that in the Analyzer?

          Do you understand clearly what I'm trying to do? I'll try to explain again:

          I currently have strategy setup using an indicator (call itMyIndicator)on 30 minute bars and the strategy runs correctly and the results look correct. Now what I'd like to do is add to the strategy another condition that "MyIndicator" must also have a buy signal on the 2 minute bars of the same instrument used for the 30 minute signal. So basically, I want the longer timeframe (30 min) to signal a buy and have it confirmed by the shorter timeframe (2min) using the same indicator on both the 30 and 2 minute bars of the same instrument.

          I hope this is clear. At this point I'm not sure how I need to do this. Do I need somehow to define a second data series in the indicator or do I somehow define itbyeditingthe existing strategy?

          Thx,












          Comment


            #6
            imported post

            Please check out again the docs. The sample shows you
            - how to add addtional series with a different timeframe to your strategy
            - how to run indicators in your strategy on these different series

            This is exactely what you need to do: http://www.ninjatrader-support.com/H...struments.html

            Comment


              #7
              imported post

              Dierk,

              I read the article and put in the Add statement and then I've tried numerous ways to get it to work and can't. Maybe you can help. Basically I want to repeat the "If" statement again but to be run on the second data series which in this case is the 5 minute dataseries that I added in the intialize. EdsPivotSMA is an indicator that I wrote that plots 2 lines, LongSMA and Short SMA. LongMAPeriods and ShortMAPeriods are variables that I can change to optimize the indicator.

              Hopefully, you can provide me some ideas of what to try. Thanks,

              Here's the code:

              protectedoverridevoid Initialize()

              {

              SetTrailStop(
              "", CalculationMode.Ticks, TrailingStop, false);

              Add(PeriodType.Minute,
              5);

              CalculateOnBarClose =
              false;

              }

              ///<summary>

              /// Called on each bar update event (incoming tick)

              ///</summary>

              protectedoverridevoid OnBarUpdate()

              {

              // Condition set 1

              if (Close[0] > EdsPivotSMA(LongMAPeriods, ShortMAPeriods).LongSMA[0] && Close[0] > EdsPivotSMA(LongMAPeriods, ShortMAPeriods).ShortSMA[0]&& EdsPivotSMA(LongMAPeriods, ShortMAPeriods).ShortSMA[0] > EdsPivotSMA(LongMAPeriods, ShortMAPeriods).LongSMA[0])



              // Want to add the next conditons, similar to above if statement but applied to 5 minute bar

              // (ie. BarsArray[1]) rather than to the default data series.















              {

              EnterLongLimit(DefaultQuantity, Close[
              0], "Buy Long");

              ExitShortLimit(Close[
              0], "Cover Short", "");

              Comment


                #8
                imported post

                As the article suggests with it's sample
                Code:
                CCI(BarsArray[1], 20)[0]
                you need to run your indicator on the secondary series like
                Code:
                EdsPivotSMA(BarsArray[1], LongMAPeriods, ShortMAPeriods).LongSMA[0]
                BarsArray[0] = primary series (default)
                BarsArray[1] = secondary series added in Initialize

                Please let us know what you wanted to see clarified in the docs.

                Thanks

                Comment


                  #9
                  imported post

                  Thx Dierk,

                  I'll give it a try. I was using EdsPivotSMA((BarsArray[1], LongMAPeriods), (BarsArray[1],ShortMAPeriods)).LongSMA[0] as I was not sure how to exactly add the BarsArray expression.




                  Comment


                    #10
                    imported post

                    Great. We'll try to clarify in the docs.

                    Comment


                      #11
                      imported post

                      That seemed to work ok for me but got another question on a slightly different topic but for the same strategy. I've set up the strategy to only calculate on close. From my results it appears that the strategy is only calculating when the default input series (which in my case is the 30 minute data series) rather than on both the 30 minute and shorter data series of 5 minutes. What is happening is it is only picking up signals when both the long signal and short signal are both given on the 30 minute close. Ideally I'd like to have the 30 minute signal checked (say at 10 am) and then if the 5 minute bar closes with a buy signal at 10:10am that I would buy then.

                      To have this happen would I need to change the default data series to the shorter one or do I need to somehow trigger a variable in the strategy to keep track of the long signals from each of the longer and shorter timeframes?

                      Thx for all your help Dierk. BTW where is Bamburg? My brother-in-law works in Cologne (Koln) and we visited there 2 years ago. Nice city.




                      Comment


                        #12
                        imported post

                        OnBarUpdate is triggered for each series where a bar closes (if CalculateOnBarClose=true) in your case on every bar of the 30min and on every bar of the 5 min series.

                        Please confirm by:
                        Code:
                        Print(BarsInProgress.ToString() + "  " + Time[0]);
                        which prints the timestamp of every closed bar.

                        Comment


                          #13
                          imported post

                          Yes you would need to make the 5 min series the primary series if that is the time frame you need to execute orders against. You can check values of the larger time frame within the context of the primary series.

                          Bamberg is several hours SE of Koln.

                          Ray


                          RayNinjaTrader Customer Service

                          Comment


                            #14
                            imported post

                            First, I'm getting this message when I run the analyzer:

                            "Order for strategy '----' was placed in incorrect 'BarsinProgress' context. Order ignored.



                            Second, I added the print line you requested at the top of the OnBarUpdae section of the strategy. It shows 2 timestamps for every 5 minutes and 4 timestamps on the 1/2 hour. Not sure why 4 on the 1/2 hour; shouldn't it still be just 2?

                            Ray,

                            So if I understand you correctly, if I'm executing off of the 5 minutes signal, which is my case, then that should be the primary series and the 30 minute should be the secondary series. So just got to flip all the program around then.



                            Fred

                            Comment


                              #15
                              imported post

                              1 other thing on the timestamps that I just noticed:

                              On the 4 that occur each 1/2 hour, the first item in the line on 2 of them is a 1, and the first item in the line of 2 of them is a 0. If this helps at all.


                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by proptrade13, Today, 11:06 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post proptrade13  
                              Started by kulwinder73, Today, 10:31 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by RookieTrader, Today, 09:37 AM
                              3 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by terofs, Yesterday, 04:18 PM
                              1 response
                              24 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by CommonWhale, Today, 09:55 AM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Working...
                              X