I have defined a time frame ( from 2:05 - 16:05 US EST every day ) where new orders would be placed as follows:
from datetime import datetime
class MovingAverageCrossAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetTimeZone("US/Eastern")
def trading(self,now):
start = now.replace(hour=2, minute=5, second=0, microsecond=0)
end=now.replace(hour=16, minute=5, second=0, microsecond=0)
if now >start and now<end:
return 'start trading'
else:
return 'stop trading'
def OnData(self, data):
now =datetime.now()
if self.trading(now)=='start trading':
..... # code to place orders
however when I run backtesting, the trades were executed outside the timeframe :
2020-01-01 00:00:00 : Launching analysis for 8882d05317bc8af1323bc8db439be288 with LEAN Engine v2.4.0.0.102912020-01-01 20:51:00 : Warning: To meet brokerage precision requirements, order LimitPrice was rounded to 0.70159 from 0.70158526834995232020-01-01 20:51:00 : SELL <<0.701382020-02-28 05:54:00 : Warning: Due to brokerage limitations, orders will be rounded to the nearest lot size of 12020-02-28 05:54:00 : Warning: To meet brokerage precision requirements, order LimitPrice was rounded to 0.65231 from 0.65231385711152832020-02-28 05:54:00 : SELL <<0.6513252020-03-03 07:40:00 : Warning: To meet brokerage precision requirements, order LimitPrice was rounded to 0.65657 from 0.65657049347428362020-03-03 07:40:00 : BUY >> 0.6568052020-03-08 21:49:00 : Warning: To meet brokerage precision requirements, order LimitPrice was rounded to 0.65809 from 0.65808808997083292020-03-08 21:49:00 : SELL <<0.6520752020-03-09 10:06:00 : Warning: To meet brokerage precision requirements, order LimitPrice was rounded to 0.66106 from 0.66106384668347162020-03-09 10:06:00 : BUY >> 0.6618952020-03-09 21:59:00 : Warning: To meet brokerage precision requirements, order LimitPrice was rounded to 0.65746 from 0.65746495935046932020-03-09 21:59:00 : SELL <<0.656622020-03-17 02:47:00 : Warning: To meet brokerage precision requirements, order LimitPrice was rounded to 0.60838 from 0.6083820927482482
Can you please clarify what time zone are the orders execution time displayed in backtest logs and what might be wrong with my code setting up the time frame ?
Any assistance would be appreciated!
Gloria ZUO
This case can be closed. Issue resolved thanks.
Gloria ZUO
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!