Overall Statistics
Total Trades
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Net Profit
0%
Sharpe Ratio
0
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0
Beta
0
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
from collections import deque
from datetime import datetime


class BitfinexTest(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019,3,1)  # Set Start Date
        self.SetEndDate(2019,3,5)
        self.SetCash(10000)  # Set Strategy Cash
        
        self.SetBrokerageModel(BrokerageName.Bitfinex, AccountType.Margin)
        
        self.AddCrypto('BTCUSD', Resolution.Minute)
        self.SetBenchmark("BTCUSD")
        self.SetTimeZone(TimeZones.Utc)

        self.slowperiod = 60
        
        self.qprice = deque(maxlen=5)
        self.qsma = deque(maxlen=5)
        self.qatr = deque(maxlen=5)
        
        self.warmupfinished = False
        self.consolidated5min = False
        
        consolidator = QuoteBarConsolidator(5)
        consolidator.DataConsolidated += self.OnDataConsolidated
        self.SubscriptionManager.AddConsolidator('BTCUSD',consolidator)
        
        self.slowsma = SimpleMovingAverage(self.slowperiod)
        self.atrmin = AverageTrueRange(14)

        self.RegisterIndicator('BTCUSD', self.slowsma, consolidator)
        self.RegisterIndicator('BTCUSD', self.atrmin, consolidator)

        
        cryptoPlot = Chart('Crypto Plot')
        cryptoPlot.AddSeries(Series('Price', SeriesType.Line, 0))
        cryptoPlot.AddSeries(Series('atr', SeriesType.Line, 1))
        cryptoPlot.AddSeries(Series('smaslow', SeriesType.Line, 0))
        self.AddChart(cryptoPlot)
        
        self.SetWarmUp(timedelta(self.slowperiod+2))
 
    def OnData(self, data):
        #OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
        if not data.ContainsKey("BTCUSD"): self.Debug("No Data record for BTCUSD"); return
              #self.qprice.appendleft(data['BTCUSD'].Close)
              #if self.slowsma.IsReady: self.qsma.appendleft(self.slowsma.Current.Value)
              #if self.atrmin.IsReady: self.qatr.appendleft(self.atrmin.Current.Value)
        if self.IsWarmingUp or self.consolidated5min == False: return
        if self.warmupfinished == False:
            self.Log(f"qprice: {self.qprice}")
            self.Log(f"qsma: {self.qsma}")
            self.Log(f"qatr: {self.qatr}")
            self.warmupfinished = True
        if self.Time.minute <= 5 and self.Time.hour % 6 == 0:
            self.Plot('Crypto Plot', 'Price', data['BTCUSD'].Close)
            self.Plot('Crypto Plot', 'atr', self.qatr[0])
            self.Plot('Crypto Plot', 'smaslow', self.slowsma.Current.Value)

    def OnDataConsolidated(self,sender,bar):
        if not self.IsWarmingUp: self.consolidated5min = True
        self.qprice.appendleft(bar.Close)
        self.qsma.appendleft(self.slowsma.Current.Value)
        self.qatr.appendleft(self.atrmin.Current.Value)