Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multi timeframe - current day

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

    Multi timeframe - current day

    I am trying to check the primary close against the day's open (CalculateOnCarClose = false). At first I was trying this:


    Code:
    if (Closes[0][0] >= Closes[1][0])
    But the condition was testing true for the day after I wanted it to. This does not make sense to me. With CalculateOnBarClose = false, shouldn't the 5 minute be checking for the current day?

    I switched to this:

    Code:
    Closes[0][0] >= CurrentDayOHL().CurrentOpen[0]
    which seems to be working correctly.

    But now I am trying to check for previous day closes, and I am all befuddled. I want to check for two down days prior to current and I am using this:


    Code:
    Closes[1][2] <= Closes[1][3]
    && Closes[1][1] <= Closes[1][2]
    What do I need to do to ensure that I am checking the correct days?

    Thanks for any help.

    #2
    Along these same lines, I am trying to check current day's SMA and current day and previous day on a custom indicator. All of the checked values are for one day earlier than I expect them to be, and I am using [0] as the reference.

    From the documentation, I would expect that with CalculateOnBarClose = false that for any bar shorter than the longest interval, the shorter current is checking longer 'yet to be complete' bar value.

    E.g., I expect this:

    With day = index 1, and week = index 2:

    Closes[1][0] <= SMA[Closes[2],20)[0]

    to check the day's close against the SMA for the week that the day is in. But this is not what I am getting at all. Printing SMA[Closes[2],20)[2] shows the comparison value as being the week prior. And for that matter, the close of the day prior (I have to use CurrentDayOHL() to get the current day for some reason).


    Thanks for any help.

    Comment


      #3
      Another annoying thing that has come up. Looking at the output window, the day comparisons are looking at the weekend days - and exclude weekends for the strategy is set to true. Do I need to include more conditionals to check for weekends in the strategy?? I can't seem to find any built-in functions that mention weekends.

      Comment


        #4
        Day Trading Fool,

        Sorry for the delay in a response, we had some technical difficulties on our end during the day. Thank you for your patience.

        The likely reason you are having issues is because of the order the various Bars objects are updated. Your lower time frame is updating before the other Bars objects you are checking and as such you end up checking the value of the Bars prior to them updating to the new values. To address this you should make your checks in the last Bars object to update instead of the first one to update. Only at that point in time do all of your Bar objects have "synced" values.

        For your weekend, whatever data is shown on the chart is what the strategy calculates on. You literally need a chart without weekend data showing for it to skip the weekend, otherwise you will have to add conditionals like checking Time[0].DayOfWeek and ensuring it isn't Saturday or Sunday.

        Hope that helps.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the help Josh.

          Not sure that I understand. Are you saying that I should be using the BarInProgress function to filter the conditionals? I haven't been using anything. And I am not sure how I could use that.... Here is a bit of code:

          Code:
          if (ToTime(Time[0]) >= 133500
                                      && VOLMA(BarsArray[1], 30)[0] >= MinAverage30DayVol
                                      && Closes[1][1] >= MinPrice
                                      && Closes[0][0] >= CurrentDayOHL().CurrentOpen[0]
                                      && CurrentDayOHL().CurrentOpen[0] < SMA(Closes[1],20)[0] 
                                      && PriorDayOHLC().PriorClose[2] <= PriorDayOHLC().PriorClose[3]
                                      && PriorDayOHLC().PriorClose[1] <= PriorDayOHLC().PriorClose[2])
          I can get current day - the 'real' current day using the CurrentDayOHL - but the SMA it is comparing to is for the day prior rather than the current. How to fix this?

          Prior day is working correctly - except that it is checking weekend data - Monday's pass the criteria if there are no ticks over the weekend. Any recommendations?

          Thanks!

          Comment


            #6
            Day Trading Fool,

            You will definitely want to filter your code by BarsInProgress.

            Code:
            if (BarsInProgress == x)
            {
                // strategy code
            }
            x is the number for the last BIP context to update. Usually this is the highest BIP value as BIPs are evaluated sequentially.

            If you are using PriorDayOHLC() it will indeed check weekend if on your chart it has weekend data. No way around this besides removing that data or checking in your code for the actual day of weeks.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Ok - I here is how I have it set up:

              The primary is the shortest time interval (currently 5 mins). Day is index 1, week is index 2.

              As you can see - I am trying to check the primary against the day that it should be 'in':

              Code:
              Closes[0][0] >= CurrentDayOHL().CurrentOpen[0]
              This is working. But if I were to use BIP, which index should I be checking for prior to checking the primary against the day that it should be in? (I messed around with it earlier and couldn't seem to get anything to work.)

              How about the SMA comparison? Which BIP do I check for to ensure that the SMA is for the current day and not the day prior?

              Weekends - the strategy is set to exclude weekends and they are not showing up on the chart. I don't know why they are showing up in the strategy. Any suggestions?

              Comment


                #8
                Day Trading Fool,

                If you want synced values you can only check the values of any of the Bars after all Bars have been updated. This means your last BIP which means all your code needs to go in at BIP2.

                Code:
                if (BarsInProgress == 2)
                {
                    // code
                }
                When you are in BIP2, Closes[0][0] will give you the minute's close, Closes[1][0] would be daily, Closes[2][0] would be the same as Close[0] which would be weekly close. For SMA, SMA(BarsArray[0], 20)[0] would be minute SMA, SMA(BarsArray[1], 20)[0] would be daily, SMA(BarsArray[2], 20)[0] would be the same as SMA(20)[0] which would be weekly SMA.

                Setting strategy to exclude weekend simply means do not allow for trades during weekend, it does not mean to not process weekend data. Whatever data is shown is what will be processed. It is there somewhere if you are processing it, otherwise it won't show up.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Ok - so if I understand correctly, there is no way to check a 5 minute close mid-day against the current day's open? Say with:
                  Code:
                  Closes[0][0] >= Closes[1][0];
                  Even with CalculateOnBarClose = false?

                  It sounds like the weekend filter is going to be pretty complex... well, one check for Monday, another check for Tuesday and associated statements for each. Probably holidays too. Is there something like a 'Check if market was open yesterday' function?

                  Thanks for the help.
                  Last edited by Day Trading Fool; 02-10-2010, 08:14 AM. Reason: Added code

                  Comment


                    #10
                    Day Trading Fool,

                    Closes[0][0] can be checked against Closes[1][0] only when CalculateOnBarClose = false during real-time. The critical factor is real-time. Otherwise historically processed bars will only have one event update for the daily bars.

                    Unfortunately there is no "check if market was open yesterday" function.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks for the help Josh.

                      It looks as if what I am trying to test for is impossible to do on historical data? I tried this to see what would happen:

                      Code:
                                  if (Position.MarketPosition == MarketPosition.Flat)
                                  {
                                      if (BarsInProgress == 2)
                                      {    
                                          Print (Time[0]+": Open: "+Open[0]+"; Indicator_1: "+Indicator_1(Close,12, 10).Value[0]+"; Indicator_2: "+Indicator_2(Close, 12, 10, 3).Value[0]); 
                                          if (BarsInProgress == 1)
                                          {
                                              Print (Time[0]+": Open: "+Open[0]+"; Close: "+Close[0]+"; Yesterday's Close: "+Close[1]+" Two days ago: "+Close[2]); 
                                              if (BarsInProgress == 0)
                                              {
                                                  if (Close[0]>Opens[1][0])
                                                  {
                                                      Print (Time[0]+": Open: "+Open[0]+"; Close: "+Close[0]+"; Day's Open: "+Opens[1]);
                                                  }
                                              }
                                          }
                                      }
                      But nothing printed beyond the first BIP condition. So if I understand correctly, NT processes like:

                      The day starts.
                      Process all 5 minute bars for Day 1.
                      Process Day 1.
                      Process all 5 minute bars for Day 2.
                      Process Day 2
                      ...
                      Process all 5 minute bars for Day 7.
                      Process Day 7.
                      Process Week 1.
                      ...

                      Or maybe:
                      Process all 5 minute bars.
                      Process all Day bars.
                      Process all Week bars.

                      Either of these correct?

                      Perhaps there is some kind of work around? I guess the only things I can't compare properly at this point are the custom indicators and the SMA. The problem is similar in both cases:

                      Code:
                      Indicator_1(Closes[2], 12, 10, 3).Value[0] >= Indicator_2(Closes[2], 12, 10, 3).Value[1]
                      is looking at data a week/2 weeks early relative to the day I am trying to check the 5 minute in.

                      And for the SMA:

                      Code:
                      CurrentDayOHL().CurrentOpen[0] < SMA(Closes[1],20)[0]
                      Checks the correct day open against the wrong day SMA (the day prior). Is there nothing I can do? Thanks for any suggestions.

                      Comment


                        #12
                        Day Trading Fool,

                        Your outlined sequence of events is correct based on the ordering of Bar series you have added. What you can try is to run your strategy on a weekly chart, then Add() daily bars as the secondary and minute bars as the tertiary. See if that helps the sequencing enough to allow you to do what you want.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          Which sequence of events? The first case or the 2nd?

                          It sounds like a pass thru conditional boolean may work...

                          Comment


                            #14
                            The first sequence.
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Sorry about this... I am still very much confused - and still trying to figure out a work around.

                              I stripped everything away and have a strategy setup as: Week as the primary, day as the secondary, and 5-minute as the tertiary.

                              I setup conditionals as:
                              Code:
                              if (BarsInProgress == 0)
                                              {
                                                  Print ("BIP = 0: "+Times[0][0] + "; "+Times[1][0]+"; "+Times[2][0]);
                                              }
                                              if (BarsInProgress == 1)
                                              {
                                                  Print ("BIP = 1: "+Times[0][0] + "; "+Times[1][0]+"; "+Times[2][0]);
                                              }
                                              if (BarsInProgress == 2)
                                              {
                                                  Print ("BIP = 2: "+Times[0][0] + "; "+Times[1][0]+"; "+Times[2][0]);
                                              }
                              Here is the last few lines of output:
                              BIP = 0: 2/9/2010 1:20:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:15:00 PM
                              BIP = 2: 2/9/2010 1:20:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:20:00 PM
                              BIP = 0: 2/9/2010 1:25:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:20:00 PM
                              BIP = 2: 2/9/2010 1:25:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:25:00 PM
                              BIP = 0: 2/9/2010 1:30:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:25:00 PM
                              BIP = 2: 2/9/2010 1:30:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:30:00 PM
                              BIP = 0: 2/9/2010 1:35:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:30:00 PM
                              BIP = 2: 2/9/2010 1:35:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:35:00 PM
                              BIP = 0: 2/9/2010 1:40:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:35:00 PM
                              BIP = 2: 2/9/2010 1:40:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:40:00 PM
                              BIP = 0: 2/9/2010 1:45:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:40:00 PM
                              BIP = 2: 2/9/2010 1:45:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:45:00 PM
                              BIP = 0: 2/9/2010 1:50:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:45:00 PM
                              BIP = 2: 2/9/2010 1:50:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:50:00 PM
                              BIP = 0: 2/9/2010 1:55:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:50:00 PM
                              BIP = 2: 2/9/2010 1:55:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:55:00 PM
                              BIP = 0: 2/9/2010 2:00:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 1:55:00 PM
                              BIP = 2: 2/9/2010 2:00:00 PM; 2/8/2010 12:00:00 AM; 2/9/2010 2:00:00 PM
                              Why isn't BIP = 1 ever true? Why is Times[1][0] always one day behind? Is the code goofy?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              672 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              577 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X