Overall Statistics
Total Trades
705
Average Win
1.40%
Average Loss
-2.32%
Compounding Annual Return
152.960%
Drawdown
33.800%
Expectancy
0.102
Net Profit
326.600%
Sharpe Ratio
2.699
Probabilistic Sharpe Ratio
83.832%
Loss Rate
31%
Win Rate
69%
Profit-Loss Ratio
0.60
Alpha
1.453
Beta
-0.134
Annual Standard Deviation
0.529
Annual Variance
0.28
Information Ratio
2.066
Tracking Error
0.599
Treynor Ratio
-10.651
Total Fees
$0.00
class DynamicUncoupledPrism(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 1, 1)  # Set Start Date
        self.SetCash(1000)  # Set Strategy Cash
        self.symbol = "EURUSD"
        
        # Add forex and set brokerage model
        self.AddForex(self.symbol, Resolution.Minute, Market.Oanda, True, 50)
        self.SetBrokerageModel(BrokerageName.OandaBrokerage) 
        
        # Setup indicators
        self.rsi = RelativeStrengthIndex(self.symbol, 6)
        
        # Setup bar consolidator
        thirtyMinuteConsolidator = QuoteBarConsolidator(timedelta(minutes=30))
        self.SubscriptionManager.AddConsolidator(self.symbol, thirtyMinuteConsolidator)
        self.RegisterIndicator(self.symbol, self.rsi, thirtyMinuteConsolidator)
        
        # Setup window
        self.rsiWindow = RollingWindow[float](5)


    def OnData(self, data):
        self.rsiWindow.Add(self.rsi.Current.Value)
        
        # Wait for rsi
        if not self.rsi.IsReady:
            return
        
        # Define the signals
        should_buy = self.rsi.Current.Value < 30 and self.rsiWindow[1] > 30
        should_short = self.rsi.Current.Value > 70 and self.rsiWindow[1] < 70
        
        is_long = self.Portfolio[self.symbol].IsShort == False
        is_short = self.Portfolio[self.symbol].IsShort
        is_invested = self.Portfolio[self.symbol].Invested
        
        number_to_invest = 40000 # self.Portfolio.TotalPortfolioValue * 30
        
        if is_invested == False:
            if should_buy:
                self.MarketOrder(self.symbol, number_to_invest / 2)
            if should_short:
                self.MarketOrder(self.symbol, -number_to_invest / 2)
        else:
            if should_buy and is_short:
                self.MarketOrder(self.symbol, number_to_invest)
            if should_short and is_long:
                self.MarketOrder(self.symbol, -number_to_invest)
            
        # self.Debug("IS_INVESTED: " + str(is_invested))
        # self.Debug("IS_LONG: " + str(is_long))
        # self.Debug("IS_SHORT: " + str(is_short))
        # self.Debug("SHOULD LONG: " + str(should_buy))
        # self.Debug("SHOULD EXIT LONG: " + str(should_exit_buy))
        # self.Debug("SHOULD SHORT: " + str(should_sell))
        # self.Debug("SHOULD EXIT SHORT: " + str(should_exit_sell))
        # self.Debug(data.Bars[self.symbol].EndTime)
        # self.Debug("OPEN: " + str(data.Bars[self.symbol].Open))
        # self.Debug("HIGH: " + str(data.Bars[self.symbol].High))
        # self.Debug("LOW: " + str(data.Bars[self.symbol].Low))
        # self.Debug("CLOSE: " + str(data.Bars[self.symbol].Close))