Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

multi timeframes, instruments

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

    multi timeframes, instruments

    have addded the sample codes for adding a 3min chart and a i min AAPL chart, but the charts are not added when backtesting, whats missing?:

    protected override void Initialize()
    {
    Add(PeriodType.Minute, 3);
    Add("AAPL", PeriodType.Minute, 1);

    Add(RSI(4, 0));
    Add(RSI(9, 0));
    Add(EMA(21));
    Add(EMA(55));
    Add(EMA(200));
    Add(ATR(14));

    CalculateOnBarClose = true;
    }

    #2
    Hello sosMsos,

    Thank you for your post.

    When backtesting, the chart shown will always be the parent one the backtest is ran on. This will be the Type and value specified in the backtest options - for example Minute, 1. The strategy will have internal access to the second instrument added but it is not reflected on a seperate chart.

    For information on working with the data of added instruments and timeframes please see the following helpguide article: http://www.ninjatrader.com/support/h...nstruments.htm

    If you are trying to plot strategy values on the chart, the following example shows how to perform this:
    When running a strategy on a chart you may find the need to plot values onto a chart. If these values are internal strategy calculations that are difficult to migrate to an indicator, you can use the following technique to achieve a plot. NinjaTrader 8 With NinjaTrader 8 we introduced strategy plots which provide the ability


    Please let me know if I can assist any further.
    DexterNinjaTrader Customer Service

    Comment


      #3
      somehow i cant get it to work, need some assistance.

      Example:
      underlying instrument is SPY

      if nyse tick crossbelow -600 on the 1 min chart, enter long.


      How would i do that?
      -----------------------------------------------------


      I started with, for sure thats wrong i guess:

      Add("^TICK", PeriodType.Minute, 1);
      .....
      if (BarsArray[1] < -600))
      {
      EnterLong(DefaultQuantity, "");
      }

      Comment


        #4
        Hi sosMsos,

        You are on the right track checking BarsArray[1] as this will hold your ^TICK data, but there is an more straightforward way to check it by passing it to CrossBelow(). Try this:

        if(CrossBelow(BarsArray[1], -600, 1))
        {
        // do whatever
        }

        For more information on using CrossBelow, BarsArray and multiple timeframes /instruments please see the following help guide articles:



        DexterNinjaTrader Customer Service

        Comment


          #5
          Thanks Dexter seem to work though i am not able to see the Tick chart.

          Next, i d like to combine this condition (tick below-600) with an indicator conditon during the next 20 bars, somehow i made a mistake, no trades anymore.

          idea:
          if Tick below -600 and RSI9 <=30 during the next 20 bars then get long

          ->Please check the code:

          if (CountIf(delegate {return (CrossBelow(BarsArray[1], -600, 1));}, 20) >0
          && CountIf(delegate {return (RSI(9, 0).Avg[0] <= 30);}, 20) >0)
          {
          EnterLong(DefaultQuantity, "");
          }

          Comment


            #6
            Hi sosMsos,

            Additional instruments added with Add() will not be visible or selectable in a chart, the data is just able to be referenced from the strategy code.

            You will need to make sure you have 20 bars of data on your chart first. You can do this by checking CurrentBar > 20. Here is a sample on how to make sure you have enough bars:


            Try that out and let me know if I can assist any further.
            DexterNinjaTrader Customer Service

            Comment


              #7
              THanks.

              I have chartdata 10 years back, donno what you mean.

              Onother thing is, i get fills on the second instrument (Tick) and the underlying (SPY)
              for a whopping 2 trillion cumulative profit and a 55:1 profit factor over the last year.

              Why does NT enters long on both, i mean the Tick should just be an indicator,
              Last edited by sosMsos; 04-27-2011, 02:26 PM.

              Comment


                #8
                Hi sosMsos,

                EnterLong() will submit to whatever the current BarsInProgress is equal to. If you want to narrow it down to only buy the underlying instrument, make sure you're on BarsInProgress 0:

                if (BarsInProgress == 0)
                EnterLong(DefaultQuantity, "long signal");

                This will prevent EnterLong() from buying your second added instrument, ^TICK.

                For more information on using BarsInProgress please see this helpguide article: http://www.ninjatrader.com/support/h...inprogress.htm

                Give this a try and let me know if I can assist you any further.
                DexterNinjaTrader Customer Service

                Comment


                  #9
                  if market gaps up on the daily chart do something on the 1 min chart
                  -> is this the right expression, does not work.

                  if (Open[0] > (BarsArray High[1]))

                  donno how and where to implement barsarray into the code.

                  Comment


                    #10
                    Hello again sosMsos,

                    You can use Highs, Lows, Closes, Opens arrays to achieve this.
                    For example:

                    if(Close[0] < Closes[1][1])

                    That would compare the close of the most current bar on the primary data series to the close of the secondary data series 1 bar ago.

                    Use of Highs, Lows, Closes, Opens is covered in the following helpguide article: http://www.ninjatrader.com/support/h...nstruments.htm , Please see the 'Accessing the Price Data in a Multi-Bars NinjaScript' section.
                    DexterNinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_Dexter View Post

                      if(Close[0] < Closes[1][1])
                      section
                      That just seem to count back two bars, i need a comparisson between the bars ranges of the smaller and the larger timeframe.

                      I tried this, but i dont know where to put the barsarray command:
                      if (Open[0] > High (BarsArray[1]))

                      -> if current bar (1min) opens higher than the high of the 2nd timeframe (daily bar) then ...

                      Comment


                        #12
                        Hi sosMsos,

                        Close[0] and Closes[1][0] are two different things, Closes[1] refers to the second data series / timeframe added, in your case this would be day bars.

                        If you would like a framework to start from, please see the SampleMultiTimeFrame strategy that comes with NinjaTrader. You can view the source to it by opening it with Tools->Edit NinjaScript->Strategy and select SampleMultiTimeFrame.

                        This sample shows how to compare data from multiple time frames for the same instrument so it may be a good jumping off point.
                        DexterNinjaTrader Customer Service

                        Comment


                          #13
                          Thanks Dexter!
                          Another not working code. Please have a look:

                          Condition: if daily chart is in an uptrend ( The ema conditions) do something on the 1 min chart.

                          protected override void Initialize()
                          {
                          Add(PeriodType.Day, 1);


                          CalculateOnBarClose = true;
                          }


                          protected override void OnBarUpdate()
                          {
                          // Condition set 1
                          if (EMA(BarsArray[1], 21)[0] > EMA(BarsArray[1], 55)[0] <- feel te syntax is wrong
                          && EMA(BarsArray[1], 55)[0] > EMA(BarsArray[1], 200)[0]
                          && EMA(BarsArray[1], 55)[0] > EMA(BarsArray[1], 55)[1]
                          && EMA(BarsArray[1], 200)[0] > EMA(BarsArray[1], 200)[1])


                          // if (BarsInProgress == 0) <- donno if i need this
                          EnterLong(DefaultQuantity, "");
                          Last edited by sosMsos; 04-28-2011, 01:00 PM.

                          Comment


                            #14
                            Hello sosMsos,

                            Thank you for your reply.

                            EMA()[0] is correct, you can simplify your code by putting all the EMAs in a BarsInProgress == 2 check. When you do this, you do not have to specify BarsArray[1]. Then you can specify EnterLong to buy the primary series with an overload:

                            e.g.:
                            if ( BarsInProgress == 1)
                            {
                            if (EMA(21)[0] > EMA(55)[0] && EMA(55)[0] > EMA(200)[0]
                            && EMA(55)[0] > EMA(55)[1] && EMA(200)[0] > EMA(200)[1])
                            {
                            EnterLong(0, DefaultQuantity, "");
                            }
                            }

                            Note the different EnterLong(), the 0 specifies to buy the Primary data series. This is similiar to putting EnterLong in if (BarsInProgress == 0) but easier to work with when you're already in another BarsInProgress.

                            For more information on EnterLong()'s overloads please see the following helpguide article:
                            DexterNinjaTrader Customer Service

                            Comment


                              #15
                              Thanks for your patience, but the deeper i get into this the more overwhelming it gets.

                              i wanted the EMA conditions on the daly chart to be a master condition that must be fulfilled befor anything else happens on smaller timeframes.

                              You recommended to bracket the EMA conditions under BarsinProgress==1 ,
                              But now when i want to add conditions that refer to the actual timeframe this syntax seems not to work, like i did here:


                              if ( BarsInProgress == 1)
                              if (EMA(21)[0] > EMA(55)[0] && EMA(55)[0] > EMA(200)[0]
                              && EMA(55)[0] > EMA(55)[1] && EMA(200)[0] > EMA(200)[1])

                              if ( BarsInProgress == 0)
                              if (CountIf(delegate {return (CrossAbove(RSI(9, 0).Avg, 30, 1));}, 5) >0)
                              if (CountIf(delegate {return (CrossAbove(RSI(4, 0).Avg, 70, 1));}, 5) >0)

                              {
                              EnterLong(0,DefaultQuantity, "");

                              }
                              Last edited by sosMsos; 04-28-2011, 02:42 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              666 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              376 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              110 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              575 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              580 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X