Overall Statistics
Total Trades
127
Average Win
1.08%
Average Loss
-1.04%
Compounding Annual Return
3.157%
Drawdown
7.000%
Expectancy
0.328
Net Profit
20.522%
Sharpe Ratio
0.489
Probabilistic Sharpe Ratio
7.648%
Loss Rate
35%
Win Rate
65%
Profit-Loss Ratio
1.04
Alpha
0.027
Beta
-0.001
Annual Standard Deviation
0.055
Annual Variance
0.003
Information Ratio
-0.512
Tracking Error
0.173
Treynor Ratio
-31.559
Total Fees
$0.00
Estimated Strategy Capacity
$560000.00
Lowest Capacity Asset
EURUSD 8G
from System.Drawing import Color

class ForexBollingerBandBot(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2015, 1, 1)
        self.SetEndDate(2021, 1, 1)
        self.SetCash(100000)
        self.pair = self.AddForex("EURUSD", Resolution.Daily, Market.Oanda).Symbol
        self.bb = self.BB(self.pair, 20, 2)
        
        stockPlot = Chart('Trade Plot')
        stockPlot.AddSeries(Series('Buy', SeriesType.Scatter, '$', 
                            Color.Green, ScatterMarkerSymbol.Triangle))
        stockPlot.AddSeries(Series('Sell', SeriesType.Scatter, '$', 
                            Color.Red, ScatterMarkerSymbol.TriangleDown))
        stockPlot.AddSeries(Series('Liquidate', SeriesType.Scatter, '$', 
                            Color.Blue, ScatterMarkerSymbol.Diamond))
        self.AddChart(stockPlot)

    def OnData(self, data):
        if not self.bb.IsReady:
            return
        
        price = data[self.pair].Price
        
        self.Plot("Trade Plot", "Price", price)
        self.Plot("Trade Plot", "MiddleBand", self.bb.MiddleBand.Current.Value)
        self.Plot("Trade Plot", "UpperBand", self.bb.UpperBand.Current.Value)
        self.Plot("Trade Plot", "LowerBand", self.bb.LowerBand.Current.Value)
        
        if not self.Portfolio.Invested:
            if self.bb.LowerBand.Current.Value > price:
                self.SetHoldings(self.pair, 1)
                self.Plot("Trade Plot", "Buy", price)
            elif self.bb.UpperBand.Current.Value < price:
                self.SetHoldings(self.pair, -1)
                self.Plot("Trade Plot", "Sell", price)
        else:
            if self.Portfolio[self.pair].IsLong:
                if self.bb.MiddleBand.Current.Value < price:
                    self.Liquidate()
                    self.Plot("Trade Plot", "Liquidate", price)
            elif self.bb.MiddleBand.Current.Value > price:
                self.Liquidate()    
                self.Plot("Trade Plot", "Liquidate", price)