override public TradePoints Execute(application.Data data, int[] parameters) { //application.Data vnidxData1 = data.New("^VNINDEX"); adviceInfo = new TradePoints(); DataSeries minusDmi_14 = new Indicators.MinusDI(data.Bars, parameters[0], ""); DataSeries plusDmi_14 = new Indicators.PlusDI(data.Bars, parameters[1], ""); AppTypes.MarketTrend lastTrend = AppTypes.MarketTrend.Unspecified; AppTypes.MarketTrend currentTrend = AppTypes.MarketTrend.Unspecified; for (int idx = 0; idx < minusDmi_14.Count; idx++) { currentTrend = ((plusDmi_14[idx] > minusDmi_14[idx]) ? AppTypes.MarketTrend.Upward : AppTypes.MarketTrend.Downward); if (lastTrend == AppTypes.MarketTrend.Downward && currentTrend == AppTypes.MarketTrend.Upward) { BuyAtClose(idx); } if (lastTrend == AppTypes.MarketTrend.Upward && currentTrend == AppTypes.MarketTrend.Downward) { SellAtClose(idx); } lastTrend = currentTrend; } return(adviceInfo); }
private void DoRanking() { this.myValueType = ValueTypes.Amount; this.Amount2PercentDenominator = application.Settings.sysStockTotalCapAmt; resultTab.TabPages.Clear(); StringCollection stockCodeList = stockCodeSelectLb.myValues; StringCollection strategyList = strategyClb.myCheckedValues; StringCollection timeRangeList = timeRangeLb.myCheckedValues; progressBar.Value = 0; progressBar.Minimum = 0; progressBar.Maximum = stockCodeList.Count * timeRangeList.Count; for (int stockCodeId = 0; stockCodeId < stockCodeList.Count; stockCodeId++) { string stockCode = stockCodeList[stockCodeId].ToString(); DataTable testRetsultTbl = CreateDataTable(timeRangeList, strategyList); common.controls.baseDataGridView resultGrid = CreateResultGrid(stockCode, testRetsultTbl); for (int colId = 0; colId < timeRangeList.Count; colId++) { AppTypes.TimeRanges timeRange = AppTypes.TimeRangeFromCode(timeRangeList[colId]); decimal profit = 0; application.Data analysisData = new application.Data(timeRange, cbTimeScale.myValue, stockCode); for (int rowId = 0; rowId < strategyList.Count; rowId++) { profit = 0; //Analysis cached data so we MUST clear cache to ensure the system run correctly Strategy.Data.ClearCache(); Strategy.TradePoints advices = Strategy.Libs.Analysis(analysisData, strategyList[rowId]); if (advices != null) { myTmpDS.tradeEstimate.Clear(); Strategy.Libs.EstimateTrading(analysisData, advices, new Strategy.Libs.EstimateOptions(), myTmpDS.tradeEstimate); profit = (myTmpDS.tradeEstimate.Count == 0 ? 0 : profit = myTmpDS.tradeEstimate[myTmpDS.tradeEstimate.Count - 1].profit); } testRetsultTbl.Rows[rowId][colId + 1] = profit; } progressBar.Value++; Application.DoEvents(); } } FormResize(); }