public override void OnStateChange(IndicatorState state) { if (state == IndicatorState.Configure) { _lengthJaw = CreateParameterInt("Jaw length", 13); _lengthLips = CreateParameterInt("Lips length", 8); _lengthTeeth = CreateParameterInt("Teeth length", 5); _shiftJaw = CreateParameterInt("Jaw offset", 8); _shiftLips = CreateParameterInt("Lips offset", 3); _shiftTeeth = CreateParameterInt("Teeth offset", 5); _seriesJaw = CreateSeries("Jaw", Color.DodgerBlue, IndicatorChartPaintType.Line, true); _seriesTeeth = CreateSeries("Teeth", Color.DarkRed, IndicatorChartPaintType.Line, true); _seriesLips = CreateSeries("Lips", Color.LawnGreen, IndicatorChartPaintType.Line, true); _smaJaw = IndicatorsFactory.CreateIndicatorByName("Ssma", Name + "SsmaJaw", false); ((IndicatorParameterInt)_smaJaw.Parameters[0]).Bind(_lengthJaw); ProcessIndicator("Jaw SSMA", _smaJaw); _smaLips = IndicatorsFactory.CreateIndicatorByName("Ssma", Name + "SsmaLips", false); ((IndicatorParameterInt)_smaLips.Parameters[0]).Bind(_lengthLips); ProcessIndicator("Lips SSMA", _smaLips); _smaTeeth = IndicatorsFactory.CreateIndicatorByName("Ssma", Name + "SsmaTeeth", false); ((IndicatorParameterInt)_smaTeeth.Parameters[0]).Bind(_lengthTeeth); ProcessIndicator("Teeth SSMA", _smaTeeth); } }
public AlligatorTrend(string name, StartProgram startProgram) : base(name, startProgram) { _startProgram = startProgram; // создаем вкладку робота TabCreate(BotTabType.Simple); _tab = TabsSimple[0]; // создаем настроечные параметры робота Regime = CreateParameter("Режим работы бота", "Off", new[] { "On", "Off", "OnlyClosePosition", "OnlyShort", "OnlyLong" }); AlligatorFastLenght = CreateParameter("Длина быстрого алигатора", 100, 50, 200, 10); AlligatorMiddleLenght = CreateParameter("Длина среднего алигатора", 100, 50, 200, 10); AlligatorSlowLenght = CreateParameter("Длина медленного алигатора", 100, 50, 200, 10); Volume = CreateParameter("Объем входа в позицию", 1.0m, 1.0m, 100.0m, 1.0m); MaxPositionCount = CreateParameter("Максимальное количество позиций", 2, 1, 10, 1); Slippage = CreateParameter("Проскальзывание (в шагах цены)", 350, 1, 500, 50); // создаем индикаторы на вкладке робота и задаем для них параметры _alligator = IndicatorsFactory.CreateIndicatorByName("Alligator", name + "Alligator", false); _alligator = (Aindicator)_tab.CreateCandleIndicator(_alligator, "Prime"); _alligator.ParametersDigit[0].Value = AlligatorSlowLenght.ValueInt; _alligator.ParametersDigit[1].Value = AlligatorFastLenght.ValueInt; _alligator.ParametersDigit[2].Value = AlligatorMiddleLenght.ValueInt; _alligator.Save(); // подписываемся на события _tab.CandleFinishedEvent += _tab_CandleFinishedEvent; ParametrsChangeByUser += AlligatorTrend_ParametrsChangeByUser; }
public override void OnStateChange(IndicatorState state) { if (state == IndicatorState.Configure) { _length = CreateParameterInt("Period", 13); _series = CreateSeries("Values", Color.LimeGreen, IndicatorChartPaintType.Column, true); _sma = IndicatorsFactory.CreateIndicatorByName("Sma", Name + "Sma", false); ((IndicatorParameterInt)_sma.Parameters[0]).Bind(_length); ProcessIndicator("Sma", _sma); } }
public override void OnStateChange(IndicatorState state) { if (state == IndicatorState.Configure) { _lenght = CreateParameterInt("Length", 5); _seriesUp = CreateSeries("SeriesUp", Color.DarkRed, IndicatorChartPaintType.Point, true); _seriesDown = CreateSeries("SeriesDown", Color.DarkGreen, IndicatorChartPaintType.Point, true); _fractial = IndicatorsFactory.CreateIndicatorByName("Fractail_lenth", Name + "Fractail", false); ((IndicatorParameterInt)_fractial.Parameters[0]).Bind(_lenght); ProcessIndicator("Fractail", _fractial); } }
public override void OnStateChange(IndicatorState state) { if (state == IndicatorState.Configure) { _lenght = CreateParameterInt("Length", 21); _deviation = CreateParameterDecimal("Deviation", 2); _seriesUp = CreateSeries("Up line", Color.Green, IndicatorChartPaintType.Line, true); _seriesCenter = CreateSeries("Centre line", Color.Green, IndicatorChartPaintType.Line, false); _seriesDown = CreateSeries("Down line", Color.Green, IndicatorChartPaintType.Line, true); _sma = IndicatorsFactory.CreateIndicatorByName("Sma", Name + "Sma", false); ((IndicatorParameterInt)_sma.Parameters[0]).Bind(_lenght); ProcessIndicator("Central SMA", _sma); } }
public override void OnStateChange(IndicatorState state) { if (state == IndicatorState.Configure) { _shortPeriod = CreateParameterInt("Short Period", 3); _longPeriod = CreateParameterInt("Long Period", 10); _seriesLine = CreateSeries("Chaikin Oscillator", Color.Gold, IndicatorChartPaintType.Line, true); _seriesLine.CanReBuildHistoricalValues = false; _seriesShort = IndicatorsFactory.CreateIndicatorByName("Sma", Name + "Short", false); ((IndicatorParameterInt)_seriesShort.Parameters[0]).Bind(_shortPeriod); ProcessIndicator("Short Period", _seriesShort); _seriesLong = IndicatorsFactory.CreateIndicatorByName("Sma", Name + "Long", false); ((IndicatorParameterInt)_seriesLong.Parameters[0]).Bind(_longPeriod); ProcessIndicator("Short Period", _seriesLong); } }
public override void OnStateChange(IndicatorState state) { if (state == IndicatorState.Configure) { _lenghtFastLine = CreateParameterInt("Fast line length", 12); _lenghtSlowLine = CreateParameterInt("Slow line length", 26); _lenghtSignalLine = CreateParameterInt("Signal line length", 9); _seriesMacd = CreateSeries("MACD", Color.DarkGreen, IndicatorChartPaintType.Line, true); _seriesSignalLine = CreateSeries("Signal line", Color.DarkRed, IndicatorChartPaintType.Line, true); _seriesMacdHistogramm = CreateSeries("MACD Histogramm", Color.DodgerBlue, IndicatorChartPaintType.Column, false); _emaFast = IndicatorsFactory.CreateIndicatorByName("Ema", Name + "Ema fast", false); ((IndicatorParameterInt)_emaFast.Parameters[0]).Bind(_lenghtFastLine); ProcessIndicator("Ema fast", _emaFast); _emaSlow = IndicatorsFactory.CreateIndicatorByName("Ema", Name + "Ema slow", false); ((IndicatorParameterInt)_emaSlow.Parameters[0]).Bind(_lenghtSlowLine); ProcessIndicator("Ema slow", _emaSlow); } }
public override void OnStateChange(IndicatorState state) { if (state == IndicatorState.Configure) { _lenghtFastLine = CreateParameterInt("Fast line length", 5); _lenghtSlowLine = CreateParameterInt("Slow line length", 32); _candlePoint = CreateParameterStringCollection("Candle point", "Typical", Entity.CandlePointsArray); _series = CreateSeries("AO", Color.DarkGreen, IndicatorChartPaintType.Column, true); _emaFast = IndicatorsFactory.CreateIndicatorByName("Ema", Name + "Ema fast", false); ((IndicatorParameterInt)_emaFast.Parameters[0]).Bind(_lenghtFastLine); ((IndicatorParameterString)_emaFast.Parameters[1]).Bind(_candlePoint); ProcessIndicator("Ema fast", _emaFast); _emaSlow = IndicatorsFactory.CreateIndicatorByName("Ema", Name + "Ema slow", false); ((IndicatorParameterInt)_emaSlow.Parameters[0]).Bind(_lenghtSlowLine); ((IndicatorParameterString)_emaSlow.Parameters[1]).Bind(_candlePoint); ProcessIndicator("Ema slow", _emaSlow); } }
/// <summary> /// Конструктор /// </summary> /// <param name="name">Имя робота</param> /// <param name="startProgram">Программа, в которой запущен робот</param> public BollingerTrend(string name, StartProgram startProgram) : base(name, startProgram) { _startProgram = startProgram; // создаем вкладку робота Simple TabCreate(BotTabType.Simple); _tab = TabsSimple[0]; // создаем настроечные параметры робота Regime = CreateParameter("Режим работы бота", "Off", new[] { "On", "Off", "OnlyClosePosition", "OnlyShort", "OnlyLong" }); OnDebug = CreateParameter("Включить отладку", false); OnDepositFixed = CreateParameter("Включить режим фикс. депозита", false); DepositFixedSize = CreateParameter("Размер фикс. депозита", 100, 100.0m, 100, 100); DepositNameCode = CreateParameter("Код инструмента, в котором депозит", "USDT", new[] { "USDT", "" }); VolumePercent = CreateParameter("Объем входа в позицию (%)", 50, 40, 300, 10); BollingerPeriod = CreateParameter("Длина болинжера", 100, 50, 200, 10); BollingerDeviation = CreateParameter("Отклонение болинжера", 1.5m, 1.0m, 3.0m, 0.2m); MethodOutOfPosition = CreateParameter("Метод выхода из позиции", "ChannelBoundary", new[] { "ChannelBoundary", "ChannelCenter" }); OnStopForBreakeven = CreateParameter("Вкл. стоп для перевода в безубытк", true); MinProfitOnStopBreakeven = CreateParameter("Мин. профит для перевода в безубытк (%)", 7, 5, 20, 1); Slippage = CreateParameter("Проскальзывание (в шагах цены)", 350, 1, 500, 50); VolumeDecimals = CreateParameter("Кол. знаков после запятой для объема", 4, 4, 10, 1); ShiftTimeExchange = CreateParameter("Разница времени с биржей", 5, -10, 10, 1); // создаем индикаторы на вкладке робота и задаем для них параметры _bollinger = IndicatorsFactory.CreateIndicatorByName("Bollinger", name + "Bollinger", false); _bollinger = (Aindicator)_tab.CreateCandleIndicator(_bollinger, "Prime"); _bollinger.ParametersDigit[0].Value = BollingerPeriod.ValueInt; _bollinger.ParametersDigit[1].Value = BollingerDeviation.ValueDecimal; _bollinger.Save(); // подписываемся на события _tab.CandleFinishedEvent += Tab_CandleFinishedEvent; _tab.PositionClosingFailEvent += Tab_PositionClosingFailEvent; _tab.PositionClosingSuccesEvent += Tab_PositionClosingSuccesEvent; _tab.PositionOpeningFailEvent += Tab_PositionOpeningFailEvent; _tab.MarketDepthUpdateEvent += Tab_MarketDepthUpdateEvent; ParametrsChangeByUser += BollingerTrend_ParametrsChangeByUser; }
public void ProcessIndicator(IIndicator indicator) { if (isPaint == false || can_draw == false) { return; } if (!series.Exists(x => x.AreaName == indicator.NameArea)) { return; } OxyArea area = all_areas.Find(x => (string)x.Tag == indicator.NameArea); if (indicator.ValuesToChart != null) { if (indicator.PaintOn == false) { UpdateIndicatorEvent?.Invoke(); // тут может быть косяк так как некоторые индюки нужно прорисовывать даже на false return; } List <List <decimal> > val_list = indicator.ValuesToChart; List <Color> colors = indicator.Colors; string name = indicator.Name; Parallel.For(0, val_list.Count, i => { if (val_list[i] == null || val_list[i].Count == 0) { return; } var seria = series.Find(x => x.SeriaName == name + i.ToString()); if (seria.OxyColor != null) { seria.OxyColor = OxyColor.FromArgb(colors[i].A, colors[i].R, colors[i].G, colors[i].B); } seria.Count = val_list.Count; try { if (area != null) { area.BuildIndicatorSeries(seria, val_list[i], time_frame_span); } } catch { return; } }); UpdateIndicatorEvent?.Invoke(); return; } Aindicator ind = (Aindicator)indicator; List <IndicatorDataSeries> indi_series = ind.DataSeries; Parallel.For(0, indi_series.Count, i => { if (indi_series[i].IsPaint == false) { return; } var seria = series.Find(x => x.SeriaName == indi_series[i].NameSeries); seria.OxyColor = OxyColor.FromArgb(indi_series[i].Color.A, indi_series[i].Color.R, indi_series[i].Color.G, indi_series[i].Color.B); seria.Count = indi_series.Count; try { if (area != null) { mediator.BuildIndicatorSeries(area, seria, indi_series[i].Values, time_frame_span); } } catch { return; } }); UpdateIndicatorEvent?.Invoke(); }
/// <summary> /// событие завершения свечи /// </summary> /// <param name="candles">массив свечек</param> /// <param name="tab">источник по которому произошло событие</param> private void NewCandleEvent(List <Candle> candles, BotTabSimple tab) { // 1 Если поза есть, то по трейлинг стопу закрываем // 2 Позы нет. Открывать лонг, если последние N свечей мы были над скользящей средней if (Regime.ValueString == "Off") { return; } if (candles.Count < 10) { return; } if (candles.Count - 1 - CandlesLookBack.ValueInt - 1 <= 0) { return; } List <Position> positions = tab.PositionsOpenAll; if (positions.Count == 0) { // логика открытия Aindicator sma = (Aindicator)tab.Indicators[0]; for (int i = candles.Count - 1; i >= 0 && i > candles.Count - 1 - CandlesLookBack.ValueInt; i--) { decimal curSma = sma.DataSeries[0].Values[i]; if (curSma == 0) { return; } if (candles[i].Close < curSma) { return; } } if (candles[candles.Count - 1 - CandlesLookBack.ValueInt - 1].Close > sma.DataSeries[0].Values[candles.Count - 1 - CandlesLookBack.ValueInt - 1]) { return; } tab.BuyAtLimit(Volume.ValueDecimal, tab.PriceBestAsk + tab.Securiti.PriceStep * Slippage.ValueInt); } else { Position pos = positions[0]; if (pos.State != PositionStateType.Open) { return; } decimal close = candles[candles.Count - 1].High; decimal priceActivation = close - close * TrailStop.ValueDecimal / 100; decimal priceOrder = priceActivation - tab.Securiti.PriceStep * Slippage.ValueInt; tab.CloseAtTrailingStop(pos, priceActivation, priceOrder); } }