Overall Statistics |
Total Trades 151 Average Win 0.34% Average Loss -0.17% Compounding Annual Return -84.696% Drawdown 4.000% Expectancy -0.260 Net Profit -3.038% Sharpe Ratio -12.623 Loss Rate 75% Win Rate 25% Profit-Loss Ratio 2.00 Alpha -1.994 Beta 27.174 Annual Standard Deviation 0.122 Annual Variance 0.015 Information Ratio -12.779 Tracking Error 0.122 Treynor Ratio -0.057 Total Fees $0.00 |
### <summary> ### Simple RSI Strategy intended to provide a minimal algorithm example using ### one indicator ### </summary> from clr import AddReference AddReference("System") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Indicators") AddReference("QuantConnect.Common") import time import matplotlib.pyplot as plt from System import * from QuantConnect import * from QuantConnect.Algorithm import * from QuantConnect.Indicators import * from datetime import datetime from System import * from QuantConnect import * from QuantConnect.Data.Consolidators import * from QuantConnect.Data.Market import * from QuantConnect.Orders import OrderStatus from QuantConnect.Algorithm import QCAlgorithm from QuantConnect.Indicators import * import numpy as np from datetime import timedelta, datetime import pandas import numpy as np ### <summary> ### Simple RSI Strategy intended to provide a minimal algorithm example using ### one indicator ### </summary> class MultipleSymbolConsolidationAlgorithm(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.''' # Set our main strategy parameters self.SetStartDate(2015, 1, 1) self.SetEndDate(2015, 1, 6) # Set End Date self.SetCash(10000) self.quant = 10000 self.spread = 15/10000 self.spread_15 = 15/10000 self.first_stg_up = 0 self.first_stg_down = 0 self.pip_s = 5 self.tp = 33/10000 self.sl = 14/10000 self.tp_s = {} self.sl_s = {} self.tp_s_n = 0 self.sl_s_n = 0 self.long = {} self.short = {} self.price = {} self.trade_ind = {} self.first_stg_up = {} self.first_stg_down = {} self.Data = {} self.trades = {} self.c = 0 BarPeriod = TimeSpan.FromHours(20) SimpleMovingAveragePeriod = 20 RollingWindowSize = 20 self.quoteBarWindow = RollingWindow[QuoteBar](20) ForexSymbols =["EURUSD", "GBPUSD", "USDCHF", "AUDUSD","NZDUSD"] for symbol in ForexSymbols: forex = self.AddForex(symbol) self.Data[symbol] = SymbolData(forex.Symbol, BarPeriod, RollingWindowSize) self.trades[symbol] = 0 self.price[symbol] = 0 self.short[symbol] = 0 self.long[symbol] = 0 self.sl_s[symbol] = 0 self.tp_s[symbol] = 0 self.trade_ind[symbol] = 0 self.first_stg_up[symbol] = 0 self.first_stg_down[symbol] = 0 def SmaUpdated(self, sender, updated): self.smaWindow.Add(updated) def OnData(self,data): for symbol in self.Data.keys(): symbolData = self.Data[symbol] self.quoteBarWindow.Add(data[symbol]) self.SMA(symbol, 20).Updated += self.SmaUpdated self.smaWindow = RollingWindow[IndicatorDataPoint](20) self.bb_ind = self.BB(symbol, 20, 1, MovingAverageType.Simple, Resolution.Hour); self.slow = self.SMA(symbol, 1, Resolution.Hour) self.fast = self.SMA(symbol, 1, Resolution.Hour) fxOpen = data[symbol].Open fxClose = data[symbol].Close fxHigh = data[symbol].High fxLow = data[symbol].Low price = data[symbol].Price pip = (fxHigh - fxLow)*10000 if self.smaWindow.IsReady == True: trend_sma = np.where(self.fast.Current.Value > self.slow.Current.Value,1,0) Console.Write(self.smaWindow[0]) # this is a test to write the sma value to the consol, this is where the error occure. # Trade logic: if self.long[symbol] == 0 and self.short[symbol] == 0: if not self.Portfolio[symbol].Invested: if fxClose > fxOpen:# and trend_sma == 1 : # The trend sma parameter do not work as i do not get any parameters from the sma self.first_stg_up[symbol] = 1 if self.first_stg_up[symbol] == 1 and fxClose > self.bb_ind.LowerBand.Current.Value: self.first_stg_down[symbol] = 0 self.trade_ind[symbol] = 1 # Line 137 - 161 take trade, stopp loss and tp function (works not any faults in here) if not self.Portfolio[symbol].Invested: if pip >self.pip_s and fxOpen < fxClose and self.trade_ind[symbol] == 1 : if self.long[symbol] == 0 and self.short[symbol] == 0: self.price[symbol] = data[symbol].Price self.tp_s[symbol] = price + self.tp self.sl_s[symbol] = price - self.sl self.long[symbol] = 1 self.MarketOrder(symbol, self.quant) if self.price[symbol] > 0 and self.long[symbol] == 1 : if data[symbol].Price >= self.tp_s[symbol] : self.long[symbol] = 0 self.Liquidate(symbol) if data[symbol].Price <= self.sl_s[symbol] : self.long[symbol] = 0 self.Liquidate(symbol) # this is a part of an example, do not think that i am class SymbolData(object): def __init__(self, symbol, barPeriod, windowSize): self.Symbol = symbol self.BarPeriod = barPeriod self.Bars = RollingWindow[IBaseDataBar](windowSize)