Overall Statistics
Total Trades
319
Average Win
0.18%
Average Loss
-0.10%
Compounding Annual Return
-86.962%
Drawdown
11.300%
Expectancy
-0.283
Net Profit
-8.543%
Sharpe Ratio
-5.932
Loss Rate
74%
Win Rate
26%
Profit-Loss Ratio
1.77
Alpha
-1.163
Beta
0.267
Annual Standard Deviation
0.219
Annual Variance
0.048
Information Ratio
-3.228
Tracking Error
0.245
Treynor Ratio
-4.864
Total Fees
$0.00
# Your New Python File
from datetime import datetime
import decimal
import numpy as np
import clr
clr.AddReference("System")
clr.AddReference("QuantConnect.Algorithm")
clr.AddReference("QuantConnect.Indicators")
clr.AddReference("QuantConnect.Common")

from System import *
from QuantConnect import *
from QuantConnect.Algorithm import *
from QuantConnect.Indicators import *

class DynamicBreakoutAlgorithm(QCAlgorithm):

    def Initialize(self):
    
        self.SetStartDate(2019, 7, 28) #Set Start Date
        self.SetEndDate(2019, 8, 13) #Set End Date
        self.SetCash(5000) #Set Strategy Cash
        # Find more symbols here: http://quantconnect.com/data
        self.AddForex("GBPAUD", Resolution.Minute, Market.Oanda)
        self.eurusd = self.AddForex("GBPAUD", Resolution.Minute).Symbol
        self.numberOfBars = 6 #5
        self.highet_price = 0
        self.lowest_price = 0

    def get_highest_price(self):
    
        m_highest_price = 0
        high_counter = 0
        self.df = self.History(self.eurusd, self.numberOfBars,Resolution.Minute)['high'].values
    
        for f in self.df:
            if high_counter == self.numberOfBars - 1:
                break
                
            if f > m_highest_price:
                m_highest_price = f
                high_counter += 1
    
        return m_highest_price

    def get_lowest_price(self):
    
        m_lowest_price = 0
        low_counter = 0
        self.df_low = self.History(self.eurusd, self.numberOfBars,Resolution.Minute)['low'].values
    
        for f in self.df_low:
            if low_counter == self.numberOfBars - 1:
                break
            
            if f > m_lowest_price:
                m_lowest_price = f
                low_counter += 1
        
        return m_lowest_price

    def OnData(self, data):
    
        holdings = self.Portfolio["GBPAUD"].Quantity
        self.price = data["GBPAUD"].Price
        self.positionSize = self.Portfolio.TotalPortfolioValue

        self.df = self.History(self.eurusd, self.numberOfBars,Resolution.Minute)
    
        if not self.df.empty:
            self.highest_price = self.get_highest_price()
            self.lowest_price = self.get_lowest_price()

        if holdings == 0:
    
            if self.price > self.highest_price:
                self.Log("TRUE 1")
                self.Buy("GBPAUD", self.positionSize)

            if self.price < self.lowest_price:
                self.Log("TRUE 2")
                self.Sell("GBPAUD", self.positionSize)

        else:
    
            if self.price > self.highest_price and holdings < 0:
                self.Log("TRUE 3")
                self.Buy("GBPAUD", self.positionSize * 2)

            if self.price < self.lowest_price and holdings > 0:
                self.Log("TRUE 4")
                self.Sell("GBPAUD", self.positionSize * 2)