Overall Statistics
Total Trades
231
Average Win
2.50%
Average Loss
-3.37%
Compounding Annual Return
19.846%
Drawdown
29.200%
Expectancy
0.119
Net Profit
43.702%
Sharpe Ratio
0.603
Probabilistic Sharpe Ratio
25.025%
Loss Rate
36%
Win Rate
64%
Profit-Loss Ratio
0.74
Alpha
0.159
Beta
0.026
Annual Standard Deviation
0.267
Annual Variance
0.071
Information Ratio
0.265
Tracking Error
0.29
Treynor Ratio
6.147
Total Fees
$0.00
import numpy as np
### <summary>
### Basic template algorithm simply initializes the date range and cash. This is a skeleton
### framework you can use for designing an algorithm.
### </summary>
class BasicTemplateAlgorithm(QCAlgorithm):
    '''Basic template algorithm simply initializes the date range and cash'''
    def Initialize(self):
        self.SetStartDate(2017,7, 31)  #Set Start Date
        self.SetEndDate(2019,7,31)    #Set End Date
        self.SetCash(5000)           #Set Strategy Cash
        
        #This algorithm trades EURGBP on the Hour Resolution
        self.AddForex("EURGBP", Resolution.Hour, Market.Oanda)
        self.SetBrokerageModel(BrokerageName.OandaBrokerage) 
        
        #We add our RSI 14 period indicator
        self.rsi = self.RSI("EURGBP", 14)
        
        #pointer to keep track of last bar's RSI Value
        self.lastrsi = None
        
    def OnData(self, data):
        #Make sure our indicator is ready before we can use it
        if not self.rsi.IsReady: 
            return
        
        #Make sure there is a past RSI value to compare to
        if self.lastrsi is None:
            self.lastrsi = self.rsi.Current.Value
            return 
        
        #If we cross oversold threshold from below
        if self.lastrsi < 30 and self.rsi.Current.Value > 30:
            
            #if we are not currently in a trade
            if not self.Portfolio["EURGBP"].Invested:
                 #we place a long market order
                 self.SetHoldings("EURGBP", 5)
                 
        #If RSI is oversold while we are short        
        elif self.rsi.Current.Value < 30 and self.Portfolio["EURGBP"].IsShort:
            # if we are already in a short trade we liquidate
            self.Liquidate()
                     
        #if RSI signals overbought
        if self.lastrsi > 70 and self.rsi.Current.Value < 70:
            
            if not self.Portfolio["EURGBP"].Invested:
                 #enter short position
                 self.SetHoldings("EURGBP", -5)
        
        #if RSI is overbought while we are long       
        elif self.rsi.Current.Value > 70 and self.Portfolio["EURGBP"].IsLong:
            #if we already in a long trade we liquidate 
            self.Liquidate()
        
        #store current RSI value to use later
        self.lastrsi = self.rsi.Current.Value