Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question on days of the week

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

    Question on days of the week

    Hello,
    I was wondering how to backtest my strategy only in certain days of the week. For example i would like to execute my orders only on mondays.

    Thanks for advices.

    #2
    Hello jvr23,

    Welcome to the NinjaTrader forums! You can use C# DateTime features for this. An example entry condition that checks bar time stamp and only enters Monday:

    if(Time[0].DayOfWeek == DayOfWeek.Monday)
    {
    //EnterHere
    }
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by jvr23 View Post
      Hello,
      I was wondering how to backtest my strategy only in certain days of the week. For example i would like to execute my orders only on mondays.

      Thanks for advices.
      Code:
      protected override void OnBarUpdate()
      {
      if (Time[0].DayOfWeek != DayOfWeek.Monday) return;
      // Rest of code to process trades goes here
      }

      Comment


        #4
        Thanks. Have to learn basics of C#. Unfortunately i know only python and c++ ...

        Comment


          #5
          Both Python and c++ are OO languages. The transition to C# should not be too hard for you then.

          Comment


            #6
            question

            I'm trying to backtest the ES from 1.1.2005 to 7.11.2011 with this strategy
            Code:
                    protected override void Initialize()
                    {
                        CalculateOnBarClose = true;
                        ExitOnClose = true;
                    }
            
                    /// <summary>
                    /// Called on each bar update event (incoming tick)
                    /// </summary>
                    protected override void OnBarUpdate()
                    {
                        // Condition set 1
                        if (Time[0].DayOfWeek == DayOfWeek.Monday)
                        {
                            if (Open[1] < Close[1])
                            {
                                EnterLong();
                            }
                        }
                    }
            but there is no executions when i click on "Run backtest". Start date is 13.4.2006 and end date is 13.4.2006
            Simply i would like to percently compute how many mondays,tuesdays etc. closed above theirs open.
            Thanks for help

            Comment


              #7
              Originally posted by jvr23 View Post
              I'm trying to backtest the ES from 1.1.2005 to 7.11.2011 with this strategy
              Code:
                      protected override void Initialize()
                      {
                          CalculateOnBarClose = true;
                          ExitOnClose = true;
                      }
              
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                          // Condition set 1
                          if (Time[0].DayOfWeek == DayOfWeek.Monday)
                          {
                              if (Open[1] < Close[1])
                              {
                                  EnterLong();
                              }
                          }
                      }
              but there is no executions when i click on "Run backtest". Start date is 13.4.2006 and end date is 13.4.2006
              Simply i would like to percently compute how many mondays,tuesdays etc. closed above theirs open.
              Thanks for help
              Given that the "start date" and "end date" (emphasis mine) are the same, that is the result that I would expect.

              Comment


                #8
                Originally posted by koganam View Post
                Given that the "start date" and "end date" (emphasis mine) are the same, that is the result that I would expect.
                The time frame is set to 1.1.2005 to 7.11.2011. 13.4.2006-13.4.2006 is in summary after backtest.

                Comment


                  #9
                  So i've restarted NT and timeframe problem is solved. But another strange thing is that there are only 2 executions. 1 BUY on 8.2.2005 and 1 SELL on 7.11.2011.

                  Comment


                    #10
                    Great you are seeing some executions now. Next step is to debug the strategy.

                    Since your one trade lasts almost the entire duration of your test, then it's likely that your exits are too restrictive, or that you don't have any exits at all. If you wanted to add more potential entries, could do this simply by setting ExitOnClose = true, adding protective orders with SetStopLoss() and SetProfitTarget(), or changing EntriesPerDirection to a higher number.
                    Last edited by NinjaTrader_RyanM1; 11-08-2011, 12:45 PM.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_RyanM View Post
                      Great you are seeing some executions now. Next step is to debug the strategy.

                      Since your one trade lasts almost the entire duration of your test, then it's likely that your exits are too restrictive, or that you don't have any exits at all. If you wanted to add more potential entries, could do this simply by setting ExitOnClose = true, adding protective orders with SetStopLoss() and SetProfitTarget(), or changing EntriesPerDirection to a higher number.
                      Hello,
                      Thanks for reply. As you can see in my code i have "ExitOnClose = true". but even so i'm in one long position through whole timeframe....sorry for my english hope you understand.

                      Comment


                        #12
                        What session template are you using? What interval are you running the strategy against?
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_RyanM View Post
                          What session template are you using? What interval are you running the strategy against?
                          session template : <Use instrument settings>
                          time frame : 1.1.2005 to 7.11.2011
                          data series type: Day
                          instrument ES 12-11

                          Comment


                            #14
                            I see. ExitOnClose wouldn't be seen on daily intervals. You will need to create some additional exits in your strategy.
                            Ryan M.NinjaTrader Customer Service

                            Comment


                              #15
                              Is there any method "am i in long/short position in time[0]?"

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by AttiM, 02-14-2024, 05:20 PM
                              12 responses
                              213 views
                              0 likes
                              Last Post DrakeiJosh  
                              Started by cre8able, 02-11-2023, 05:43 PM
                              3 responses
                              237 views
                              0 likes
                              Last Post rhubear
                              by rhubear
                               
                              Started by frslvr, 04-11-2024, 07:26 AM
                              8 responses
                              116 views
                              1 like
                              Last Post NinjaTrader_BrandonH  
                              Started by stafe, 04-15-2024, 08:34 PM
                              10 responses
                              47 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by rocketman7, Today, 09:41 AM
                              3 responses
                              11 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X