Overall Statistics
Total Trades
65
Average Win
0.02%
Average Loss
0.00%
Compounding Annual Return
0.567%
Drawdown
0.100%
Expectancy
6.593
Net Profit
0.161%
Sharpe Ratio
2.045
Loss Rate
69%
Win Rate
31%
Profit-Loss Ratio
23.30
Alpha
0.004
Beta
-0.004
Annual Standard Deviation
0.002
Annual Variance
0
Information Ratio
-0.753
Tracking Error
0.118
Treynor Ratio
-0.894
Total Fees
$0.00
import numpy as np
from decimal import Decimal

class VerticalResistanceFlange(QCAlgorithm):
    
    stopMarketTicket = None
    limitTicket = None

    def Initialize(self):
        
        self.SetStartDate(2018, 3, 23) 
        self.SetEndDate(2018, 7, 4)
        self.SetCash(100000)  
        

        self.uj = self.AddForex("USDJPY", Resolution.Minute, Market.Oanda)
        self.usdjpy = self.AddForex("USDJPY").Symbol

        self.SetBrokerageModel(BrokerageName.OandaBrokerage)
        
        self.SetWarmUp(240, Resolution.Minute)
        
        self.rsi = self.RSI("USDJPY", 10,  MovingAverageType.Simple, Resolution.Minute)
        self.ich = self.ICHIMOKU("USDJPY", 9, 26, 52, 52, 26, 26, Resolution.Minute)
        self.RegisterIndicator("USDJPY", self.rsi, Resolution.Minute)
        self.RegisterIndicator("USDJPY", self.ich, Resolution.Minute)
        
        self.UniverseSettings.Resolution = Resolution.Minute

    def OnData(self, data):
        
        if self.IsWarmingUp:
                return
            
        for key in data.Keys:
            self.Log(str(key.Value) + ": " + str(data.Time) + " > " + str(data[key].Value))
            
            
        #Set individual variables for ICHIMOKU indicator values (Tenkan, Kijun, Senkou) and RSI 
        ichT = self.ich.Tenkan.Current.Value
        ichK = self.ich.Kijun.Current.Value
        ichSA = self.ich.SenkouA.Current.Value
        ichSB = self.ich.SenkouB.Current.Value
        
        rsi_value = self.rsi.Current.Value
        
        if not self.Portfolio.Invested:
        ##If "Tenkan" lines meet and RSI is between 15 and 45, short
            if round(ichT, 3) == round(ichK, 3) and rsi_value < 45.0 and rsi_value > 15.0:
                self.Debug("Tenkan Kijun intersection. Short.")
                self.Debug("Tenkan = " + str(ichT) + " Kijun = " + str(ichK))
                self.Debug("RSI Value: " + str(rsi_value))
                #Set amount of portfolio to venture
                self.amount = self.Portfolio.Cash * 0.04
                #Order pair, set stops, print values
                self.marketTicket = self.MarketOrder("USDJPY", -self.amount)
                self.price = data[self.usdjpy].Close
                self.Debug(str(self.price))
                self.stopPrice = self.price * 1.01
                self.limitPrice = self.price * 0.994
                self.Debug("Limit price, short: " + str(self.limitPrice))
                self.stopMarketTicket = self.StopMarketOrder("USDJPY", self.amount, self.stopPrice)
                self.limitTicket = self.StopMarketOrder("USDJPY", self.amount, self.limitPrice)
                self.Debug("Short order triggered per Ichimoku! For " + str(self.price))
        ##If "Tenkan" lines meet and RSI is between 30 and 80, long        
            elif round(ichT, 3) == round(ichK, 3) and rsi_value < 80.0 and rsi_value > 30.0:
                self.Debug("Tenkan Kijun intersection. Long.")
                self.Debug("Tenkan = " + str(ichT) + " Kijun = " + str(ichK))
                self.Debug("RSI Value: " + str(rsi_value))
                self.amount = self.Portfolio.Cash * 0.04
                self.marketTicket = self.MarketOrder("USDJPY", self.amount)
                self.price = data[self.usdjpy].Close
                self.Debug(str(self.price))
                self.stopPrice = self.price * 0.996
                self.limitPrice = self.price * 1.006
                self.Debug("Limit price, long: " + str(self.limitPrice))
                self.stopMarketTicket = self.StopMarketOrder("USDJPY", -self.amount, self.stopPrice)
                self.limitTicket = self.LimitOrder("USDJPY", -self.amount, self.limitPrice)

                self.Debug("Long order triggered per Ichimoku! For " + str(self.price))

    def OnOrderEvent(self, orderEvent):
        #"One cancels the other" implementation for take profit / stop loss
        if self.IsWarmingUp:
                return
        if self.stopMarketTicket is not None and self.stopMarketTicket.Status == OrderStatus.Filled: 
            self.Debug("Stop Market hit! For " + str(self.Securities["USDJPY"].Price))
            self.limitTicket.Cancel()
            self.stopMarketTicket = None
        if self.limitTicket is not None and self.limitTicket.Status == OrderStatus.Filled:
            self.Debug("Take Profit hit! For " + str(self.Securities["USDJPY"].Price))
            self.stopMarketTicket.Cancel()
            self.limitTIcket = None


                

# Your New Python File