I am using Daily FX to import the economic calendar, but I don't want the code to execute right on the hour. I want it to wait a few minutes until a clearer direction can be identified before placing orders. I see there is a WaitOne method, but I am having a difficult time figuring out how to use it in an algo. Does anyone have any examples or something they can whip up to show me?
Gurumeher Sawhney
Scheduled Events can be used for this case, which allows you to trigger code to run at specific times regardless of the data events. So an event can be scheduled that independently triggers when to import the Daily FX economics calendar. This sample code shows Scheduled Events implemented at various times calling various methods.
Joshua Montgomery
Gurumeher Sawhney
Thank you for looking into my question. Let me use an example to better help illustrate what I'm looking for.
Let's say I'm interested in creating an algo that liquidates my holdings of "EURUSD" on the release of a major economic release. Five minutes later, once the trade direction is a little clearer, it will place an order. The economic releases are not consistent, so they could be at any time of day (which means most of the scheduled events for a time of day or date won't work. Also, I only want it to wait and implement the order once, so a recurring scheduled event won't work either.
The code would probably go through a loop, but I need to implement a waiting period so it can liquidate upon release and then run a second time to place the order after a predetermined waiting period.
Other issues I'm having with this code are:
I've attached a simple backtest to show how far I've gotten. Maybe it will help explain what I'm looking for or where I'm stuck at.
Gurumeher Sawhney
In order to execute a trade 10 minutes after the trading signal is determined, try storing all the data necessary for the order in an object, including the future time, and then query the array using self.Time and conditional statements. The future time can be calculated via DateTime arithmetic: in python it is as easy as datetime.now() + timedelta(minutes = 10).
The DailyFX object has a public property Currency that defines the currency for the event so a conditional statement can be used to filter out the events. The DailyFX object updates automatically based on the data, but a potential solution could be using a conditional statement that ignores the second event if there exists an aforementioned object whose order still needs to be created.
Joshua Montgomery
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!