Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
-2.951%
Drawdown
5.900%
Expectancy
0
Net Profit
-2.959%
Sharpe Ratio
-0.534
Probabilistic Sharpe Ratio
4.353%
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
-0.018
Beta
-0.022
Annual Standard Deviation
0.043
Annual Variance
0.002
Information Ratio
-2.25
Tracking Error
0.123
Treynor Ratio
1.057
Total Fees
$0.00
Estimated Strategy Capacity
$1400000.00
class HyperActiveMagentaChimpanzee(QCAlgorithm):
    
    highestsymbolprice = 0
    lowestsymbolprice  = 0
    # define the RollingWindow in initialize
    def Initialize(self):
        self.SetStartDate(2019, 1, 1)  # Set Start Date
        self.SetEndDate(2020, 1, 1)
        self.SetCash(100000)  # Set Strategy Cash
        # self.AddEquity("SPY", Resolution.Minute)
        tickers = ["EURUSD"]
        for ticker in tickers:
            self.AddForex(ticker, Resolution.Hour, Market.Oanda)
        # note length is (desired lookback period + 1)
        self.lowValues = RollingWindow[float](4)
        self.highValues = RollingWindow[float](4)

    def OnData(self, data):
        # add data
        tickers = ["EURUSD"]
        for ticker in tickers:
            self.lowValues.Add(data[ticker].Low)
            self.highValues.Add(data[ticker].High)
            current_price = data[ticker].Close
        
        # make sure window is properly warmed up before using
        if(not self.lowValues.IsReady):
            return
        
        if(not self.highValues.IsReady):
            return
        
        if self.Portfolio.Invested:
            if self.isLong:
              
              
                if current_price > self.highestsymbolprice:
                    self.highestsymbolprice = current_price
                    updateFields = UpdateOrderFields()
                    updateFields.StopPrice = self.highestsymbolprice * 0.98
                    self.trailingstop = updateFields.StopPrice
                    if current_price <= self.trailingstop:
                        self.Liquidate(ticker)
                        self.Log(f"{self.Time} Long Position Trailing Stop Profit at {current_price}")
               
            else:
             
                if current_price < self.lowestsymbolprice:
                    self.lowestsymbolprice = current_price
                    updateFields = UpdateOrderFields()
                    updateFields.StopPrice = self.lowestsymbolprice * 1.02
                    self.trailingstop = updateFields.StopPrice 
                    if current_price >= self.trailingstop:
                        self.Liquidate(ticker)
                        self.Log(f"{self.Time} Short Position Trailing Stop Profit at {current_price}")
                        
                        
        if not self.Portfolio.Invested: 
            
            # If the high 3 bars ago is less than the current low, and the current low is less than the previous bar high, and the current bar high is 
            # less than the high 2 bars ago and the previous bar high is less than the high 2 bars ago,buy long at the next market open.            
            if(self.highValues[3] < data[ticker].Low and data[ticker].Low < self.highValues[1] and 
            data[ticker].High < self.highValues[2]  and self.highValues[1]  < self.highValues[2] ):
                
                self.SetHoldings(ticker, 1)
                # get buy-in price for trailing stop loss/profit
                self.buyInPrice = current_price
                # entered long position
                self.isLong = True
                        
                self.Log(f"{self.Time} Entered Long Position at {current_price}")
            
            # If the low 3 bars ago is great than the current high, and the current high is greater than the previous bar low, and the current bar low is 
            # greater than the low 2 bars ago and the previous bar low is greater than the low 2 bars ago,sell short at the next market open.    
            if(self.lowValues[3] > data[ticker].High and data[ticker].High > self.lowValues[1] and 
            data[ticker].Low > self.lowValues[2] and self.lowValues[1] > self.lowValues[2]):
                
                self.SetHoldings(ticker, -1)
                # get sell-in price for trailing stop loss/profit
                self.sellInPrice = current_price
                # entered short position
                self.isLong = False
                        
                self.Log(f"{self.Time} Entered Short Position at {current_price}")