Overall Statistics |
Total Trades 491 Average Win 0.41% Average Loss -0.24% Compounding Annual Return 3.049% Drawdown 4.700% Expectancy 0.028 Net Profit 2.045% Sharpe Ratio 0.364 Loss Rate 62% Win Rate 38% Profit-Loss Ratio 1.74 Alpha -0.02 Beta 2.943 Annual Standard Deviation 0.074 Annual Variance 0.005 Information Ratio 0.146 Tracking Error 0.074 Treynor Ratio 0.009 Total Fees $0.00 |
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 HustleForexAlgo(QCAlgorithm): '''In this example we look at the 13ema/20sma hourly moving average cross. This algorithm will go long when the 13ema crosses above the 20sma and will go short when the 13ema crosses back below the 20sma.''' def __init__(self): self.symbol = "EURUSD" self.previous = None self.fast = None self.slow = None def Initialize(self): self.SetStartDate(2017,6,1) #Set Start Date self.SetEndDate(2018,2,1) #Set End Date self.SetCash(100000) #Set Strategy Cash self.AddForex("EURUSD", Resolution.Hour, Market.Oanda) #Set time frame for bars. # create a 13 period exponential moving average self.fast = self.EMA(self.symbol, 13); # create a 20 period simple moving average self.slow = self.SMA(self.symbol, 20); self.PlotIndicator("EMA", self.fast); self.PlotIndicator("SMA", self.slow); self.previous = None def OnData(self, data): # wait for our fast ema to fully initialize if not self.fast.IsReady: return # wait for our slow ema to fully initialize if not self.slow.IsReady: return # define a small tolerance on our checks to avoid bouncing tolerance = 0.000000; holdings = self.Portfolio[self.symbol].Quantity # Bullish entry from no position if holdings == 0: # if the 13ema is greater than the 20sma, we'll go long if self.fast.Current.Value > self.slow.Current.Value * int(1 + tolerance): newTicket = self.MarketOrder(self.symbol, 100000) # Bearish entry from no position if holdings == 0: # if the 13ema is lower than the 20sma, we'll go short if self.fast.Current.Value < self.slow.Current.Value * int(1 + tolerance): newTicket = self.MarketOrder(self.symbol, -100000) # Bullish entry from short position if holdings < 0: # if the 13ema is greater than the 20sma, we'll go long if self.fast.Current.Value > self.slow.Current.Value * int(1 + tolerance): newTicket = self.MarketOrder(self.symbol, int(-1 * holdings)) newTicket = self.MarketOrder(self.symbol, 100000) # Bearish entry from long position if holdings > 0: # if the 13ema is lower than the 20sma, we'll go short if self.fast.Current.Value < self.slow.Current.Value * int(1 + tolerance): newTicket = self.MarketOrder(self.symbol, int(-1 * holdings)) newTicket = self.MarketOrder(self.symbol, -100000) self.previous = self.Time