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
Probabilistic 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
-7.481
Tracking Error
0.112
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
class HGMACD(QCAlgorithm):

    def Initialize(self):
        
        self.contract = None

        self.SetStartDate(2021, 10, 25)    #Set Start Date
        self.SetEndDate(2021, 10,29)      #Set End Date
        self.SetCash(5000)             #Set Strategy Cash
        self.SetWarmUp(TimeSpan.FromDays(3)) # Set warm up
        # Subscribe and set our expiry filter for the futures chain
        futureHG = self.AddFuture(Futures.Metals.Copper)
        futureHG.SetFilter(0, 182)
        self.Contracts = {}
        
    def OnData(self, slice):
        
        for chain in slice.FutureChains:
            contracts = [contract for contract in chain.Value]
            if len(contracts) == 0:
                self.oi_contract = None
                self.macd = None
                break
            
            self.popularContracts = [contract for contract in chain.Value] #if contract.OpenInterest > 1000]
 
            if len(self.popularContracts) == 0:
                continue
            
            contract = sorted(self.popularContracts, key=lambda k : k.OpenInterest, reverse=True)
            self.liquidContract = contract[0]
            contract = contract[0]
            if contract.Symbol not in self.Contracts:
                on512T = TradeBarConsolidator(512)
                
                self.SubscriptionManager.AddConsolidator(contract.Symbol, on512T)
                self.macd = MovingAverageConvergenceDivergence(12, 26, 9, MovingAverageType.Exponential)
                self.RegisterIndicator(contract.Symbol, self.macd, on512T)
                self.Contracts[contract.Symbol] = self.macd
                
            macd = self.Contracts[contract.Symbol]
            
            if (macd != None and macd.IsReady):
             if bar.Symbol == contract.Symbol:
                tolerance = 0.00
                signalDeltaPercent = (macd.Current.Value - macd.Signal.Current.Value)/macd.Fast.Current.Value
                
                if signalDeltaPercent < -tolerance:
                #if self.macd.Current.Value < 0
                #Go long
                    self.SetHoldings(contract.Symbol, 1)

                elif signalDeltaPercent > tolerance:
            #if self.macd.Current.Value > 0
            #Go short
                    self.SetHoldings(contract.Symbol, -1)
            
                else:
                    self.Liquidate
            else:
              self.Log('MACDs not ready yet')