Hello everyone
Today I tried to bring my algorithm from one day timeframe to a 4 hour timeframe. Unfortunately I didn't make it and the documentation didn't help me either.
So my question would be whether someone can help me with my algorithm to get a 4h timeframe.
Do you only have to do this consolidation for the equity or do you have to do it again for the indicator?
I hope someone can help me!
Thanks
Marcel
Vladimir
Marcel Friz
It is not clear either you want to check conditions every 4 Hours or you need to calculate simple moving average based on 4 Hour bar?
Vladimir
Marcel Friz
"Price - Moving Average(4 Hour bar) Cross" checks conditions at 10 and 14.
Is this what you are looking for?
Marcel Friz
Hi Vladimir,
Thanks for your support!
I would like my algorithm to be based on a period of 4 hours. I don't want to check the conditions at a certain time.
Therefore the indicators should be calculated on a 4h basis. And this is one of my questions is it possible to create a 4hour SMA without consolidating the equity to 4hour, so is it possible only creating a 4hour SMA?
So it is the second suggestion from you that I want to reach: you need to calculate SMA based on 4hours bar.
If I am right, you have the solution in your last backtest, if it’s so, please give me a short feedback that I can accept the answer.
Thanks Vladimir for your effort!
Fred Painchaud
Hi Marcel,
If you remove the line:
from the algo, you will have your algo without the time constraint on trades…
F
Fred Painchaud
Hi Marcel,
I don't see a link to edit a previous post so I post again to include the backtest (I also want to test backtest inclusions 😊).
F
Vladimir
Marcel Friz,
"Price - Moving Average(4 Hour bar) Cross" subscribed to Hour data
self.stock = self.AddEquity(STOCK, Resolution.Hour).Symbol
self.bond = self.AddEquity(BOND, Resolution.Hour).Symbol
Than data consolidated to 4 Hour bar
Consolidator = TradeBarConsolidator(timedelta(hours = 4))
self.SubscriptionManager.AddConsolidator(self.stock, consolidator)
Than Simple Moving Average calculated using consolidated 4 Hour bar data.
self.sma = SimpleMovingAverage(MA)
self.RegisterIndicator(self.stock, self.sma, consolidator)
As there may be no more than 2 4 Hour bars during Equity trading session I limit trading to 10 and 14.
if not(self.Time.time() == time(10) or self.Time.time() == time(14)): return
but you can change it to 11 and 15 or 12 and 16.
If you will remove that line than algorithm will check conditions and Plot self.sma every Hour.
In this case you need to adjust start date as there is limit 4000 data points for plotting indicators.
Enjoy
Vladimir
Marcel Friz,
Here is "Price - Moving Average(4 Hour bar) Cross"
With check conditions and Plot self.sma every Hour.
Marcel Friz
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!