Hi,
I am trying a simple inside day breakout strategy that is running on a different platform currently. (Disclaimer: I am new here with very limited coding knowledge. Any questions posted with obvious answers are purely out of desperation after many failed attempts. Please be kind, I will get there one day... ) In plain English, here is the idea:
- check data for inside day H[0] < H[1] and L[0] > L[1]
- store range of inside day (insideRange = H-L)
- ignore Sundays due to limited data (using daily data but would it be better to consolidate hourly into a daily bar?)
- place buy stop and sell stop at H and L with a limit at H + insideRange and L - insideRange
- position size is calculated as (cash * risk percentage * close) / insideRange to covert JPY back to USD
- orders remain valid until triggered or replaced with a new one (in case of another inside day)
Sounds pretty simple but a couple of challenges I can't work out. I created a log for inside days and comparing with other chart data, there is no inside day on some of the days the log fires a notification. Order execution also seems incorrect with entry orders being triggered in both directions (is this because of the daily data I am using?).
I really appreciate any help with this as on the n-th iteration and still nowhere closer than at the beginning...
Thanks
Derek Melchin
Hi Heiko,
Welcome to QC!
It appears to trigger invalid signals because we need to align the timestamps of the data passed to the backtester and the data retreived in the research notebook. To align the timestamps, we need to set the `x` argument of our Candlestick figure to
[d.date() + timedelta(days=1) for d in spy_hist.index]
so that it reads
fig = go.Figure(data=[go.Candlestick(x=[d.date() + timedelta(days=1) for d in spy_hist.index], open=spy_hist['open'], high=spy_hist['high'], low=spy_hist['low'], close=spy_hist['close'])], layout=go.Layout( title=go.layout.Title(text='JPY OHLC'), xaxis_title='Date', yaxis_title='Price', xaxis_rangeslider_visible=False ))
See the attached backtest for reference.
For assistance setting TP and SL orders, refer to this thread. We recommend using a high resolution than daily when using these types of orders.
Best,
Derek Melchin
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.
Heiko Mueller
Thanks for your explanation Derek. When using a higher timeframe would you suggest to use two diferrent resolutions (one for signal generation, one for tading) or consolidating a higher timeframe into daily bars with
self.Consolidate("USDJPY", Resolution.Daily, self.OnDataConsolidated) and
def OnDataConsolidated(self, bar):
self.window.Add(bar)
or self.Consolidate("USDJPY", Resolution.Daily, lambda x: self.window.Add(x))
Thanks again
Derek Melchin
Hi Heiko,
We don't advise subscribing to more than one resolution per symbol. Consolidating the data from a higher resolution is recommended.
Best,
Derek Melchin
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.
Heiko Mueller
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!