Overall Statistics
Total Trades
22
Average Win
4.64%
Average Loss
-0.42%
Compounding Annual Return
407.574%
Drawdown
4.800%
Expectancy
2.304
Net Profit
10.799%
Sharpe Ratio
8.825
Probabilistic Sharpe Ratio
88.124%
Loss Rate
73%
Win Rate
27%
Profit-Loss Ratio
11.11
Alpha
2.875
Beta
0.187
Annual Standard Deviation
0.31
Annual Variance
0.096
Information Ratio
6.362
Tracking Error
0.546
Treynor Ratio
14.623
Total Fees
$234.98
Estimated Strategy Capacity
$13000.00
Lowest Capacity Asset
MATICUSD 2S7
#region imports
from AlgorithmImports import *
#endregion
class MATICana_USD(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2022, 10, 20)  # Set Start Date
        self.SetEndDate(2022, 11, 11) #Set End Date
        self.SetCash(10000)  # Set Strategy Cash
        self.SetBrokerageModel(BrokerageName.BinanceUS, AccountType.Cash)
        
        crypto = self.AddCrypto("MATICUSD", Resolution.Hour, Market.BinanceUS)
        self.lot_size = crypto.SymbolProperties.LotSize
        self.symbol = crypto.Symbol

        self.sto = Stochastic(14, 1, 3)
        self.highestPrice = 0
        self.next_trade_time = datetime.min
        self.entryPrice = 0
        self.entryTicket = None
        self.month = 0

    
    def IsRebalanceDue(self, time):
        if time.month == self.month or time.month not in [1, 4, 7, 10]:
            return None
        
        self.month = time.month
        return time

    def OnData(self, data):
        if data.QuoteBars.ContainsKey(self.symbol):
            self.sto.Update(data.QuoteBars[self.symbol])
        if self.sto.IsReady:
            indicator_value = self.sto.Current.Value

        MATIC_stoch_k = self.sto.StochK.Current.Value
        MATIC_stoch_d = self.sto.StochD.Current.Value
        
        price = self.Securities[self.symbol].Price
        holding_quantity = self.Portfolio[self.symbol].Quantity
        invested = abs(self.Portfolio[self.symbol].Quantity) > self.lot_size
        if not invested and not self.Transactions.GetOpenOrders(self.symbol):
            if MATIC_stoch_d <= 15 and MATIC_stoch_d > 3 and self.Time > self.next_trade_time:
                quantity = self.CalculateOrderQuantity(self.symbol, 1)
                self.entryTicket = self.MarketOrder(self.symbol, quantity)
                self.entryPrice = price

        invested = abs(self.Portfolio[self.symbol].Quantity) > self.lot_size
        if invested:
            if MATIC_stoch_k >= 96 and MATIC_stoch_k < 105:
                self.MarketOrder(self.symbol, self.get_sell_quantity(0))
                self.next_trade_time = self.Time + timedelta(hours = 4)

            if price > self.highestPrice:
                self.highestPrice = price 
            
            if self.Securities[self.symbol].Price < (self.highestPrice * .95):
                self.MarketOrder(self.symbol, self.get_sell_quantity(0))
                self.next_trade_time = self.Time + timedelta(hours = 4)
    
    def get_sell_quantity(self, weight):
        return int(self.CalculateOrderQuantity(self.symbol, weight) / self.lot_size) * self.lot_size