Hello all! I wrote this simple also trying to backtest breakouts with different variations of volume divergence from the mean of the current bar as a confirmation but I am making a mistake and have exhausted my resources trying to figure out what I'm doing wrong. As always thank you to everyone in the community for all the help so far, I appreciate it! I have attached my code here below,
# region imports
from AlgorithmImports import *
# endregion
class SleepyBlueSeahorse(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2010, 1, 1)
self.SetEndDate(2011, 1, 1)
self.SetCash(100000)
self.AddEquity("SPY", Resolution.Minute)
self.tradeBarWindow = RollingWindow[TradeBar](2)
self.ema = self.EMA("SPY", 30, MovingAverageType.Exponential, Resolution.Minute, Field.Volume)
self.max = self.MAX("SPY", 1, Resolution.Daily)
self.min = self.MIN("SPY", 1, Resolution.Daily)
self.Schedule.On(self.DateRules.EveryDay("SPY"),
self.TimeRules.BeforeMarketClose("SPY", 10),
self.EveryDayBeforeMarketClose)
self.SetWarmup(timedelta(days=2))
def OnData(self, data: Slice):
if self.IsWarmingUp:
return
self.tradeBarWindow.Add(data["SPY"])
price = self.Securities["SPY"].Price
if not self.tradeBarWindow.IsReady:
return
if self.Time.hour >= 10 and self.Time.hour < 13 and not self.Portfolio.Invested:
if price > self.max.Current.Value and self.tradeBarWindow[1].Close < self.max.Current.Value:
if data["SPY"].Volume > self.ema.Current.Value:
self.MarketOrder("SPY", 100)
if price < self.min.Current.Value and self.tradeBarWindow[1].Close > self.min.Current.Value:
if data["SPY"].Volume > self.ema.Current.Value:
self.MarketOrder("SPY", -100)
def EveryDayBeforeMarketClose(self):
self.Liquidate()
Vladimir
AegeanFutures
Here is your algorithm with some modifications. I hope on helps to solve the problem.
If you are satisfied with my answer, please accept it and don't forget to like it
AegeanFutures
Vladimir, thank you for getting back to me so quickly and all of the help I've gotten from you in my time here on QC.
What I want this algorithm to do is to firstly check if the current bars price is greater that the highest price of the previous days high or lower than the low. Then it should check to make sure the previous one minute bar was inside the range of the previous day. Finally the confirmation to take the trade is the breakout bar, current bar printing outside of the range, having a multiple higher volume than the moving average of volume on the one minute bar time period. I tweaked what you sent me a bit but am getting an error saying the NONE TYPE object, my tradebarwindow doesn't have the attribute close, high or low.
Can you tell me what it is I'm missing . I ran the code on the time period you have in your original implementation of this and it didn't give me the error. Also I would appreciate you taking a look at how I've implemented my trading logic to make sure I am actually analyzing the data as I've stated above I'm trying too. Here is my code with the edits , Best Regards
Vladimir
AegeanFutures
Here is another algorithm with my attempts to solve most of your request
What I want this algorithm to do is to firstly check if the current bars price
is greater that the highest price of the previous minute high or lower than the low.
if price >= self.PrevHighM.Current.Value:
if price < self.PrevLowM.Current.Value:
Then it should check to make sure the previous one minute bar was inside the
range of the previous day.
if self.PrevHighM.Current.Value < self.PrevHighD.Current.Value:
if self.PrevLowM.Current.Value > self.PrevLowD.Current.Value:
Finally the confirmation current bar, having a multiple higher volume than the
moving average of volume on the one minute bar time period.
if vmar > MULT:
If you are satisfied with my answer, please accept it and don't forget to like it
AegeanFutures
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!