/// <summary> /// Загрузить настройки. /// </summary> /// <param name="settings">Хранилище настроек.</param> public override void Load(SettingsStorage settings) { base.Load(settings); ShortSma.LoadNotNull(settings, "ShortSma"); LongSma.LoadNotNull(settings, "LongSma"); }
/// <summary> /// Сохранить настройки. /// </summary> /// <param name="settings">Хранилище настроек.</param> public override void Save(SettingsStorage settings) { base.Save(settings); settings.SetValue("ShortSma", ShortSma.Save()); settings.SetValue("LongSma", LongSma.Save()); }
protected override void OnStarted() { this .WhenCandlesFinished(_series.CandleSeries) .Do(ProcessCandle) .Apply(this); this .WhenNewMyTrade() .Do(trade => _myTrades.Add(trade)) .Apply(this); // store current values for short and long _isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue(); _candlesStarted = false; this .WhenSubscriptionStarted(_series) .Do(() => _candlesStarted = true) .Apply(this); Subscribe(_series); base.OnStarted(); }
/// <summary> /// Обработать входное значение. /// </summary> /// <param name="input">Входное значение.</param> /// <returns>Результирующее значение.</returns> protected override IIndicatorValue OnProcess(IIndicatorValue input) { var shortValue = ShortSma.Process(input).GetValue <decimal>(); var longValue = LongSma.Process(input).GetValue <decimal>(); return(new DecimalIndicatorValue(this, Math.Abs(100m * (shortValue - longValue) / longValue))); }
private void ProcessCandle(Candle candle) { // strategy are stopping if (ProcessState == ProcessStates.Stopping) { CancelActiveOrders(); return; } this.AddInfoLog(LocalizedStrings.Str3634Params.Put(candle.OpenTime, candle.OpenPrice, candle.HighPrice, candle.LowPrice, candle.ClosePrice, candle.TotalVolume, candle.Security)); // process new candle var longValue = LongSma.Process(candle); var shortValue = ShortSma.Process(candle); // calc new values for short and long var isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue(); // crossing happened if (_isShortLessThenLong != isShortLessThenLong) { // if short less than long, the sale, otherwise buy var direction = isShortLessThenLong ? Sides.Sell : Sides.Buy; // calc size for open position or revert var volume = Position == 0 ? Volume : Position.Abs().Min(Volume) * 2; // calc order price as a close price + offset var price = candle.ClosePrice + ((direction == Sides.Buy ? Security.PriceStep : -Security.PriceStep) ?? 1); RegisterOrder(this.CreateOrder(direction, price, volume)); // or revert position via market quoting //var strategy = new MarketQuotingStrategy(direction, volume); //ChildStrategies.Add(strategy); // store current values for short and long _isShortLessThenLong = isShortLessThenLong; } var trade = _myTrades.FirstOrDefault(); _myTrades.Clear(); var data = new ChartDrawData(); data .Group(candle.OpenTime) .Add(_candlesElem, candle) .Add(_shortElem, shortValue) .Add(_longElem, longValue) .Add(_tradesElem, trade); _chart.Draw(data); }
protected override void OnStarted() { _candleManager .WhenCandlesFinished(_series) .Do(ProcessCandle) .Apply(this); // запоминаем текущее положение относительно друг друга _isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue(); base.OnStarted(); }
protected override void OnStarted() { _candleManager .WhenCandlesFinished(_series) .Do(ProcessCandle) .Apply(this); // store current values for short and long _isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue(); base.OnStarted(); }
protected override void OnStarted() { this .WhenCandlesFinished(_series) .Do(ProcessCandle) .Apply(this); // запоминаем текущее положение относительно друг друга _isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue(); // начинаем получать свечи за период в 5 дней Start(_series, DateTime.Today - TimeSpan.FromDays(5), CurrentTime); base.OnStarted(); }
protected override void OnStarted() { _series .WhenCandlesFinished() .Do(ProcessCandle) .Apply(this); this .WhenNewMyTrades() .Do(trades => _myTrades.AddRange(trades)) .Apply(this); // store current values for short and long _isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue(); base.OnStarted(); }
protected override void OnStarted() { _series .WhenCandlesFinished() .Do(ProcessCandle) .Apply(this); this .WhenNewMyTrades() .Do(trades => _myTrades.AddRange(trades)) .Apply(this); // запоминаем текущее положение относительно друг друга _isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue(); base.OnStarted(); }
private void ProcessCandle(Candle candle) { // если наша стратегия в процессе остановки if (ProcessState == ProcessStates.Stopping) { // отменяем активные заявки CancelActiveOrders(); return; } // добавляем новую свечу LongSma.Process(candle); ShortSma.Process(candle); // вычисляем новое положение относительно друг друга var isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue(); // если произошло пересечение if (_isShortLessThenLong != isShortLessThenLong) { // если короткая меньше чем длинная, то продажа, иначе, покупка. var direction = isShortLessThenLong ? Sides.Sell : Sides.Buy; // вычисляем размер для открытия или переворота позы var volume = Position == 0 ? Volume : Position.Abs() * 2; // регистрируем заявку (обычным способом - лимитированной заявкой) //RegisterOrder(this.CreateOrder(direction, (decimal)Security.GetCurrentPrice(direction), volume)); // переворачиваем позицию через котирование var strategy = new MarketQuotingStrategy(direction, volume); ChildStrategies.Add(strategy); // запоминаем текущее положение относительно друг друга _isShortLessThenLong = isShortLessThenLong; } }
private void ProcessCandle(Candle candle) { // strategy are stopping if (ProcessState == ProcessStates.Stopping) { CancelActiveOrders(); return; } // process new candle LongSma.Process(candle); ShortSma.Process(candle); // calc new values for short and long var isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue(); // crossing happened if (_isShortLessThenLong != isShortLessThenLong) { // if short less than long, the sale, otherwise buy var direction = isShortLessThenLong ? Sides.Sell : Sides.Buy; // calc size for open position or revert var volume = Position == 0 ? Volume : Position.Abs() * 2; // register order (limit order) RegisterOrder(this.CreateOrder(direction, (decimal)(Security.GetCurrentPrice(this, direction) ?? 0), volume)); // or revert position via market quoting //var strategy = new MarketQuotingStrategy(direction, volume); //ChildStrategies.Add(strategy); // store current values for short and long _isShortLessThenLong = isShortLessThenLong; } }
private void ProcessCandle(Candle candle) { // strategy are stopping if (ProcessState == ProcessStates.Stopping) { CancelActiveOrders(); return; } this.AddInfoLog(LocalizedStrings.Str3634Params.Put(candle.OpenTime, candle.OpenPrice, candle.HighPrice, candle.LowPrice, candle.ClosePrice, candle.TotalVolume, candle.Security)); // process new candle var longValue = LongSma.Process(candle); var shortValue = ShortSma.Process(candle); // calc new values for short and long var isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue(); // crossing happened if (_isShortLessThenLong != isShortLessThenLong) { // if short less than long, the sale, otherwise buy var direction = isShortLessThenLong ? Sides.Sell : Sides.Buy; // calc size for open position or revert var volume = Position == 0 ? Volume : Position.Abs().Min(Volume) * 2; if (!SafeGetConnector().RegisteredMarketDepths.Contains(Security)) { var price = Security.GetMarketPrice(Connector, direction); // register "market" order (limit order with guaranteed execution price) if (price != null) { RegisterOrder(this.CreateOrder(direction, price.Value, volume)); } } else { // register order (limit order) RegisterOrder(this.CreateOrder(direction, (decimal)(Security.GetCurrentPrice(this, direction) ?? 0), volume)); // or revert position via market quoting //var strategy = new MarketQuotingStrategy(direction, volume) //{ // WaitAllTrades = true, //}; //ChildStrategies.Add(strategy); } // store current values for short and long _isShortLessThenLong = isShortLessThenLong; } var trade = _myTrades.FirstOrDefault(); _myTrades.Clear(); var dict = new Dictionary <IChartElement, object> { { _candlesElem, candle }, { _shortElem, shortValue }, { _longElem, longValue }, { _tradesElem, trade } }; _chart.Draw(candle.OpenTime, dict); }
private void ProcessCandle(Candle candle) { // если наша стратегия в процессе остановки if (ProcessState == ProcessStates.Stopping) { // отменяем активные заявки CancelActiveOrders(); return; } this.AddInfoLog(LocalizedStrings.Str2177Params.Put(candle.OpenTime, candle.OpenPrice, candle.HighPrice, candle.LowPrice, candle.ClosePrice, candle.TotalVolume)); // добавляем новую свечу var longValue = LongSma.Process(candle); var shortValue = ShortSma.Process(candle); // вычисляем новое положение относительно друг друга var isShortLessThenLong = ShortSma.GetCurrentValue() < LongSma.GetCurrentValue(); // если произошло пересечение if (_isShortLessThenLong != isShortLessThenLong) { // если короткая меньше чем длинная, то продажа, иначе, покупка. var direction = isShortLessThenLong ? Sides.Sell : Sides.Buy; // вычисляем размер для открытия или переворота позы var volume = Position == 0 ? Volume : Position.Abs().Min(Volume) * 2; if (!SafeGetConnector().RegisteredMarketDepths.Contains(Security)) { var price = Security.GetMarketPrice(Connector, direction); // регистрируем псевдо-маркетную заявку - лимитная заявка с ценой гарантирующей немедленное исполнение. if (price != null) { RegisterOrder(this.CreateOrder(direction, price.Value, volume)); } } else { // регистрируем заявку (обычным способом - лимитированной заявкой) RegisterOrder(this.CreateOrder(direction, (decimal)(Security.GetCurrentPrice(this, direction) ?? 0), volume)); // переворачиваем позицию через котирование //var strategy = new MarketQuotingStrategy(direction, volume) //{ // WaitAllTrades = true, //}; //ChildStrategies.Add(strategy); } // запоминаем текущее положение относительно друг друга _isShortLessThenLong = isShortLessThenLong; } var trade = _myTrades.FirstOrDefault(); _myTrades.Clear(); var dict = new Dictionary <IChartElement, object> { { _candlesElem, candle }, { _shortElem, shortValue }, { _longElem, longValue }, { _tradesElem, trade } }; _chart.Draw(candle.OpenTime, dict); }