Back

Scheduled Event - Active time or Stop loss/Limit order Issue

For some reason my code is only exectuing one trade at the start date and time of the scheduled event. My thoughts are; does scheduled event only trigger once? Or maybe my stop loss and take profit are not working correctly, since the market should move 5 to 11 pips to trigger either the stop loss or take profit during the high volume overnight time. Attached my backtest for the code. Ideally I just want the code to run once per week at 3 AM for one trade.

Update Backtest








0

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.


I have a few observations that maybe someone can shed some light on. 1), 3), and 4) seem like bugs.

1) I have it running 1 out of 6 months now, but then it just stops showing trades?

2) I also noticed that limit and stop markets don't cancel when one fills. Any way around this? I attempted to do it a backhand way shown at the end of the code, but it didn't work. Can this be implemented by the QuantConnect team?

3) Putting the schedule at several times other than (6,0) results in the backtest giving the first Market order as Market on Open order (even though I don't have a Market on Open order coded), What market schedule is the data on? Forex should be open from Sunday to Friday night US time. So calling a regular order anytime on Monday shouldn't be an issue.

4) How can I have -6000 unrealized and +337 net profit on my backtest results?

I attached my latest backtest if it helps.

0


Hi Michael,

1) The reason the algorithm stops trading after the first month is because the ordering logic causes lingering orders instead of implementing an OCO ordering scheme. When one of these lingering orders gets executed, the portfolio remains in an invested state. Taking a look at the `SpecificTime` method, we see the algorithm must pass the following condition before orders are considered

if not self.Portfolio.Invested:
...

In the backtest above, the portfolio stays in an invested state from February 3rd to the end of the backtest.

2) To implement OCO orders, refer to this related thread.

3) I was not able to reproduce this issue. See the attached backtest order logs for reference.

4) Net profit is the after-fees profit the algorithm has generated on completed trades. Unrealized profit is the profit status of the portfolio's current positions. These values are almost always different.

Lastly, it should be noted that the indicators in the algorithm above are updated on each minute and every 5-minute interval. To fix this, we need to use the indicator classes instead of the indicator helper methods in the QCAlgorithm class.

self.EMA5 = ExponentialMovingAverage(5)
self.EMA40 = ExponentialMovingAverage(40)
self.RegisterIndicator("EURUSD", self.EMA5, timedelta(minutes=5))
self.RegisterIndicator("EURUSD", self.EMA40, timedelta(minutes=5))

I recommend reviewing our documentation on consolidating data for indicators.

See the attached backtest for reference.

Best,
Derek Melchin

1

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.


Thanks for your feedback and comments! I've tried to implement the OCO, but the code doesn't seem to be entering the if statement in the def OnOrderEvent. Any ideas? See attached code.

0


I just went into debugger mode and put the break point at line 39, the market order. After this it did not go to def OnOrderEvent. Even though I watched the variable self.EntryTicket which was now set to 1: Order ID: (BrokerID:1) Filled Market Order for 100000 units of EURUSD Request Count:1 Response Count:1 

Maybe Oanda is not supported by def OnOrderEvent ?

 

I also #23 and#32 to remove the schedule factor to help debug

 

0

I think I figured it out. Can someone please doublecheck my algorithm? Also to my comment in the intital post I think a "market order on open" shows when it's a holiday? Ie. January 1st? It happens in this backtest, even though I don't have a market order on open coded.

0


Looks like it's working, but I can only run buy or sell at once, not both at the same time.

0

Update Backtest





0

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.


Loading...

This discussion is closed