Overall Statistics
Total Trades
2
Average Win
0%
Average Loss
-0.65%
Compounding Annual Return
-9.799%
Drawdown
3.900%
Expectancy
-1
Net Profit
-0.649%
Sharpe Ratio
3.426
Probabilistic Sharpe Ratio
92.066%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.025
Beta
0.001
Annual Standard Deviation
0.007
Annual Variance
0
Information Ratio
1.341
Tracking Error
0.568
Treynor Ratio
29.49
Total Fees
$19.87
Estimated Strategy Capacity
$8000.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.SetAccountCurrency("USD")
        self.SetCash(10000)  # Set Strategy Cash
     
        self.SetBrokerageModel(BrokerageName.BinanceUS, AccountType.Cash)
        

        self.symbol = self.AddCrypto("MATICUSD", Resolution.Hour, Market.BinanceUS).Symbol
        

        self.sto = Stochastic(14, 1, 3)
       
        



        #self.sto = self.Stochastic("SOLUSD", 14, 1, 3, Resolution.Hour)
        #closing_prices = self.History(self.symbol, 14, Resolution.Hour)["close"]
        #for time, price in closing_prices.loc[self.symbol].items():
        #    self.rsi.Update(time, price)





        
        
    


    

        chart = Chart("My Indicators")
        #chart.AddSeries(Series('faststoch', SeriesType.Line, "0"))
        chart.AddSeries(Series('MATIC stochk', SeriesType.Line, "0"))
        chart.AddSeries(Series('MATIC stochd', SeriesType.Line, "0"))
        chart.AddSeries(Series('MATIC stochastic', SeriesType.Line, "0"))
        #chart.AddSeries(Series('Price', SeriesType.Line, "0"))
        
        
        
        self.highestPrice = 0
        
        
        
        self.AddChart(chart)
       


        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):

        self.PlotIndicator()

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



        
        #SOL_fast_stoch = self.sto.FastStoch.Current.Value
        MATIC_stoch_k = self.sto.StochK.Current.Value
        MATIC_stoch_d = self.sto.StochD.Current.Value
        
        
        

        
        price = self.Securities[self.symbol].Price
       
        


        if not self.Portfolio[self.symbol].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("MATICUSD", 1)
                self.Log("MATIC order quantity set")
                self.Log("MATIC buy Order @ >> {0}".format(self.Securities["MATICUSD"].Price))
                self.Log("MATIC buy stoch D @ >> {0}".format(self.sto.StochD.Current.Value))
                self.entryTicket = self.MarketOrder("MATICUSD", quantity)
                self.entryPrice = price




                

        if self.Portfolio[self.symbol].Invested:
            if MATIC_stoch_k >= 96 and MATIC_stoch_k < 105:  
                self.Log("MATIC price liquidate @ >> {0}".format(self.Securities["MATICUSD"].Price))
                self.Log("MATIC sell stoch @ >> {0}".format(self.sto.StochK.Current.Value))
                self.Liquidate("MATICUSD")
                self.next_trade_time = self.Time + timedelta(hours = 4)
        

               
                
            if price > self.highestPrice:
                self.highestPrice = price 
            
            if self.Securities["MATICUSD"].Price < (self.highestPrice * .95):
                self.Liquidate("MATICUSD")
                self.next_trade_time = self.Time + timedelta(hours = 4)
                self.Log("MATIC stop loss triggered")



                
        
        
                
        


    def PlotIndicator(self):
       #self.Plot("My Indicators", "faststoch", self.sto.FastStoch.Current.Value)
       self.Plot("My Indicators", "MATIC stochk", self.sto.StochK.Current.Value)
       self.Plot("My Indicators", "MATIC stochd", self.sto.StochD.Current.Value)
       self.Plot("My Indicators", "MATIC Price", self.Securities["MATICUSD"].Price)


        
    #def ExitPositions(self):
        #self.Liquidate(self.uvxy)
        #self.Log(f"30 min before close on Friday: Fired at: {self.Time}")

    def OnBrokerageDisconnect(self) -> None:
        self.Debug("Brokerage connection lost")

    def OnBrokerageReconnect(self) -> None:
        self.Debug("Brokerage connection restored")