Hi Vladimir I tried ur code and it was working great until this happened
It stared buying at the highest and selling at the lowest . I hope u can provide me with some answers.😊
and one more thing when I changed the BAR to 1 , the trades increased and became 1920 instead of 26 when the BAR was 60. Can u explain me why this affected the volumes of trade ?
CRYPTO = "USDCUSDT"; BAR = 1;
class BlackpantherFractal(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2022, 5, 1)
self.SetEndDate(2022, 5, 3)
self.SetCash("USDT", 1000)
self.crypto = self.AddCrypto(CRYPTO, Resolution.Minute, Market.Binance).Symbol
self.SetSecurityInitializer(lambda s: s.SetLeverage(1))
self.SetBrokerageModel(BrokerageName.Binance, AccountType.Margin)
self.Consolidate(self.crypto, timedelta(minutes = BAR), self.CustomBarHandler)
self.window = RollingWindow[TradeBar](3)
self.consolidator = TradeBarConsolidator(timedelta(minutes=BAR))
self.SubscriptionManager.AddConsolidator(self.crypto, self.consolidator)
self.SetWarmUp(BAR, Resolution.Minute)
def CustomBarHandler(self, bar):
if self.IsWarmingUp: return
self.window.Add(bar)
if not self.window.IsReady: return
H = [self.window[i].High for i in range(3)]
L = [self.window[i].Low for i in range(3)]
C = [self.window[i].Close for i in range(3)]
curr_price = self.Securities[self.crypto].Price
if not self.Portfolio[self.crypto].IsLong:
if ( curr_price <= L[1] <= L[2]):
self.SetHoldings(self.crypto,1)
elif not self.Portfolio[self.crypto].IsShort:
if ( curr_price >= H[1] >= H[2]):
self.SetHoldings(self.crypto,-1)
