Overall Statistics
Total Trades
106
Average Win
2.00%
Average Loss
-1.14%
Compounding Annual Return
-9.383%
Drawdown
16.700%
Expectancy
-0.114
Net Profit
-7.535%
Sharpe Ratio
-0.467
Loss Rate
68%
Win Rate
32%
Profit-Loss Ratio
1.76
Alpha
-0.03
Beta
-0.194
Annual Standard Deviation
0.146
Annual Variance
0.021
Information Ratio
-1.3
Tracking Error
0.205
Treynor Ratio
0.352
Total Fees
$0.00
class HeikinCashi(QCAlgorithm):

    def Initialize(self):

        # Set our main strategy parameters
        self.SetStartDate(2019,1,2)
        self.SetCash(200)
        self.SetBrokerageModel(BrokerageName.OandaBrokerage)
        self.SetTimeZone( "Europe/Berlin" );

        # Direction current position
        self.CP_D = "None"
        
        self.HK_PS = "None"
        self.HK_S = "None"

        self.Currencies = ["AUDUSD"]
        
        self.HK = dict() # Create dict to hold all our HK Indicators
        self.MO = dict() # Create dict to hold all our MO Indicators

        for Currency in self.Currencies:
            # Find more symbols here: http://quantconnect.com/data
            self.AddForex(Currency, Resolution.Daily, Market.Oanda)
            self.HK[Currency] = self.HeikinAshi(Currency, Resolution.Daily)
            self.MO[Currency] = self.MOM(Currency, 10, Resolution.Daily)

            self.Schedule.On(self.DateRules.Every(DayOfWeek.Friday), \
                             self.TimeRules.BeforeMarketClose(Currency, 60), \
                             self.EveryFridayBeforeMarketClose)

    def OnData(self, data):

        for Currency in self.Currencies:
            
            # Aliases
            # -----------------------------------------------------------------
            
            # Heikin
            HK_O = self.HK[Currency].Open.Current.Value
            HK_C = self.HK[Currency].Close.Current.Value
            HK_P = self.HK[Currency].Current.Price
            
            # OHLC
            O = data[Currency].Open
            C = data[Currency].Close
            P = data[Currency].Price
            
            # Momentum
            MO_D = self.MO[Currency].Current.Value
            
            # -----------------------------------------------------------------
           
            # Work out Heikin Sentiment
            # ---------------------------------------
            self.HK_PS = self.HK_S

            if HK_O < HK_C:
                self.HK_S = "Bull" 
            elif HK_O > HK_C:
                self.HK_S = "Bear"
            else:
                self.HK_S = "None"
                
            # Logging
            # -----------------------------------------------------------------
            
            #self.Log("{0} OC       >> O: {1}, C:{2} | Price: {3}".format(Currency, O,C,P))
            #self.Log("{0} Heikin   >> O: {1}, C:{2} | Price: {3} | Sentiment: {4}".format(Currency, HK_O,HK_C,HK_P,HK_S))
            
            # Entry / Exit Criteria
            # -----------------------------------------------------------------
            
            # Check if we are in the market
            if not self.Portfolio.Invested:
                
                # If not, we check HK sentiment is bullish
                if self.HK_S == "Bull" and self.HK_S == self.HK_PS and MO_D > 0:
                    self.MarketOrder(Currency, 1000, False, "Long")
                    self.CP_D = "Bull"
                    #self.Log("{0} Momentum >> {1}".format(Currency, MO_D))
                elif self.HK_S == "Bear" and self.HK_S == self.HK_PS and MO_D < 0:
                    self.MarketOrder(Currency, -1000, False, "Short")
                    self.CP_D = "Bear"
                    #self.Log("{0} Momentum >> {1}".format(Currency, MO_D))
            else:
                #self.Log("{0} Profit: {1} {2}".format(Currency, self.Portfolio[Currency].UnrealizedProfit, self.HK_S))
                if self.CP_D != self.HK_S:
                    self.Log("{0} Realized Profit: {1} {2}".format(Currency, self.Portfolio[Currency].UnrealizedProfit, self.HK_S))
                    self.Liquidate(Currency)

    # Override the base class event handler for order events
    def OnOrderEvent(self, orderEvent):
        order = self.Transactions.GetOrderById(orderEvent.OrderId)
        self.Debug("{0}: {1}".format(order.Type, orderEvent))
        if self.CP_D == "Bull" and order.Status == OrderStatus.Filled:
            self.CP_D = "None"
        if self.CP_D == "Bear" and order.Status == OrderStatus.Filled:
            self.CP_D = "None"

    def EveryFridayBeforeMarketClose(self):
        self.Liquidate()