Overall Statistics
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)
        
    def OnData(self, data):
        #Make sure our indicator is ready before we can use it
        if not self.rsi.IsReady: 
            return
        
        #If RSI signals oversold
        if 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)
                 
            else:
                # if we are already in a short trade we liquidate
                 if self.Portfolio["EURGBP"].IsShort:
                     self.Liquidate()
                     
        #if RSI signals overbought
        if self.rsi.Current.Value > 70:
            
            if not self.Portfolio["EURGBP"].Invested:
                 #enter short position
                 self.SetHoldings("EURGBP", -5)
                
            else:
                #if we already in a long trade we liquidate 
                 if self.Portfolio["EURGBP"].IsLong:
                      #We liquidate our position
                      self.Liquidate()