protected override bool Process(MarketData indicator, DateTime updateTime, Price value, ref Signal.Tick tradingOrder) { KeyValuePair <DateTime, Price>?timeValueLow = _low.TimeSeries[updateTime]; KeyValuePair <DateTime, Price>?timeValueHigh = _high.TimeSeries[updateTime]; if (timeValueLow == null || timeValueHigh == null) { return(false); } if (_high.TimeSeries.TotalMinutes(updateTime) < _high.Period / 60) { return(false); } Price lowWMA = timeValueLow.Value.Value; Price highWMA = timeValueHigh.Value.Value; var signalValue = lowWMA - highWMA; SIGNAL_CODE oldSignalCode = _signalCode; if (signalValue.Offer > 0) { tradingOrder = _onBuy; _signalCode = SIGNAL_CODE.BUY; } else if (signalValue.Bid < 0) { tradingOrder = _onSell; _signalCode = SIGNAL_CODE.SELL; } else { return(false); } return(oldSignalCode != SIGNAL_CODE.UNKNOWN && oldSignalCode != SIGNAL_CODE.HOLD && oldSignalCode != _signalCode); }
public Trade(DateTime tradingTime, string epic, SIGNAL_CODE direction, int size, decimal price, int placeHolder = 0) { _tradingTime = tradingTime; _epic = epic; _direction = direction; _size = size; _price = price; _placeHolder = placeHolder; }
public override void Insert(DateTime updateTime, Signal signal, SIGNAL_CODE code, decimal stockvalue) { check(updateTime, signal.Id); string tradeRef = signal.Trade == null ? "" : " " + signal.Trade.Reference; var newLine = string.Format("{0},{1},{2},{3},{4},{5}{6}", DATATYPE_SIGNAL, signal.Id, formatDateTime(updateTime), tradeRef, (int)code, stockvalue, Environment.NewLine); _csvSignalStringBuilder.Append(newLine); }
public Trade(DateTime tradingTime, string epic, SIGNAL_CODE direction, int size, decimal price, int placeHolder = 0, TradeCancelled onTradeCancelled = null) { _tradingTime = tradingTime; _epic = epic; _direction = direction; _size = size; _price = price; _placeHolder = placeHolder; _tradeCancelled = onTradeCancelled; }
public Trade(Row row) { _id = (string)row[0]; _confirmationTime = new DateTime(((DateTimeOffset)row[1]).Ticks, DateTimeKind.Local); _direction = (SIGNAL_CODE)(int)row[2]; _epic = (string)row[3]; _price = (decimal)row[4]; _size = (int)row[5]; _reference = (string)row[6]; _tradingTime = new DateTime(((DateTimeOffset)row[7]).Ticks, DateTimeKind.Local); }
public Trade(Row row) { _id = (string)row.GetValue(typeof(string).GetType(), "tradeid"); _confirmationTime = new DateTime(((DateTime)row.GetValue(typeof(DateTimeOffset).GetType(), "confirmation_time")).Ticks, DateTimeKind.Local); _direction = (SIGNAL_CODE)(int)row.GetValue(typeof(int).GetType(), "direction"); _epic = (string)row.GetValue(typeof(string).GetType(), "mktdataid"); _price = (decimal)row.GetValue(typeof(decimal).GetType(), "price"); _size = (int)row.GetValue(typeof(int).GetType(), "size"); _reference = (string)row.GetValue(typeof(string).GetType(), "traderef"); _tradingTime = new DateTime(((DateTime)row.GetValue(typeof(DateTimeOffset).GetType(), "trading_time")).Ticks, DateTimeKind.Local); }
public ModelMacD(MarketData index, int lowPeriod = 2, int midPeriod = 10, int highPeriod = 60, MarketData tradingIndex = null) { if (Config.Settings.ContainsKey("ASSUMPTION_TREND")) _trendAssumption = Config.Settings["ASSUMPTION_TREND"] == "BULL" ? SIGNAL_CODE.BUY : SIGNAL_CODE.SELL; List<MarketData> mktData = new List<MarketData>(); mktData.Add(index); _mktData = mktData; _index = index; _tradingIndex = tradingIndex == null ? index : tradingIndex; _lowPeriod = lowPeriod; _midPeriod = midPeriod; _highPeriod = highPeriod; }
public IndicatorWatershed(MarketData mktData, int resolutionMinutes, int nbPools, IndicatorRSI rsi) : base("Water_" + resolutionMinutes + "_" + nbPools + "_", new List <MarketData> { mktData }) { _resolutionSeconds = resolutionMinutes * 60; _nbPools = nbPools; _rsi = rsi; if (Config.Settings.ContainsKey("ASSUMPTION_TREND")) { _trend = Config.Settings["ASSUMPTION_TREND"] == "BEAR" ? SIGNAL_CODE.SELL : SIGNAL_CODE.BUY; } }
public SignalMacD(MarketData asset, int lowPeriod, int highPeriod, IndicatorEMA low = null, IndicatorEMA high = null, MarketData tradingAsset = null) : base("MacD_" + lowPeriod + "_" + highPeriod + "_" + asset.Id, asset, tradingAsset) { if (Config.Settings.ContainsKey("ASSUMPTION_TREND")) _trendAssumption = Config.Settings["ASSUMPTION_TREND"] == "BULL" ? SIGNAL_CODE.BUY : SIGNAL_CODE.SELL; _low = low == null ? new IndicatorEMA(asset, lowPeriod) : new IndicatorEMA(low); if (low != null) _low.PublishingEnabled = false; _high = high == null ? new IndicatorEMA(asset, highPeriod) : new IndicatorEMA(high); if (high != null) _high.PublishingEnabled = false; _mktIndicator.Add(_low); _mktIndicator.Add(_high); }
public ModelMacD(MarketData index, int lowPeriod = 2, int midPeriod = 10, int highPeriod = 60, MarketData tradingIndex = null) { if (Config.Settings.ContainsKey("ASSUMPTION_TREND")) { _trendAssumption = Config.Settings["ASSUMPTION_TREND"] == "BULL" ? SIGNAL_CODE.BUY : SIGNAL_CODE.SELL; } List <MarketData> mktData = new List <MarketData>(); mktData.Add(index); _mktData = mktData; _index = index; _tradingIndex = tradingIndex == null ? index : tradingIndex; _lowPeriod = lowPeriod; _midPeriod = midPeriod; _highPeriod = highPeriod; }
public SignalMacD(MarketData asset, int lowPeriod, int highPeriod, IndicatorEMA low = null, IndicatorEMA high = null, MarketData tradingAsset = null) : base("MacD_" + lowPeriod + "_" + highPeriod + "_" + asset.Id, asset, tradingAsset) { if (Config.Settings.ContainsKey("ASSUMPTION_TREND")) { _trendAssumption = Config.Settings["ASSUMPTION_TREND"] == "BULL" ? SIGNAL_CODE.BUY : SIGNAL_CODE.SELL; } _low = low == null ? new IndicatorEMA(asset, lowPeriod) : new IndicatorEMA(low); if (low != null) { _low.PublishingEnabled = false; } _high = high == null ? new IndicatorEMA(asset, highPeriod) : new IndicatorEMA(high); if (high != null) { _high.PublishingEnabled = false; } _mktIndicator.Add(_low); _mktIndicator.Add(_high); }
public Trade(Trade cpy, bool opposite = false, DateTime?trading_time = null) { this._epic = cpy._epic; if (opposite) { this._direction = (cpy._direction == SIGNAL_CODE.BUY ? SIGNAL_CODE.SELL : SIGNAL_CODE.BUY); this._tradingTime = trading_time.Value; } else { this._direction = cpy._direction; this._tradingTime = cpy._tradingTime; this._confirmationTime = cpy._confirmationTime; } this._size = cpy._size; this._reference = cpy._reference; this._id = cpy._id; this._price = cpy._price; this._placeHolder = cpy._placeHolder; }
public Trade(Trade cpy, bool opposite = false, DateTime? trading_time = null) { this._epic = cpy._epic; if (opposite) { this._direction = (cpy._direction == SIGNAL_CODE.BUY ? SIGNAL_CODE.SELL : SIGNAL_CODE.BUY); this._tradingTime = trading_time.Value; } else { this._direction = cpy._direction; this._tradingTime = cpy._tradingTime; this._confirmationTime = cpy._confirmationTime; } this._size = cpy._size; this._reference = cpy._reference; this._id = cpy._id; this._price = cpy._price; this._placeHolder = cpy._placeHolder; this._tradeCancelled = cpy._tradeCancelled; }
public override void Insert(DateTime updateTime, Signal signal, SIGNAL_CODE code, decimal mktdatavalue) { if (Config.TradingEnabled) { if (signal.Trade == null) { return; } if (signal.Trade.Reference == "") { return; } } if (_session == null) { throw new ApplicationException(EXCEPTION_CONNECTION_CLOSED); } string tradeRef = signal.Trade == null ? null : " " + signal.Trade.Reference; executeAsyncQuery(string.Format(DB_INSERTION + "(signalid, trading_time, tradeid, value, mktdatavalue) values ('{2}', {3}, '{4}', {5}, {6})", DB_HISTORICALDATA, DATATYPE_SIGNAL, signal.Id, ToUnixTimestamp(updateTime), tradeRef, Convert.ToInt32(code), mktdatavalue)); }
public override void Insert(DateTime updateTime, Signal signal, SIGNAL_CODE code, decimal stockvalue) { var time = new DateTime(updateTime.Year, updateTime.Month, updateTime.Day, updateTime.Hour, updateTime.Minute, updateTime.Second); if (((SIGNAL_CODE)_expectedSignalData[signal.Id].Value(time).Value.Value.Bid != code) || Math.Abs(_expectedSignalData[signal.Id].Value(time).Value.Value.Offer - stockvalue) > TOLERANCE) { string error; if ((SIGNAL_CODE)_expectedSignalData[signal.Id].Value(time).Value.Value.Bid != code) { error = "Test failed: signal " + signal.Name + " time " + time.ToShortTimeString() + " expected value " + ((SIGNAL_CODE)_expectedSignalData[signal.Id].Value(time).Value.Value.Bid).ToString() + " != " + code.ToString(); } else { error = "Test failed: signal stock value " + signal.Name + " time " + time.ToShortTimeString() + " expected value " + (_expectedSignalData[signal.Id].Value(time).Value.Value.Offer).ToString() + " != " + stockvalue.ToString(); } Log.Instance.WriteEntry(error, EventLogEntryType.Error); throw new ApplicationException(error); } }
protected void OnUpdate(MarketData mktData, DateTime updateTime, Price value) { if (_signalProcessing) { return; } lock (_mktIndicator) { if (_signalProcessing) { return; } try { _signalProcessing = true; Signal.Tick tradingOrder = _onHold; bool signaled = Process(mktData, updateTime, value, ref tradingOrder); if (signaled) { // send a signal var stockValue = _asset.TimeSeries[updateTime].Value.Value; if (tradingOrder(this, updateTime, stockValue)) { if (_signalCode == SIGNAL_CODE.BUY) { if (_oldSignalCode == SIGNAL_CODE.SELL) { PublisherConnection.Instance.Insert(updateTime.AddSeconds(-1), this, _signalCode, stockValue.Offer); } PublisherConnection.Instance.Insert(updateTime, this, _signalCode, stockValue.Offer); } else if (_signalCode == SIGNAL_CODE.SELL) { if (_oldSignalCode == SIGNAL_CODE.BUY) { PublisherConnection.Instance.Insert(updateTime.AddSeconds(-1), this, _signalCode, stockValue.Bid); } PublisherConnection.Instance.Insert(updateTime, this, _signalCode, stockValue.Bid); } else if (_signalCode == SIGNAL_CODE.HOLD) { if (_oldSignalCode == SIGNAL_CODE.BUY) { PublisherConnection.Instance.Insert(updateTime, this, SIGNAL_CODE.SELL, stockValue.Bid); } else if (_oldSignalCode == SIGNAL_CODE.SELL) { PublisherConnection.Instance.Insert(updateTime, this, SIGNAL_CODE.BUY, stockValue.Offer); } } else if (_signalCode == SIGNAL_CODE.FAILED) { PublisherConnection.Instance.Insert(updateTime, this, _signalCode, stockValue.Bid); } _oldSignalCode = _signalCode; } } } finally { _signalProcessing = false; } } }
public bool Update(DateTime updateTime, Price value, Price rsi) { var curValue = value.Mid(); if (StartValue == decimal.MinValue) { StartValue = curValue; } if (GlobalTrend == SIGNAL_CODE.BUY) { if (ReachedExtremum) { if (curValue > LastValue) { PoolTrend = LastValue < StartValue ? SIGNAL_CODE.SELL : SIGNAL_CODE.BUY; Depth = LastValue < StartValue ? ExtremumValue - StartValue : ExtremumValue - LastValue; return(true); } } else { if (curValue > ExtremumValue) { ExtremumValue = curValue; ExtremumTime = updateTime; } else if (curValue < ExtremumValue) { ReachedExtremum = true; } } } else { if (ReachedExtremum) { if (curValue < LastValue) { PoolTrend = LastValue < StartValue ? SIGNAL_CODE.SELL : SIGNAL_CODE.BUY; Depth = LastValue < StartValue ? LastValue - ExtremumValue : StartValue - ExtremumValue; return(true); } } else { if (curValue < ExtremumValue) { ExtremumValue = curValue; ExtremumTime = updateTime; } else if (curValue > ExtremumValue) { ReachedExtremum = true; } } } LastTime = updateTime; LastValue = curValue; LastRsi = rsi.Bid; return(false); }
public Pool(SIGNAL_CODE globalTrend, DateTime startTime) { GlobalTrend = globalTrend; StartTime = startTime; ExtremumValue = GlobalTrend == SIGNAL_CODE.BUY ? decimal.MinValue : decimal.MaxValue; }
public abstract void Insert(DateTime updateTime, Signal signal, SIGNAL_CODE code, decimal stockvalue);
public override void Insert(DateTime updateTime, Signal signal, SIGNAL_CODE code, decimal stockvalue) { var time = new DateTime(updateTime.Year, updateTime.Month, updateTime.Day, updateTime.Hour, updateTime.Minute, updateTime.Second); if (((SIGNAL_CODE)_expectedSignalData[signal.Id].Value(time).Value.Value.Bid != code) || Math.Abs(_expectedSignalData[signal.Id].Value(time).Value.Value.Offer - stockvalue) > TOLERANCE) { string error; if ((SIGNAL_CODE)_expectedSignalData[signal.Id].Value(time).Value.Value.Bid != code) error = "Test failed: signal " + signal.Name + " time " + time.ToShortTimeString() + " expected value " + ((SIGNAL_CODE)_expectedSignalData[signal.Id].Value(time).Value.Value.Bid).ToString() + " != " + code.ToString(); else error = "Test failed: signal stock value " + signal.Name + " time " + time.ToShortTimeString() + " expected value " + (_expectedSignalData[signal.Id].Value(time).Value.Value.Offer).ToString() + " != " + stockvalue.ToString(); Log.Instance.WriteEntry(error, EventLogEntryType.Error); throw new ApplicationException(error); } }
public ReplayPositionUpdateInfo(DateTime timestamp, string epic, string dealId, string dealRef, string status, string dealStatus, int size, decimal level, SIGNAL_CODE direction) : base(null) { _name = epic; _id = dealId; _itemData["timestamp"] = string.Format("{0}-{1}-{2}T {3}:{4}:{5}.{6}", timestamp.Year, timestamp.Month, timestamp.Day, timestamp.Hour, timestamp.Minute, timestamp.Second, timestamp.Millisecond); _itemData["dealReference"] = dealRef; _itemData["status"] = status; _itemData["dealStatus"] = dealStatus; _itemData["size"] = size.ToString(); _itemData["level"] = level.ToString(); _itemData["channel"] = "PublicRestOTC"; _itemData["direction"] = direction == SIGNAL_CODE.BUY ? "BUY" : (direction == SIGNAL_CODE.SELL ? "SELL" : "UNKNOWN"); }
public ReplayPositionUpdateInfo(DateTime timestamp, string epic, string dealId, string dealRef, string status, string dealStatus, int size, decimal level, SIGNAL_CODE direction) : base(null) { _name = epic; _id = dealId; _itemData["timestamp"] = string.Format("{0}-{1}-{2}T {3}:{4}:{5}.{6}", timestamp.Year, timestamp.Month, timestamp.Day, timestamp.Hour, timestamp.Minute, timestamp.Second, timestamp.Millisecond); _itemData["dealReference"] = dealRef; _itemData["status"] = status; _itemData["dealStatus"] = dealStatus; _itemData["size"] = size.ToString(); _itemData["level"] = level.ToString(); _itemData["channel"] = "PublicRestOTC"; _itemData["direction"] = direction == SIGNAL_CODE.BUY ? "BUY" : (direction == SIGNAL_CODE.SELL ? "SELL" : "UNKNOWN"); }
public override void Insert(DateTime updateTime, Signal signal, SIGNAL_CODE code, decimal stockvalue) { check(updateTime, signal.Id); string tradeRef = signal.Trade == null ? "" : " " + signal.Trade.Reference; var newLine = string.Format("{0},{1},{2},{3},{4},{5}{6}", DATATYPE_SIGNAL, signal.Id, formatDateTime(updateTime), tradeRef, (int)code, stockvalue, Environment.NewLine); _csvSignalStringBuilder.Append(newLine); }
public abstract void Insert(DateTime updateTime, Signal signal, SIGNAL_CODE code, decimal stockvalue);