Ejemplo n.º 1
0
 internal void Validate()
 {
     if (Adx != null && Scripts != null)
     {
         throw new DeltaException(
                   "Both 'adx' and 'scripts' can't both be populated in a source");
     }
     if (Adx == null && Scripts == null)
     {
         throw new DeltaException(
                   "Either 'adx' or 'scripts' must be populated in a source");
     }
     if (Adx != null)
     {
         try
         {
             Adx.Validate();
         }
         catch (DeltaException ex)
         {
             throw new DeltaException("Issue with 'adx'", ex);
         }
     }
     else if (!Scripts !.Any())
     {
         throw new DeltaException("'scripts' can't be empty in a source");
     }
Ejemplo n.º 2
0
        // сервис
        public StrategyBreakout(string name, StartProgram startProgram) : base(name, startProgram)
        {
            TabCreate(BotTabType.Simple);
            _tab = TabsSimple[0];

            _adx = new Adx(name + "Adx", false)
            {
                Lenght    = 14,
                ColorBase = Color.DodgerBlue,
                PaintOn   = true,
            };

            _adx = _tab.CreateCandleIndicator(_adx, "adxArea");
            _adx.Save();

            _alert      = new AlertToPrice(NameStrategyUniq);
            _alert.IsOn = false;
            _tab.DeleteAllAlerts();
            _tab.SetNewAlert(_alert);

            _tab.CandleFinishedEvent += StrategyAdxVolatility_CandleFinishedEvent;

            IsOn                = false;
            Volume              = 1;
            SlipageOpenSecond   = 0;
            SlipageCloseSecond  = 0;
            TimeFrom            = 10;
            TimeTo              = 22;
            AlertIsOn           = false;
            EmulatorIsOn        = false;
            LagTimeToOpenClose  = new TimeSpan(0, 0, 0, 15);
            LagPunctToOpenClose = 20;

            AdxHigh        = 20;
            Lookback       = 20;
            TrailBars      = 5;
            SlipageToAlert = 10;
            Load();

            Thread worker = new Thread(TimeWatcherArea);

            worker.IsBackground = true;
            worker.Start();

            Thread worker2 = new Thread(WatcherOpenPosition);

            worker2.IsBackground = true;
            worker2.Start();

            Thread worker3 = new Thread(AreaCloserPositionThread);

            worker3.IsBackground = true;
            worker3.Start();

            _tab.OrderUpdateEvent         += _tab_OrderUpdateEvent;
            _tab.NewTickEvent             += _tab_NewTickEvent;
            _tab.PositionClosingFailEvent += _tab_PositionClosingFailEvent;
            _tab.PositionOpeningFailEvent += _tab_PositionOpeningFailEvent;
        }
Ejemplo n.º 3
0
        public static List <decimal?> Adx(this IEnumerable <ICandle> candles, int?period = null)
        {
            period ??= 14;

            IIndicatorOptions options = new AdxOptions(period.Value);
            Adx sma = new Adx();

            return(sma.Get(candles, options));
        }
        internal static TradeIdeasGeneratorArgument Create(List <Signal> signals, HistoricalData historicalData)
        {
            TradeIdeasGeneratorArgument result = new TradeIdeasGeneratorArgument();

            SmaVol smaVol20 = new SmaVol(20);
            Sma    sma50    = new Sma(50);
            Rsi    stRsi5   = new Rsi(5);
            Rsi    rsi14    = new Rsi(14);
            Rsi    ltrsi50  = new Rsi(50);
            Cci    stCci5   = new Cci(5);
            Cci    cci14    = new Cci(14);
            Cci    ltCci50  = new Cci(50);
            Stoch  stoch14  = new Stoch(14, 14, 3);
            WillR  willr14  = new WillR(14);
            Mfi    mfi14    = new Mfi(14);
            Adx    adx20    = new Adx(20);
            Atr    atr20    = new Atr(20);

            //Assuming that signals are sorted by dates descending and all signals are present. otherwize an exception will be thrown during fetching signals (First())

            #region Indicators

            result.Rsi14           = GetValue(signals.LatestForIndicator(rsi14));
            result.YesterdayRsi14  = GetValue(signals.PreviousForIndicator(rsi14, 1));
            result.StRsi5          = GetValue(signals.LatestForIndicator(stRsi5));
            result.YesterdayStRsi5 = GetValue(signals.PreviousForIndicator(stRsi5, 1));
            result.LtRsi50         = GetValue(signals.LatestForIndicator(ltrsi50));

            result.Cci14           = GetValue(signals.LatestForIndicator(cci14));
            result.YesterdayCci14  = GetValue(signals.PreviousForIndicator(cci14, 1));
            result.StCci5          = GetValue(signals.LatestForIndicator(stCci5));
            result.YesterdayStCci5 = GetValue(signals.PreviousForIndicator(stCci5, 1));
            result.LtCci50         = GetValue(signals.LatestForIndicator(ltCci50));

            result.Stoch14          = GetValue(signals.LatestForIndicator(stoch14));
            result.YesterdayStoch14 = GetValue(signals.PreviousForIndicator(stoch14, 1));

            result.WillR14          = GetValue(signals.LatestForIndicator(willr14));
            result.YesterdayWillR14 = GetValue(signals.PreviousForIndicator(willr14, 1));

            result.Mfi14          = GetValue(signals.LatestForIndicator(mfi14));
            result.YesterdayMfi14 = GetValue(signals.PreviousForIndicator(mfi14, 1));

            result.SmaVol20 = GetValue(signals.LatestForIndicator(smaVol20));
            result.Sma50    = GetValue(signals.LatestForIndicator(sma50));

            result.Adx20 = GetValue(signals.LatestForIndicator(adx20));

            result.Atr20 = GetValue(signals.LatestForIndicator(atr20));

            //Long Term Sentiment(6 months)
            Signal syrahSentiment = signals.LatestForIndicator(LongTermSentimentForDependencies);
            int?   sentimentValue = syrahSentiment == null
                ? null
                : (int?)syrahSentiment.Value;
            result.LongTermSentiment = SyrahSentiment.MakeInterpretationInTermsOfSentiment(sentimentValue);

            //Short Term Sentiment(1 month)
            syrahSentiment = signals.LatestForIndicator(ShortTermSentimentForDependencies);
            sentimentValue = syrahSentiment == null
                ? null
                : (int?)syrahSentiment.Value;
            result.ShortTermSentiment = SyrahSentiment.MakeInterpretationInTermsOfSentiment(sentimentValue);

            #endregion

            //if (expandedQuote == null)
            //{
            //    result.LastPrice = historicalData.Close[historicalData.Count - 1];
            //}
            //else
            //{
            //    result.LastPrice = expandedQuote.Last;
            //    result.HasOption = expandedQuote.HasOption;
            //}

            result.RangeStdDev = historicalData.GetPriceRangeStdDevFor6Months();

            //result.NearestSupport = supportAndResistance.GetClosestSupport(expandedQuote.Last);
            //result.NearestResistance = supportAndResistance.GetClosestResistance(expandedQuote.Last);

            //TODO: check
            int yesterdayIndex = historicalData.High.Length - 2;
            result.YesterdayHigh = historicalData.High[yesterdayIndex];
            result.YesterdayLow  = historicalData.Low[yesterdayIndex];

            return(result);
        }