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

Reference Daily Chart

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

    Reference Daily Chart

    Hi,

    The following code looks at the value of the 8 perion SMA and checks to see if it's greater than the 21 period MA on any chart which it's running on

    SMA(Close,8)[0] >= SMA(Close, 21)[0]

    My question is this...How do i check the exact same condition from a longer term time frame. For example suppose this was running on the 1 Min chart how would i check this condition is true on the 60 Min chart?

    Thanks
    Ryebank

    #2
    Ryebank, you would need to Add() the other series needed in Initialize() and then refer to it in your conditions via BarsArray, the correct BarsInProgress context or even Opens, Closes, Highs or Lows.

    The concept is outlined here - http://www.ninjatrader.com/support/h...nstruments.htm

    For a working sample using it, please see our SampleMultiTimeFrame installed per default with NT.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Thanks for the info. I've had a look at the documentation and the simple MTF strategy and i have some questions

      i've added a time frame of 'day' is that possible for adding daily bar data? if so does 15 give me fifteen days worth of data, which i can address? do i need to add(sma(5)) and add(sma(50)) so the daily chart can use them?

      protected override void Initialize()
      {
      //Adding multiple time fram data
      Add(PeriodType.Day, 15);
      }


      protected override void OnBarUpdate()
      {
      This is where i have a problem i don't want to compare this with the currenct chart which the indicator is running on [0] all i want to check is if the 5 period SMA is above the 50 Period SMA on the daily chart and if it is then do something else....
      // Checks if the 5 period SMA is above the 50 period SMA on both the 5 and 15 minute time frames if (SMA(BarsArray[1], 5)[0] > SMA(BarsArray[1], 50)[0] && SMA(BarsArray[2], 5)[0] > SMA(BarsArray[2], 50)[0])

      So with that in mind will the following work...if the 5 period SMA on the daily chart [1] is > 50 Period SMA [1] do something

      if (SMA(BarsArray[1], 5) > SMA(BarsArray[1], 50) do something

      Comment


        #4
        Hello,

        Thanks for the reply.

        Add(PeriodType.Day, 15);


        This above will actually doesnt control the ammount of data loaded. Only requests to add a 15 day bar chart. Which would mean there is 15 days in one chart bar.

        The ammount of data loaded is always the master time frame. Therefor if you start the strategy on a 20 days back chart. All added MTF instruments will also load with 20 days back of data.

        Let me know if I can be of further assistance.

        Comment


          #5
          Ok that's fine then as that should be enough what about comparing the the sma on the daily chart

          And if that's the case why do we even need to specify a number (15) if all it does is use the number of bars from the mast chart? Does it have something to do with indexing

          Comment


            #6
            15 refers to the interval, so you are building 15-Day bars. Each bar consists of trading over 15 days.

            This is similar to if you say Add(PeriodType.Minute, 15); Each bar represents 15 minutes of trading.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              so i should use Add(PeriodType.Day, 1) each bar represents 1 days worth of trading....if i'm running this on a 60Minute chart with 15 days of historical data would that mean 360 daily bars (24*15) are available?

              Do i need to define Add(SMA(5)); and Add(SMA(10)); ? The master chart, which i'm running this indicator on already has these MA's defined. What is the purpose of defining these SMA's is it so the daily time frame can build and use them for comparison (SMA5 > SMA10)?

              If i was to do what i'm trying to achieve on the master chart it would look something like this (SMA(Close, 5)[0] > SMA(Close, 50)[0]) to make this work by doing this check on the daily chart if i understand the 'help' and sample MTF code then i need to add two line of code... As a basic outline this is what i have

              \\Initialise this
              Add(PeriodType.Day, 1)

              \\Check daily condition [1] and currenct chart condition [0]
              if ((SMA(BarsArray[1],5)[0] > SMA(BarsArray[1],50)[0]) && (High[0] < High[1])) || ((SMA(BarsArray[1],5)[0] < SMA(BarsArray[1],50)[0]) && (High[0] > High[1]))
              {
              \\ do this on the intraday chart
              Draw dot
              }

              Can anyone see why this wouldn't compile/work correctly
              Any help would be appreciated....

              Comment


                #8
                ryebank, the code looks good, you access the added bars array here in the conditions for the SMA's which is the daily one in your case. I don't follow the bars available logic you have, where's the 24 coming from? The historical data loaded would be what you set up for your master series / the primary one on the chart.

                The Add() logic in the Initialize for full indicators like the SMA is only for strategies that could add those for display / visualization.

                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  I am having the same problem. I would like to work on the ES 06-11 1 minute chart and take trades based on conditions in the 1 minute chart if the 100 day moving average is up for long trades and the 100 day moving average is down for short trades.

                  If I use the Add(PeriodType.Day,1), it generates no trades.

                  If I change it to Add(PeriodType,Minute,1) then it generates trades but it is only going to look at the 100 minute average.

                  It seems that when referencing daily bars or using the Add() function for daily bars, I am unable to reference any lower timeframe bars to make trading decisions. For example time reference If (ToTime(Time[0]) == 931)

                  I have also noticed that if use Add(PeriodType.Minute,3) for example, then I can not reference time stamps on the 1 minute bars unless I reference them every 3 minutes, 933, 936. 939, etc.

                  This is the same if I change it to Add(PeriodType.Minute,5) , I am only able to reference times on the primary 1 minute bar if they are every 5 minutes.

                  Since this is the case, it would make sense that intra-day bars could not be referenced if Add(PeriodType.Day,1) is used.

                  Are there any suggestions to working with 1 minute bars while referencing the 100 day moving average as a trend indicator.

                  thanks,

                  David
                  Last edited by capstonetrader; 03-22-2011, 01:25 PM.

                  Comment


                    #10
                    Hi David,

                    Welcome to the NinjaTrader forums!

                    We have worked with you a good deal on this by email. It really comes down to starting simple, debugging your code, and adding complexity only when you've verified behavior at each step.

                    If you are looking for professional level debugging services, please consider a NinjaScript consultant, who can be hired to write code to your specifications:
                    Ryan M.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by f.saeidi, Today, 11:02 AM
                    1 response
                    1 view
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by geotrades1, Today, 10:02 AM
                    4 responses
                    12 views
                    0 likes
                    Last Post geotrades1  
                    Started by rajendrasubedi2023, Today, 09:50 AM
                    3 responses
                    15 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by lorem, Today, 09:18 AM
                    2 responses
                    11 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by geddyisodin, Today, 05:20 AM
                    4 responses
                    30 views
                    0 likes
                    Last Post geddyisodin  
                    Working...
                    X