Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help with mulit time frame

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

    Help with mulit time frame

    I have a strategy that runs on a 5minute time frame.
    How would I be able to check on start up of the strategy the price of the open and the 20 period sma on a daily chart time frame? I only need the strategy to check it once and not continuously through out the day.

    Thanks

    #2
    Hello Superhaze,

    Thank you for your note.

    I would recommend that you do this in the OnBarUpdate and setup a condition for the first bar and check the price and 20 SMA for the daily.
    Such as,
    if(CurrentBar == 0)

    Additionally, you would need to use the Add() to additionally data series.
    Please see the link below for more information on Multi-Time series -
    http://www.ninjatrader.com/support/h...nstruments.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Ok, I used Add() to add in a daily time frame in addition to the primary bars.

      This is my code to test out to see if I get the correct opening price on the daily bars
      Code:
      if (CurrentBars[1] == 0)
                  {
                      double dailyChartOpen = Opens[1][0];
      
                      DrawTextFixed("MyTag", dailyChartOpen.ToString(), TextPosition.BottomRight);
                  }
      It retrieves the open for the current date, the problem is that I want to get the value when the asian markets open up, but its still considered the same day.

      Example, on the 17th at 4pm Colorado time the asian markets open, and a new daily bar is started, need to retrieve this open which is technically the 18th.

      Comment


        #4
        Hello superhaze421,

        Thank you for your response.

        You can use the following code for each day rather than just the first day.
        Code:
        			if(BarsInProgress == 0 && Bars.FirstBarOfSession)
        			{
        				double dailyChartOpen = Opens[1][0];
                        DrawTextFixed("MyTag", dailyChartOpen.ToString(), TextPosition.BottomRight);
        			}

        Comment


          #5
          Hi, thanks
          But it still retrieves the 17th's open not the new daily bar that starts in the afternoon.

          Comment


            #6
            Hello superhaze421,

            Thank you for your response.

            Are you using CalculateOnBarClose = True? And what instrument are you testing?

            Comment


              #7
              CalculateOnBarClose=false

              testing on CL

              Comment


                #8
                Hello superhaze421,

                Thank you for your response.

                I will test this further and follow up with you when I have additional information.

                Comment


                  #9
                  Any update? Thanks

                  Comment


                    #10
                    Change my code up a bit. I was getting the wrong open by checking the daily bars in market replay.

                    Checks the first bar of the nymex crude session open using the primary 5min bars
                    Now I need to get the value of the 20 SMA at the open, this needs to be the daily bar sma not the 5min.

                    when I run this strategy over a couple of days it returns the correct opens, but sma value stays the same. Am I doing something wrong?

                    Code:
                    protected override void Initialize()
                            {
                                CalculateOnBarClose = false;
                                Add("CL 08-14",PeriodType.Day, 1);
                            }
                    
                    
                            protected override void OnBarUpdate()
                            {
                                if(BarsInProgress == 0 && Bars.FirstBarOfSession)
                                {
                                    double dailyChartOpen = Opens[0][0];// Gets open from 5min, primary bar
                    
                                    double smaValue = SMA(BarsArray[1], 20)[0];// Should get sma from daily bar, not primary bar
                    
                                    Print(dailyChartOpen.ToString()); // gets correct value
                                    Print("SMA=" + smaValue.ToString()); // prints the same number every open
                                }

                    Comment


                      #11
                      Hello superhaze421,

                      Thank you for your patience.

                      What are your DaysToLoad set to on the Chart for the 5 Minute? (Right click > Data Series > DaysToLoad)

                      I look forward to your response.

                      Comment


                        #12
                        5 days to load

                        If i run a market replay for several days, it will give me the correct opens but will keep printing the same sma value.
                        If i restart the strategy right before the session open it will reinitialize and then give me a different sma value.
                        Last edited by superhaze421; 07-21-2014, 06:24 PM.

                        Comment


                          #13
                          Hello superhaze421,

                          Thank you for your response.

                          As we are checking the 20 period of the Daily bars we need at least 20 Daily bars loaded - so we need more than 20 DaysToLoad set for the 5 minute bar in the Data Series menu.

                          Comment


                            #14
                            ok changed it to a 5 sma and set the strategy to load 10 days in market replay 07/7 - 07/11

                            started the replay at 7/8 at around 11:00am, and got the data below

                            Session Start: 6/29/2014 3:00:00 PM Open Price 105.72 SMA Value 105.76
                            Session Start: 6/30/2014 3:00:00 PM Open Price 105.39 SMA Value 105.76
                            Session Start: 7/1/2014 3:00:00 PM Open Price 105.34 SMA Value 105.76
                            Session Start: 7/2/2014 3:00:00 PM Open Price 105.45 SMA Value 105.76
                            Session Start: 7/3/2014 3:00:00 PM Open Price 104.01 SMA Value 105.76
                            Session Start: 7/6/2014 3:00:00 PM Open Price 103.76 SMA Value 105.76
                            Session Start: 7/7/2014 3:00:00 PM Open Price 103.47 SMA Value 105.76

                            when it hits the next session at 3:00 PM
                            i get this
                            Session Start: 7/8/2014 3:00:00 PM Open Price 103.49 SMA Value 105.76

                            this is CL it gets the correct opens but SMA is the same across all dates unless I reinitialize the strategy.
                            I dont need all thoses values, just need to pull that data at the start of a sesssion, so i only need the last line that I got.

                            Code:
                             protected override void Initialize()
                                    {
                                        CalculateOnBarClose = false;
                                        Add(PeriodType.Day, 1);
                                    }
                            
                            
                                    protected override void OnBarUpdate()
                                    {
                                        if(Bars.FirstBarOfSession)
                                        {
                                            double dailyChartOpen = Open[0];// Gets open from 5min, primary bar
                                            double smaValue = SMA(Closes[1], 5)[0];// Should get sma from daily bar, not primary bar
                                            Bars.Session.GetNextBeginEnd(BarsArray[0], 0, out sessionBegin, out sessionEnd);
                                            Print("Session Start: " + sessionBegin+" Open Price "+dailyChartOpen + " SMA Value "+smaValue);
                            Last edited by superhaze421; 07-22-2014, 10:36 AM.

                            Comment


                              #15
                              Hello,

                              If you are wanting just the current day and session you would need to filter out our condition for the most current day.

                              if(Time[0] == DateTime.Today)
                              Cal H.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by sjsj2732, Yesterday, 04:31 AM
                              0 responses
                              33 views
                              0 likes
                              Last Post sjsj2732  
                              Started by NullPointStrategies, 03-13-2026, 05:17 AM
                              0 responses
                              286 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              285 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              133 views
                              1 like
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              91 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Working...
                              X