Exemple #1
0
        private void addToWatchListMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                common.controls.baseDataGridView resultDataGrid = this.CurrentDataGridView;
                if (resultDataGrid == null)
                {
                    return;
                }

                string           stockCode     = resultTab.SelectedTab.Name;
                StringCollection strategyCodes = new StringCollection();
                for (int idx = 0; idx < resultDataGrid.SelectedRows.Count; idx++)
                {
                    if (resultDataGrid.SelectedRows[idx] == null)
                    {
                        continue;
                    }
                    application.Strategy.StrategyMeta meta = application.Strategy.StrategyLibs.FindMetaByName(resultDataGrid.SelectedRows[idx].Cells[0].Value.ToString());
                    strategyCodes.Add(meta.Code);
                }
                if (strategyCodes.Count > 0)
                {
                    this.AddStockToWatchList(stockCode, strategyCodes, timeScaleCb.myValue);
                }
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
Exemple #2
0
 private void EditScreeningOption(string code)
 {
     application.Strategy.StrategyMeta meta = application.Strategy.StrategyLibs.FindMetaByCode(code);
     if (meta == null)
     {
         return;
     }
     application.Strategy.StrategyLibs.ShowStrategyForm(meta);
 }
        public void PlotStrategyTradepoints(application.Strategy.StrategyMeta meta, bool showEstimation, EstimateTradePointFunc estimateFunc)
        {
            ShowMessage("");
            EstimateOptions estOption = new EstimateOptions();

            databases.tmpDS.tradeEstimateDataTable tbl = new databases.tmpDS.tradeEstimateDataTable();
            TradePointInfo[] tradePoints = DataAccess.Libs.GetTradePointWithEstimationDetail(myData.myDataParam, myData.DataStockCode, meta.Code,
                                                                                             estOption, out tbl);
            /// Estimate trade points and set tradepoint's [isValid] property to mark whether a tradepoint is valid or not.
            for (int idx = 0; idx < tradePoints.Length; idx++)
            {
                tradePoints[idx].isValid = !tbl[idx].ignored;
            }
            PlotStrategyTradepoints(application.Strategy.StrategyLibs.ToTradePoints(tradePoints), pricePanel);

            //Call estimation handler if any.
            if (showEstimation && estimateFunc != null)
            {
                estimateFunc(this, meta.Code, estOption, tbl);
            }
        }
Exemple #4
0
        private void LoadScreeningCodes()
        {
            tmpDS.screeningCode.Clear();
            tmpDS.screeningCriteria.Clear();
            string[] screeningKeys   = application.Strategy.StrategyData.MetaList.Keys;
            object[] screeningValues = application.Strategy.StrategyData.MetaList.Values;
            Data.tmpDataSet.screeningCodeRow row;
            for (int idx = 0; idx < screeningKeys.Length; idx++)
            {
                application.Strategy.StrategyMeta meta = (application.Strategy.StrategyMeta)screeningValues[idx];
                if (meta.Type != AppTypes.StrategyTypes.Screening)
                {
                    continue;
                }
                row             = tmpDS.screeningCode.NewscreeningCodeRow();
                row.code        = meta.Code;
                row.description = meta.Name;
                tmpDS.screeningCode.AddscreeningCodeRow(row);

                //As default add all criteria to allow users select what they need more quickly.
                AddCriteria(row.code, false);
            }
        }
Exemple #5
0
        private void profitDetailMenu_Click(object sender, EventArgs e)
        {
            try
            {
                common.controls.baseDataGridView resultDataGrid = this.CurrentDataGridView;
                if (resultDataGrid == null || resultDataGrid.CurrentRow == null || resultDataGrid.CurrentCell == null)
                {
                    return;
                }

                //TUAN - 29 Sept 2012 fix bug profit detail and all profit details
                if (resultDataGrid.CurrentCell.ColumnIndex < 0)
                {
                    return;
                }
                //TUAN - 29 Sept 2012 fix bug profit detail and all profit details

                string stockCode = resultTab.SelectedTab.Name;
                databases.tmpDS.stockCodeRow stockCodeRow = DataAccess.Libs.myStockCodeTbl.FindBycode(stockCode);
                if (stockCodeRow == null)
                {
                    return;
                }
                application.Strategy.StrategyMeta meta = application.Strategy.StrategyLibs.FindMetaByName(resultDataGrid.CurrentRow.Cells[0].Value.ToString());

                //TUAN - 29 Sept 2012 fix bug profit detail and all profit details
                int colId = resultDataGrid.CurrentCell.ColumnIndex == 0 ? 1 : resultDataGrid.CurrentCell.ColumnIndex;
                //TUAN - 29 Sept 2012 fix bug profit detail and all profit details
                DataParams dataParam = new DataParams(timeScaleCb.myValue.Code, AppTypes.TimeRangeFromCode(resultDataGrid.Columns[colId].DataPropertyName), 0);
                ShowTradeTransactions(stockCodeRow, meta.Code, dataParam);
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }
        //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);
        }
        public void PlotStrategyTradepoints(application.Strategy.StrategyMeta meta, bool showEstimation, EstimateTradePointFunc estimateFunc)
        {
            int idx;

            ShowMessage("");
            EstimateOptions estOption = new EstimateOptions();

            databases.tmpDS.tradeEstimateDataTable tbl        = new databases.tmpDS.tradeEstimateDataTable();
            application.StrategyStatistics         statistics = new StrategyStatistics();
            //TradePointInfo[]
            tradePoints = DataAccess.Libs.GetTradePointWithEstimationDetail(myData.myDataParam, myData.DataStockCode, meta.Code,
                                                                            estOption, out tbl, out statistics);
            /// Estimate trade points and set tradepoint's [isValid] property to mark whether a tradepoint is valid or not.
            for (idx = 0; idx < tradePoints.Length; idx++)
            {
                tradePoints[idx].isValid = !tbl[idx].ignored;
            }

            for (idx = tradePoints.Length - 1; idx > 0; idx--)
            {
                if (tradePoints[idx].isValid)
                {
                    break;
                }
            }

            TradePointInfo tpiTradePointInfo = (TradePointInfo)tradePoints[idx];
            BusinessInfo   biLastTrade       = tpiTradePointInfo.BusinessInfo;
            BusinessInfo   biLastPoint       = tradePoints[tradePoints.Length - 1].BusinessInfo;

            double price = myData.Close[myData.Close.Count - 1];
            double risk  = (biLastPoint.Short_Resistance - price) / (price - biLastPoint.Short_Support);

            //string sResult = "Close price=" + price+
            //                 "Target="+biLastTrade.Short_Target+
            //                 "Resistance=" + biLastPoint.Short_Resistance +
            //                 " Support=" + biLastPoint.Short_Support +
            //                 " Risk return=" +risk+
            //                 " Winning Percentage:"+ String.Format("{0:P2}",statistics.dWinningPercentagePerTrade)+
            //                 " Max %Win Per Trade:" +  String.Format("{0:P2}",statistics.dMaxWinningPercentage)+
            //                 " Max %Lose Per Trade" + String.Format("{0:P2}", statistics.dMaxLosingPercentage)+
            //                 " Average %Win Per Trade" + String.Format("{0:P2}", statistics.dAverageWinningPercentage)+
            //                 " Average %Lose Per Trade" + String.Format("{0:P2}", statistics.dAverageLosingPercentage); ;

            PlotStrategyTradepoints(application.Strategy.StrategyLibs.ToTradePoints(tradePoints), pricePanel);



            //MessageBox.Show(sResult);
            //Show form
            Tools.Forms.TradeStatistics formStatistic = new Tools.Forms.TradeStatistics();
            formStatistic.AddStatisticInfo("Close price", price);
            formStatistic.AddStatisticInfo("Target", biLastTrade.Short_Target);
            formStatistic.AddStatisticInfo("Resistance", biLastPoint.Short_Resistance);
            formStatistic.AddStatisticInfo("Support", biLastPoint.Short_Support);
            formStatistic.AddStatisticInfo("Risk return", risk);
            formStatistic.AddStatisticInfo("Winning Percentage", String.Format("{0:P2}", statistics.dWinningPercentagePerTrade));
            formStatistic.AddStatisticInfo("Max %Win Per Trade", String.Format("{0:P2}", statistics.dMaxWinningPercentage));
            formStatistic.AddStatisticInfo("Max %Lose Per Trade", String.Format("{0:P2}", statistics.dMaxLosingPercentage));
            formStatistic.AddStatisticInfo("Average %Win Per Trade", String.Format("{0:P2}", statistics.dAverageWinningPercentage));
            formStatistic.AddStatisticInfo("Average %Lose Per Trade", String.Format("{0:P2}", statistics.dAverageLosingPercentage));

            formStatistic.Show(this.DockPanel, DockState.DockRightAutoHide);

            //Call estimation handler if any.
            if (showEstimation && estimateFunc != null)
            {
                estimateFunc(this, meta.Code, estOption, tbl);
            }
        }
Exemple #8
0
        private void allProfitDetailMenu_Click(object sender, EventArgs e)
        {
            try
            {
                using (new DataAccess.PleaseWait())
                {
                    common.controls.baseDataGridView resultDataGrid = this.CurrentDataGridView;
                    if (resultDataGrid == null)
                    {
                        return;
                    }

                    string stockCode = resultTab.SelectedTab.Name;
                    databases.tmpDS.stockCodeRow stockCodeRow = DataAccess.Libs.myStockCodeTbl.FindBycode(stockCode);
                    if (stockCodeRow == null)
                    {
                        return;
                    }

                    DataParams dataParam = new DataParams(timeScaleCb.myValue.Code, AppTypes.TimeRanges.None, 0);
                    //TUAN - 29 Sept 2012 fix bug profit detail and all profit details
                    int min = int.MaxValue;
                    int max = -1;
                    for (int i = 0; i < resultDataGrid.SelectedCells.Count; i++)
                    {
                        if (resultDataGrid.SelectedCells[i].RowIndex > max)
                        {
                            max = resultDataGrid.SelectedCells[i].RowIndex;
                        }
                        if (resultDataGrid.SelectedCells[i].RowIndex < min)
                        {
                            min = resultDataGrid.SelectedCells[i].RowIndex;
                        }
                    }
                    //if (resultDataGrid.SelectedRows.Count > 0)
                    if (min < max)
                    {
                        for (int rowId = min; rowId <= max; rowId++)
                        {
                            application.Strategy.StrategyMeta meta = application.Strategy.StrategyLibs.FindMetaByName(resultDataGrid.Rows[rowId].Cells[0].Value.ToString());
                            for (int idx = 1; idx < resultDataGrid.ColumnCount; idx++)
                            {
                                dataParam.TimeRange = AppTypes.TimeRangeFromCode(resultDataGrid.Columns[idx].DataPropertyName);
                                ShowTradeTransactions(stockCodeRow, meta.Code, dataParam);
                            }
                        }
                        //for (int rowId = 0; rowId < resultDataGrid.SelectedRows.Count; rowId++)
                        //{
                        //    application.Strategy.StrategyMeta meta = application.Strategy.StrategyLibs.FindMetaByName(resultDataGrid.SelectedRows[rowId].Cells[0].Value.ToString());
                        //    for (int idx = 1; idx < resultDataGrid.ColumnCount; idx++)
                        //    {
                        //        dataParam.TimeRange = AppTypes.TimeRangeFromCode(resultDataGrid.Columns[idx].DataPropertyName);
                        //        ShowTradeTransactions(stockCodeRow, meta.Code, dataParam);
                        //    }
                        //}
                    }
                    //TUAN - 29 Sept 2012 fix bug profit detail and all profit details
                    else
                    {
                        if (resultDataGrid.CurrentRow != null)
                        {
                            application.Strategy.StrategyMeta meta = application.Strategy.StrategyLibs.FindMetaByName(resultDataGrid.CurrentRow.Cells[0].Value.ToString());
                            for (int idx = 1; idx < resultDataGrid.ColumnCount; idx++)
                            {
                                dataParam.TimeRange = AppTypes.TimeRangeFromCode(resultDataGrid.Columns[idx].DataPropertyName);
                                ShowTradeTransactions(stockCodeRow, meta.Code, dataParam);
                            }
                        }
                    }
                }
            }
            catch (Exception er)
            {
                this.ShowError(er);
            }
        }