Overall Statistics
Total Trades
135
Average Win
3.05%
Average Loss
-1.67%
Compounding Annual Return
4.462%
Drawdown
24.600%
Expectancy
0.263
Net Profit
57.657%
Sharpe Ratio
0.403
Loss Rate
55%
Win Rate
45%
Profit-Loss Ratio
1.82
Alpha
0.037
Beta
0.235
Annual Standard Deviation
0.101
Annual Variance
0.01
Information Ratio
0.241
Tracking Error
0.101
Treynor Ratio
0.173
Total Fees
$0.00
class Crossing(QCAlgorithm):
    '''Basic template algorithm simply initializes the date range and cash'''

    def Initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''

        self.SetTimeZone("Africa/Douala")
        self.SetStartDate(2009,1, 1)  #Set Start Date
        self.SetEndDate(2019,6, 3)    #Set End Date
        self.SetCash(1000)         #Set Strategy Cash


        self.ProfitTarget = None
        self.StopLoss = None


        # Find more symbols here: http://quantconnect.com/data
        self.eurusd = self.AddForex("EURUSD", Resolution.Daily)
        
        self.window = RollingWindow[QuoteBar](53)

        self.ichi = self.ICHIMOKU("EURUSD", 9, 26, 26, 52, 26, 26, Resolution.Daily)

        self.ichi.Updated += self.ichiUpdated

        self.ichiWin = RollingWindow[IndicatorDataPoint](2)
        
    def ichiUpdated(self, sender, updated):
        '''Adds updated values to rolling window'''
        self.ichiWin.Add(updated)

    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.

        Arguments:
            data: Slice object keyed by symbol containing the stock data
        '''
        if data.ContainsKey("EURUSD"):
            self.window.Add(data["EURUSD"])
    
            # Wait for windows to be ready.
    
            if not (self.window.IsReady and self.ichi.IsReady): return
        
            currBar = self.window[0]
            prev1 = self.window[1]
            self.Debug("Price: {0} -> {1} ... {2} -> {3}".format(
                prev1.Time, prev1.Low,
                currBar.Time, currBar.Low
                )
            )
            
            #self.Debug(str(self.ichi.Tenkan)+" "+str(self.ichi.Kijun))
            
            sl = min([currBar.Low, prev1.Low])
            tp = currBar.Open + ((prev1.Close - sl) * 1.5)

            self.Debug("Prev open {} kijun {} prev close {}".format(prev1.Open, self.ichi.Kijun, prev1.Close))
    
            self.Debug("Tenken {}, Kijun {}, Senkoua {} and SenkouB {}".format(self.ichi.Tenkan, self.ichi.Kijun, self.ichi.SenkouA, self.ichi.SenkouB))

            if not self.Portfolio.Invested:
                if prev1.Open < self.ichi.Kijun.Current.Value and prev1.Close > self.ichi.Kijun.Current.Value:
                    self.Debug("OK ooh")
                    self.MarketOrder("EURUSD", 2000)
                    self.ProfitTarget = self.LimitOrder("EURUSD", -2000, round(tp, 5))
                    self.StopLoss = self.StopMarketOrder("EURUSD", -2000, round(sl, 5))
    
    
    def OnOrderEvent(self, orderEvent):

        if not self.StopLoss or not self.ProfitTarget: return;

        filledOrderId = orderEvent.OrderId

        if self.StopLoss.OrderId == filledOrderId:
            self.ProfitTarget.Cancel()

        if self.ProfitTarget.OrderId == filledOrderId:
            self.StopLoss.Cancel()