Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Create Weekly Time Frame from Daily Data

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

    Create Weekly Time Frame from Daily Data

    I'm creating a strategy that needs to verify certain conditions exist in both the daily time frame and weekly time frame. I have historical daily data from Yahoo loaded.

    Is it possible to create an array of weekly bar data from daily bar data? Similar to what is explained on this page but instead of creating a 1 minute and a 3 minute array of bar data from 1 minute data, I need to create a daily and weekly array from daily data? Obviously the daily array is default, but how do I get the weekly from the daily data?

    Thanks.

    #2
    Do I put Add(PeriodType.Day); and Add(PeriodType.Week); in the Initialize() function area, and then access the daily array using BarsArray[1] and access the weekly array using BarsArray[2]?


    Or do I enter only Add(PeriodType.Week); in the Initialize() function area, and access the daily data using BarsArray[0] and access the weekly array using BarsArray[1]?


    Or is that completely wrong?
    Last edited by pmn100; 08-25-2008, 12:57 PM.

    Comment


      #3
      >> Or do I enter only Add(PeriodType.Week); in the Initialize() function area, and access the daily data using BarsArray[0] and access the weekly array using BarsArray[1]?
      correct

      Comment


        #4
        Thanks Dierk

        Comment


          #5
          This isn't working for me.



          I've put Add(PeriodType.Week, 1); into the initialize() function area. I've then used the following code example to try and access this bar array:
          if (SMA(BarsArray[0], 5)[0] > SMA(BarsArray[0], 50)[0] && SMA(BarsArray[1], 5)[0] > SMA(BarsArray[1], 50)[0])

          {
          EnterShort(
          1000, "Order1");
          }

          if (BarsSinceEntry() == 4)
          {
          ExitShort(
          "Order1", "");
          }


          In English, if the 5 period SMA is above the 50 period SMA on the daily bars and the 5 period SMA is above the 50 period SMA on the weekly bars, enter short.

          But this is giving me no orders/no results. I've checked the charts and orders should have been activated.
          Last edited by pmn100; 08-26-2008, 10:27 AM.

          Comment


            #6
            If I delete the Add(PeriodType.Week, 1); and use just the following code, I do get results and orders are activated:
            if(SMA(BarsArray[0], 5)[0] > SMA(BarsArray[0], 50)[0])

            {
            EnterShort(
            1000, "Order1");
            }

            if (BarsSinceEntry() == 4)
            {
            ExitShort(
            "Order1", "");
            }

            So why isn't it recognising the weekly bar array? I've back tested using the DOW 30 from 2005 onwards, with daily bar data from Yahoo Finance. Daily, weekly, monthly charts display no problem.

            Comment


              #7
              I suggest adding some Print() statements to see what the values of the SMA on the weekly bars are and etc...
              RayNinjaTrader Customer Service

              Comment


                #8
                I've simplified the code now to this:

                if (SMA(5)[0] > 1 && SMA(BarsArray[1], 5)[0] > 1)
                {
                EnterShort(1000, "Order1");
                }
                if (BarsSinceEntry() == 4)
                {
                ExitShort("Order1", "");
                }
                And still no orders. That is simply if the 5 bar SMA is above 1 on both daily and weekly charts. Which they all are.

                This is what I've got. What am I not doing right?




                protectedoverridevoid Initialize()
                {
                Add(PeriodType.Week, 1);
                Add(SMA(5));

                CalculateOnBarClose = true;
                }

                ///<summary>
                /// Called on each bar update event (incoming tick)
                ///</summary>

                protectedoverridevoid OnBarUpdate()
                {
                if (SMA(5)[0] > 1 && SMA(BarsArray[1], 5)[0] > 1)
                {
                EnterShort(1000, "Order1");
                }
                if (BarsSinceEntry() == 4)
                {
                ExitShort("Order1", "");
                }
                }

                Comment


                  #9
                  I think I've narrowed it down to BarsSinceEntry() That function doesn't seem to want to work in multi time frames.

                  I'm using daily and weekly time frames. I want the BarsSinceEntry() to apply to the daily time frame. Is this possible using BarsInProgress or something?

                  Comment


                    #10
                    BarsSinceEntry() needs to be used with the multi-time frame syntax. Please see the Help Guide for more information. We are aware of some bugs with it right now which will be addressed in the next update.
                    Josh P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by rhyminkevin, Today, 04:58 PM
                    3 responses
                    47 views
                    0 likes
                    Last Post Anfedport  
                    Started by iceman2018, Today, 05:07 PM
                    0 responses
                    5 views
                    0 likes
                    Last Post iceman2018  
                    Started by lightsun47, Today, 03:51 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post lightsun47  
                    Started by 00nevest, Today, 02:27 PM
                    1 response
                    14 views
                    0 likes
                    Last Post 00nevest  
                    Started by futtrader, 04-21-2024, 01:50 AM
                    4 responses
                    50 views
                    0 likes
                    Last Post futtrader  
                    Working...
                    X