Hi All,
I am new to QC and have attempted to resolve the following issue using the documentation and the community discussions, to no avail.
The backtest attached is a basic SMA cross strategy. It looks at the current fast and slow SMA, and the previous period's fast and slow SMA, if (fast_SMA > slow_SMA) and (past_fast_SMA < past_slow_SMA), it should execute a long trade.
When I cross compare the trades executed on QC, with the Oanda platform, there is a complete mismatch in the data. Below is the logs for the final trade in the back test period:
2023-02-27 11:00:00 :########### LONG #################
2023-02-27 11:00:00 :Time >> 2023-02-27 11:00:00
2023-02-27 11:00:00 :If (fastEMA > slowEMA) & (pastFastEma < pastSlowEma):
2023-02-27 11:00:00 :pastFastEma >> 1.195029
2023-02-27 11:00:00 :pastSlowEma >> 1.1957374
2023-02-27 11:00:00 :Current fast_EMA >> 1.195813
2023-02-27 11:00:00 :Current slow_EMA >> 1.1955508
2023-02-27 11:00:00 :Long @ >> 1.19774
2023-02-27 11:00:00 :Limit @ >> 1.20274
2023-02-27 11:00:00 :Stop @ >> 1.19574
2023-02-27 15:00:00 :Time: 02/27/2023 15:00:00 OrderID: 69 EventID: 3 Symbol: GBPUSD Status: Canceled Quantity: -10000 StopPrice: 1.19574
The following data has been taken from the Oanda platform (+ or - a few pips) on the 27th February at 11am. The platform is set to the timezone Utc (London), which should match the timezone set in the back test.
OANDA DATA:
pastFastEma >> 1.19596
pastSlowEma >> 1.19853
Current fast_EMA >> 1.19640
Current slow_EMA >> 1.19853
Long @ >> 1.19843
This indicates the price the trade is opened at is incorrect.
Regarding the logic: If (fastEMA > slowEMA) & (pastFastEma < pastSlowEma):
Based on the data provided by Oanda, (pastFastEma < pastSlowEma) is correct. However, (fastEMA > slowEMA) is NOT correct. Thus the trade should not have been executed.
I am not sure if this is a simple or complex fix, or if it is a bug. But any support would be much appreciated.
Thanks
Zubair Chaudhary
Louis Szeto
Hi Z C
The data in OnData method is the consolidated Hour bar, but not real time data. It represents the past hour’s price. Then it runs your trading logic and will not submit the trade until the next hour bar consolidated, then filled by the next data bar after that. Thus, I believe you‘ll need to subscribed to denser data like minute/second.
Best
Louis
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.
Z C
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!