Overall Statistics
Total Trades
343
Average Win
0.30%
Average Loss
-0.26%
Compounding Annual Return
0.037%
Drawdown
5.300%
Expectancy
0.004
Net Profit
0.056%
Sharpe Ratio
0.024
Probabilistic Sharpe Ratio
7.374%
Loss Rate
54%
Win Rate
46%
Profit-Loss Ratio
1.17
Alpha
0.001
Beta
-0.003
Annual Standard Deviation
0.033
Annual Variance
0.001
Information Ratio
-0.83
Tracking Error
0.134
Treynor Ratio
-0.274
Total Fees
$0.00
Estimated Strategy Capacity
$640000.00
Lowest Capacity Asset
EURUSD 8G
financial_instrument = "EURUSD"; period = 30; SL = 0.01; TP = 0.01;

class MeasuredSkyBlueWolf(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 10, 18)  
        self.SetCash(100000)
        res = Resolution.Daily
        self.financial_instrument = self.AddForex(financial_instrument, res).Symbol
        
        self.macd = self.MACD(financial_instrument, 12, 26, 9, MovingAverageType.Exponential, res)
        self.psar = self.PSAR(financial_instrument, 0.02, 0.02, 0.2, res)
        self.ema = self.EMA(financial_instrument, 20, res)
        self.SetWarmUp(period, res)


    def OnData(self, data):
        if self.IsWarmingUp : return
        if not self.psar.IsReady: return
        if not self.macd.IsReady: return
        if not self.ema.IsReady: return
    
        price = self.Securities[financial_instrument].Price
        uptrend = price > self.ema.Current.Value
        downtrend = price < self.ema.Current.Value
        pnl = self.Securities[financial_instrument].Holdings.UnrealizedProfitPercent
        
        self.Plot("macd ", "macd signal", self.macd.Signal.Current.Value)
        self.Plot("macd ", "macd", self.macd.Current.Value)
        
        self.Plot(financial_instrument, 'current price', price)
        self.Plot(financial_instrument, 'ema', self.ema.Current.Value)
        self.Plot(financial_instrument, 'sar', self.psar.Current.Value)
    
        if not self.Portfolio.Invested:
            if uptrend is True:
                if self.macd.Current.Value > self.macd.Signal.Current.Value and self.psar.Current.Value < price:
                    self.SetHoldings(financial_instrument, 1)
            elif downtrend is True:  
                if self.macd.Current.Value < self.macd.Signal.Current.Value and self.psar.Current.Value > price:
                    self.SetHoldings(financial_instrument, -1)
                    
        elif self.Portfolio.Invested:
            if pnl >= TP:
                self.Liquidate(financial_instrument, "Take Profit")
            elif pnl < SL:
                self.Liquidate(financial_instrument, "Stop Loss")