Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

If I use a customised session template to

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

    If I use a customised session template to

    indicate that there is only 1 session a week (as per attached screenshot), and I have ExitOnClose = true in the Initialize section of the strategy code, will my trades only exit only on Saturday morning's close?

    Regards

    Kay Wai
    Attached Files

    #2
    Yes Kay, ExitOnClose is tied to the session begin / end times used - I'm not sure how exiting on Saturday morning would work for you, but theoretically you're right.

    Comment


      #3
      Hi Bertrand,

      That's because FX trades till Saturday morning in Asian time zone.

      Thanks Bertrand!

      Regards

      Kay Wai

      Comment


        #4
        Hi Bertrand,

        Unfortunately that template I showed you didn't work in market replay....it still exited on the day's close of trading. I've attached it again for your convenience.

        Is there any other way where I can code for an ExitOnClose only if it is a Saturday and to stay in the trade if it is any other day?

        Regards

        Kay Wai
        Attached Files

        Comment


          #5
          Kay, you could create some sort of method to check the time and instead of using ExitOnClose, you could just exit the position when it is Saturday morning. The code would be similar to the code in the limiting trading hours reference sample.

          The pseudo-code would look something like this:
          Code:
          if (Time[0] > {saturday 8am} && Time[0] < {saturday 10am})
          {
              ExitLong();
              ExitShort();
          }
          AustinNinjaTrader Customer Service

          Comment


            #6
            Hi Austin,

            If I'm using hourly bars, do I need to set my exit times to the hour?

            When I set the time as per below, the exit is 2 bars early.
            Code:
            [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
            [SIZE=2][FONT=Courier New][COLOR=#0000ff]else[/COLOR][/FONT][/SIZE][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (Position.MarketPosition == MarketPosition.Long)[/COLOR][/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]].DayOfWeek == DayOfWeek.Saturday)[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ((ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) >= [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]40000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] && ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]50000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]ExitLong();[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [/SIZE][/FONT]
            And when I set it as below, it doesn't exit by the close!

            Code:
            [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
            [SIZE=2][FONT=Courier New][COLOR=#0000ff]else[/COLOR][/FONT][/SIZE][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (Position.MarketPosition == MarketPosition.Long)[/COLOR][/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]].DayOfWeek == DayOfWeek.Saturday)[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ((ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]40000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] && ToTime(Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]) < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]50000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]ExitLong();[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [/SIZE][/FONT]
            The difference is the "equals" sign at 4am. The market closes at 5am as indicated on the bar. Any suggestions how I can get it to close as near to the close as possible?

            I have attached 3 charts, one with the equals sign at 4am, one without the equals sign at 4am and the last one with the time between 445am and 5am. The last bar on the right says 5am.

            Regards

            Kay Wai
            Attached Files
            Last edited by kaywai; 06-20-2011, 06:41 AM. Reason: attaching charts

            Comment


              #7
              Kay, easiest is if you add a print to your conditions contained the Time[x] / bars timestamp then as well, so you can see exactly when they would evaluate to 'true' - keep also in mind in backtesting if you evaluate a condition to 'true' on bar 0 it would then execute at then open of bar 1.

              To get access the finer timestamps than the hourly one, add for example 5 minute series in your Initialize() and use Times[x] to access those.

              Comment


                #8
                Thanks Bertrand!

                I got it to work after doing some research on BarsInProgress.

                Regards

                Kay Wai

                Comment


                  #9
                  Hi Bertrand,

                  Just a thought. If I am using 1 hours bars to determine the entry but I am trying to exit on a finer timestamps (less than an hour bar), is it necessary that I use BarsInProgress to get the desired result?

                  Is there an alternative solution?

                  Regards

                  Kay Wai

                  Comment


                    #10
                    Kay, if you have multiple series on the chart, the primary method to seperate them is to use BarsInProgress, with BIP = 0 being your main series and BIP = 1 being the secondary series.

                    There are alternatives, such as checking Times[1][0], which would look at the time values of the secondary bars (12:00, 12:05, 12:10, etc) instead of Times[0][0], which would look at the times of the primary bars (12:00, 1:00, 2:00, etc).

                    So perhaps you're looking for something like this:
                    Code:
                    if (Times[1][0] > 4am saturday && Times[1][0] < 5am saturday)
                    {
                     ExitLong()
                     ExitShort()
                    }
                    That would give your exits a more specific time to exit.
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      Hi Austin,

                      I tried what you suggested and I get 2 types of errors:-

                      Error 1: Cannot apply indexing [] to an expression of type 'System.DataTime'
                      Error 2: Operator '>' cannot be applied to operands of type 'System.DateTime' and 'int'

                      please find the code below;-
                      Code:
                      [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
                      protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] Initialize()[/COLOR]
                      {
                      CalculateOnBarClose = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];
                      ExitOnClose = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];
                      Add(TDSellExtendedSetupFXwithCOBCfalse());
                      Add(TDBuyExtendedSetupFXwithCOBCfalse());
                      Add(PeriodType.Minute, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]5[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);
                      TraceOrders = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];
                      }
                       
                      [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] OnBarUpdate()[/COLOR]
                      {
                      [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] (Position.MarketPosition == MarketPosition.Long)[/COLOR]
                      {
                      [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// First Long Exit
                      [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]].DayOfWeek == DayOfWeek.Saturday)
                      {
                      [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] ((Times[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]][[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] > [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]45000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] && Times[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]][[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]] < [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]50000[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]))
                      {
                      ExitLong();
                      Print([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Exit Time is "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + Time[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]]);
                      }
                      }
                      [/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT][/SIZE][/FONT]
                      Could you please tell me what I am doing wrong?

                      Regards

                      Kay Wai

                      Comment


                        #12
                        Hi Austin,

                        In addition to the issues I'm having which I documented earlier today, there is another problem that popped up too.

                        After I added "Add(PeriodType.Minute, 5);" to the Initialize() section, my entries are made based on a 5 minute bar chart rather than the 1 hour bar chart that I want it to do.

                        I am only including the smaller timeframe just to exit at the close on Saturday morning. That is the only reason for wanting the smaller timeframe. I would like the larger timeframe - the 1 hour bars - to determine the rest of my strategy.

                        Regards

                        Kay Wai


                        Comment


                          #13
                          Kay Wai, in your second most recent post, you'll have to use ToTime(Times[1][0]) instead of just the time when comparing to integer values (like 50000).

                          As for the issue in your most recent post (entries on the 5 minute bars instead of hourly), you will have to filter out the events based on the BarsInProgress index, like this:
                          Code:
                          OnBarUpdate()
                          {
                            if (BarsInProgress == 0)
                            {
                              // all of your strategy code here, except for the smaller timeframe exit stuff
                            }
                            else if (BarsInProgress == 1)
                            {
                              // this is where your exit code will go, because it is supposed to work on the smaller (secondary) timeframe, with BIP index = 1
                            if (Position.MarketPosition == MarketPosition.Long)
                            {
                            // First Long Exit
                              if (Times[1][0].DayOfWeek == DayOfWeek.Saturday)
                              {
                                if ((ToTime(Times[1][0]) > 45000 && ToTime(Times[1][0]) < 50000))
                                {
                                  ExitLong();
                                  Print("Exit Time on the 5 min timeframe is: " + Times[1][0].ToString());
                                  Print("Exit Time on the hour timeframe is: " + Times[0][0].ToString());
                                }
                              }
                            }
                          }
                          }
                          Please take a look at changes I've made to the code here.. It is best to keep things consistent and print out as much information as necessary to help you understand what is going on.
                          AustinNinjaTrader Customer Service

                          Comment


                            #14
                            Hi Austin,

                            Thank you very much for your help! Appreciate it!

                            Best Regards

                            Kay Wai
                            Last edited by kaywai; 06-22-2011, 11:14 PM. Reason: additonal info

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            646 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            367 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            108 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            570 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            573 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X