Overall Statistics
Total Trades
248
Average Win
1.75%
Average Loss
-2.21%
Compounding Annual Return
1728.175%
Drawdown
59.100%
Expectancy
-0.104
Net Profit
16.989%
Sharpe Ratio
2.428
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
0.79
Alpha
-5.159
Beta
859.422
Annual Standard Deviation
3.031
Annual Variance
9.189
Information Ratio
2.423
Tracking Error
3.031
Treynor Ratio
0.009
Total Fees
$0.00
from datetime import datetime
import decimal
from QuantConnect.Data import SubscriptionDataSource
from QuantConnect.Python import PythonData
from sklearn import datasets, linear_model

class DualThrustAlgorithm(QCAlgorithm):

    def Initialize(self):
        '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
        self.SetStartDate(2019,2,10)
        self.SetEndDate(2019,3,1)
        self.SetCash(10000)
        #equity = self.AddSecurity(SecurityType.Equity, "BAC", Resolution.Hour)
        equity = self.AddForex("AUDJPY", Resolution.Hour, Market.Oanda)
        self.syl = equity.Symbol
   
        self.selltrig = None
        self.buytrig = None
        self.currentopen = None
        
    def OnData(self,data):
        #self.Debug("the on data debug section")
        #self.Debug("the sell trigger is " + str(self.selltrig))
        GBPJPYSPR = False
        if self.Securities["AUDJPY"].AskPrice - self.Securities["AUDJPY"].BidPrice <= 0.02:
            GBPJPYSPR = True
        
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
        history = self.History(3, Resolution.Daily)
    
        k1 = 0.05
        k2 = 0.05
        self.high = []
        self.low = []
        self.close = []
        for slice in history:
            bar = slice[self.syl]
            self.high.append(bar.High)
            self.low.append(bar.Low)
            self.close.append(bar.Close)
        # Pull the open price on each trading day
        self.currentopen = self.Portfolio[self.syl].Price
        
        HH, HC, LC, LL = max(self.high), max(self.close), min(self.close), min(self.low)
        
        if HH - LC >= HC - LL:
            signalrange = HH - LC
        else:
            signalrange = HC - LL
        
        self.selltrig = self.currentopen - decimal.Decimal(k1) * signalrange
        self.buytrig = self.currentopen + decimal.Decimal(k2) * signalrange    
        
        '''self.Debug("the hh is " + str(HH))
        self.Debug("the sell trigger is " + str(self.selltrig)) 
        self.Debug("the buy trigger is " + str(self.buytrig))'''
        
        #start of original defondata
        holdings = self.Portfolio[self.syl].Quantity
        #self.Debug("spread is GBPJPYSPR " + str(self.Securities["GBPJPY"].AskPrice - self.Securities["GBPJPY"].BidPrice))
        
        if GBPJPYSPR:        
            if self.Portfolio[self.syl].Price >= self.selltrig:
                if holdings >= 1:
                    self.Log("my holdings is " + str(holdings))
                    self.Log("Holding-Market: The Price is " + str(self.Securities["AUDJPY"].Price) + " and the selltrig is " + str(self.selltrig))
                    self.MarketOrder(self.syl, 7000)
                else:
                    self.Log("Liquidate- Market: The sell signal is " + str(self.selltrig) + " and the price is " + str(self.Securities["AUDJPY"].Price))
                    self.Liquidate(self.syl)
                    self.MarketOrder(self.syl, 7000)
                    
            elif self.Portfolio[self.syl].Price < self.selltrig:
                 if holdings >= 1:
                    self.Log("my holdings is " + str(holdings))
                    self.Log("Holding-Market: The sell signal is " + str(self.selltrig) + " and the price is " + str(self.Securities["AUDJPY"].Price))
                    self.Liquidate(self.syl)
                    self.MarketOrder(self.syl, -7000)
                 else:
                    self.MarketOrder(self.syl, -7000)
                    
            self.Log("open: "+ str(self.currentopen)+" buy: "+str(self.buytrig)+" sell: "+str(self.selltrig))