Overall Statistics
Total Trades
8
Average Win
0.06%
Average Loss
-0.03%
Compounding Annual Return
8.146%
Drawdown
0.200%
Expectancy
1.178
Net Profit
0.150%
Sharpe Ratio
14.737
Probabilistic Sharpe Ratio
0%
Loss Rate
25%
Win Rate
75%
Profit-Loss Ratio
1.90
Alpha
0.073
Beta
0.037
Annual Standard Deviation
0.004
Annual Variance
0
Information Ratio
3.989
Tracking Error
0.072
Treynor Ratio
1.776
Total Fees
$0.00
class MovingAverageCrossAlgorithm(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(2014, 1, 1)    #Set Start Date
            self.SetEndDate(2014, 1, 7)      #Set End Date
            self.SetCash(100000)             #Set Strategy Cash
            # Find more symbols here: http://quantconnect.com/data
            # initialize our forex data 
            ForexSymbols =["EURUSD", "USDJPY", "EURGBP", "EURCHF", "USDCAD", "USDCHF", "AUDUSD","NZDUSD"]
            
            self.indicators_by_symbols = {}
            # initialize our forex data 
            for symbol in ForexSymbols:
                sym = self.AddForex(symbol).Symbol
                self.indicators_by_symbols[sym] = {}
                # create a 15 day exponential moving average
                self.indicators_by_symbols[sym]['fast'] = self.EMA(sym, 3, Resolution.Minute)
                self.indicators_by_symbols[sym]['slow'] = self.EMA(sym, 7, Resolution.Minute)
                self.indicators_by_symbols[sym]['rsi'] = self.RSI(sym, 7, MovingAverageType.Simple, Resolution.Minute)
                self.indicators_by_symbols[sym]['atr'] = self.ATR(sym, 5, MovingAverageType.Simple, Resolution.Minute)
                self.indicators_by_symbols[sym]['atr2'] = self.ATR(sym, 12, MovingAverageType.Simple, Resolution.Minute)
            
            self.SetWarmUp(12, Resolution.Minute)
            self.previous = None

        def OnData(self, data):
            '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.'''
            # a couple things to notice in this method:
            #  1. We never need to 'update' our indicators with the data, the engine takes care of this for us
            #  2. We can use indicators directly in math expressions
            #  3. We can easily plot many indicators at the same time
    
            # wait for our slowest TA indicator to fully initialize
            for symbol in self.indicators_by_symbols:
                if not self.indicators_by_symbols[symbol]['atr2'].IsReady:
                    return
            
            
            # only once per day
            if self.previous is not None and self.previous.date() == self.Time.date():
                return
            self.previous = self.Time
            
    
            # define a small tolerance on our checks to avoid bouncing
            tolerance = 0.00015
    
            for symbol, value in self.indicators_by_symbols.items():
                holdings = self.Portfolio[symbol].Quantity
                price = self.Securities[symbol].Price
                # we only want to go long if we're currently short or flat
                if holdings <= 0:
                    fast = value['fast'].Current.Value
                    slow = value['slow'].Current.Value
                    rsi = value['rsi'].Current.Value
                    atr = value['atr'].Current.Value
                    atr2 = value['atr2'].Current.Value
                    
                    # if the fast is greater than the slow, we'll go long
                    if fast > slow *(1 + tolerance) and rsi > 60 and atr > atr2:
                        self.Log("BUY  >> {0}".format(price))
                        self.SetHoldings(symbol, 0.25)
                        
                    if fast < slow *(1 - tolerance) and rsi < 40 and atr > atr2:
                        self.Log("SELL  >> {0}".format(price))
                        self.SetHoldings((symbol), 0.25)
                        
                # we only want to liquidate if we're currently long
                # if the fast is less than the slow we'll liquidate our long
                if holdings > 0 and fast < slow:
                    self.Log("SELL >> {0}".format(price))
                    self.Liquidate(symbol)
                
                if holdings < 0 and fast > slow:
                    self.Log("BUY >> {0}".format(price))
                    self.Liquidate(symbol)