SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Thu Jul 19, 2018 8:25 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Apr 14, 2010 5:25 pm 
Offline

Joined: Mon Feb 22, 2010 5:14 pm
Posts: 13
Hi,

I want to set my strategy to be active only on trading hours, 9:00-3:30 EST.
I want it for live mode and for backtesting.
How can I do it? If you can add code sample it will be great.
Also my pc is not set to EST.

Tx in advance!


Top
 Profile  
 
PostPosted: Thu Jan 27, 2011 6:20 am 
Offline

Joined: Mon Sep 08, 2008 2:20 am
Posts: 40
Location: Toronto, Ontario, Canada
There are probably cleaner ways to code this but here's a stab at it.
Code:
   public override void OnBar (Bar bar)
      {
         if(DurationWithinWorkingHours(bar.DateTime))
         {
            //Run your code
         }
         else
         {
            //You're outside day hours so close any short or long position.
         }
      }

      public bool DurationWithinWorkingHours(DateTime currentTime)
      {
         //Here just set the year, month, day to a common value and compare the time.
         DateTime start = new DateTime(1999,1,1,09,35,00);     //Allow entry at 915
         DateTime end = new DateTime(1999,1,1,16,00,00);        //Exit everything at 400
         DateTime current = new DateTime(1999,1,1,currentTime.Hour,currentTime.Minute,currentTime.Second);
          
         if (current >= start && current <= end)
            return true;
         return false;
       
      }


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group