Пример #1
0
        /// <summary>
        /// Calculation of Thrust indicators
        /// </summary>
        /// <param name="ds">data to calculate CCI</param>
        /// <param name="period">period to calculate</param>
        /// <param name="name"></param>
        public Market_TRIN(DataSeries ds, string name)
            : base(ds, name)
        {
            //application.Data stockData = new application.Data(AppTypes.TimeRanges.Y1, AppTypes.TimeScaleFromCode("D1"), "SSI");

            application.MarketData market          = new application.MarketData(AppTypes.TimeRanges.Y1, AppTypes.TimeScaleFromType(AppTypes.TimeScaleTypes.Day));
            DataSeries             advancingIssues = market.AdvancingIssues;
            DataSeries             decliningIssues = market.DecliningIssues;

            DataSeries advancingVolume = market.AdvancingVolume;
            DataSeries decliningVolume = market.DecliningVolume;

            DataSeries result1 = advancingIssues / decliningIssues;
            DataSeries result2 = advancingVolume / decliningVolume;

            DataSeries result3 = result1 / result2;

            int begin = 0;

            FirstValidValue = 0;
            this.Name       = name;
            for (int i = begin, j = 0; j < result3.Count; i++, j++)
            {
                this[i] = result3[j] * 100;
            }
        }
Пример #2
0
        //public static int CreateTradeAlert()
        //{
        //    CreateTradeAlert(null, null, null);
        //}
        public static int CreateTradeAlert(onProcessStart onStartFunc, onProcessItem onProcessItemFunc, onProcessEnd onEndFunc)
        {
            DateTime frDate = common.Consts.constNullDate;
            DateTime toDate = DateTime.Now;

            //Run all strategy analysis for all stocks.
            databases.tmpDS.stockCodeDataTable stockCodeTbl = new databases.tmpDS.stockCodeDataTable();
            databases.DbAccess.LoadData(stockCodeTbl, AppTypes.CommonStatus.Enable);

            application.AnalysisData data = new application.AnalysisData();
            data.DataTimeRange = AppTypes.TimeRanges.None;
            data.DataMaxCount  = Settings.sysGlobal.AlertDataCount;

            TradeAlertItem[] tradeAlertList = new TradeAlertItem[0];
            StringCollection strategyList   = new StringCollection();

            for (int idx = 0; idx < StrategyData.MetaList.Values.Length; idx++)
            {
                application.Strategy.StrategyMeta meta = (application.Strategy.StrategyMeta)StrategyData.MetaList.Values[idx];
                if (meta.Type != AppTypes.StrategyTypes.Strategy)
                {
                    continue;
                }
                strategyList.Add(((application.Strategy.StrategyMeta)StrategyData.MetaList.Values[idx]).Code);
            }

            if (onStartFunc != null)
            {
                onStartFunc(stockCodeTbl.Count);
            }

            DateTime alertDate;
            DateTime alertFrDate = toDate.Date;
            DateTime alertToDate = toDate;

            for (int stockCodeIdx = 0; stockCodeIdx < stockCodeTbl.Count; stockCodeIdx++)
            {
                if (onProcessItemFunc != null)
                {
                    if (!onProcessItemFunc(stockCodeTbl[stockCodeIdx].code))
                    {
                        break;
                    }
                }

                //foreach (AppTypes.TimeScale timeScale in AppTypes.myTimeScales) //???
                AppTypes.TimeScale timeScale = AppTypes.TimeScaleFromType(AppTypes.TimeScaleTypes.Day);
                {
                    data.DataStockCode = stockCodeTbl[stockCodeIdx].code;
                    data.DataTimeScale = timeScale;
                    data.LoadData();
                    for (int strategyIdx = 0; strategyIdx < strategyList.Count; strategyIdx++)
                    {
                        StrategyData.ClearCache();
                        TradePoints advices = application.Strategy.StrategyLibs.AnalysisStrategy(data, strategyList[strategyIdx].Trim());

                        if ((advices == null) || (advices.Count == 0))
                        {
                            continue;
                        }

                        //Only check the last advices for alert
                        TradePointInfo tradeInfo = (TradePointInfo)advices[advices.Count - 1];
                        alertDate = DateTime.FromOADate(data.DateTime[tradeInfo.DataIdx]);

                        //Ignore alerts that out of date range.
                        if (alertDate < alertFrDate || alertDate > alertToDate)
                        {
                            continue;
                        }
                        Array.Resize(ref tradeAlertList, tradeAlertList.Length + 1);

                        tradeAlertList[tradeAlertList.Length - 1] = new TradeAlertItem(stockCodeTbl[stockCodeIdx].code.Trim(), strategyList[strategyIdx].Trim(),
                                                                                       timeScale, alertDate,
                                                                                       data.Close[tradeInfo.DataIdx],
                                                                                       data.Volume[tradeInfo.DataIdx], tradeInfo);
                    }
                }
            }
            //Create alerts in the day
            int noAlertCreated = CreateTradeAlert(tradeAlertList);

            //Save last lun date
            //SaveLastRunTime(toDate);
            if (onEndFunc != null)
            {
                onEndFunc();
            }
            stockCodeTbl.Dispose();
            return(noAlertCreated);
        }
Пример #3
0
        /// <summary>
        /// Calculation of Thrust indicators
        /// </summary>
        /// <param name="ds">data to calculate CCI</param>
        /// <param name="period">period to calculate</param>
        /// <param name="name"></param>
        public Market_BreadthTrust(DataSeries ds, double period, string name)
            : base(ds, name)
        {
            //application.Data stockData = new application.Data(AppTypes.TimeRanges.Y1, AppTypes.TimeScaleFromCode("D1"), "SSI");
            application.MarketData market          = new application.MarketData(AppTypes.TimeRanges.Y1, AppTypes.TimeScaleFromType(AppTypes.TimeScaleTypes.Day));
            DataSeries             advancingIssues = market.AdvancingIssues;
            DataSeries             decliningIssues = market.DecliningIssues;

            DataSeries emaAdvancingIssues = Indicators.EMA.Series(advancingIssues, period, "emaAdvancingIssues");
            DataSeries emaTotalIssues     = Indicators.EMA.Series(advancingIssues + decliningIssues, period, "emaTotalIssues");

            DataSeries result3 = emaAdvancingIssues / emaTotalIssues;

            int begin = 0;

            FirstValidValue = 0;
            this.Name       = name;
            for (int i = begin, j = 0; j < result3.Count; i++, j++)
            {
                this[i] = result3[j] * 100;
            }
        }