Ejemplo n.º 1
0
        override protected void StrategyExecute()
        {
            BasicDMIRule rule = new BasicDMIRule(data.Bars, parameters[0], parameters[1]);

            Indicators.MIN min = Indicators.MIN.Series(data.Close, parameters[0], "min");
            Indicators.MAX max = Indicators.MAX.Series(data.Close, parameters[1], "max");

            for (int idx = 0; idx < data.Close.Count; idx++)
            {
                if (rule.isValid_forBuy(idx))
                {
                    BusinessInfo info = new BusinessInfo();
                    info.SetTrend(AppTypes.MarketTrend.Upward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
                    info.Short_Target = max[idx];
                    info.Stop_Loss    = min[idx];
                    BuyAtClose(idx, info);
                }
                else
                if (rule.isValid_forSell(idx))
                {
                    BusinessInfo info = new BusinessInfo();
                    info.SetTrend(AppTypes.MarketTrend.Downward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
                    info.Short_Target = min[idx];
                    info.Stop_Loss    = max[idx];
                    SellAtClose(idx, info);
                }
            }
        }
Ejemplo n.º 2
0
        override protected void StrategyExecute()
        {
            BasicDMIRule rule = new BasicDMIRule(data.Bars, parameters[0], parameters[1]);

            int cutlosslevel    = (int)parameters[2];
            int takeprofitlevel = (int)parameters[3];

            for (int idx = rule.minusDmi.FirstValidValue; idx < rule.minusDmi.Count; idx++)
            {
                //Buy Condition
                if (rule.isValid_forBuy(idx))
                {
                    BuyAtClose(idx);
                }

                //Sell Condition
                if (rule.isValid_forSell(idx))
                {
                    SellAtClose(idx);
                }

                if (is_bought && CutLossCondition(data.Close[idx], buy_price, cutlosslevel))
                {
                    SellCutLoss(idx);
                }

                if (is_bought && TakeProfitCondition(data.Close[idx], buy_price, takeprofitlevel))
                {
                    SellTakeProfit(idx);
                }
            }
        }
Ejemplo n.º 3
0
        override protected void StrategyExecute()
        {
            BasicDMIRule rule = new BasicDMIRule(data.Bars, parameters[0], parameters[1]);

            Indicators.MIN min = Indicators.MIN.Series(data.Close, parameters[0], "min");
            Indicators.MAX max = Indicators.MAX.Series(data.Close, parameters[1], "max");

            int cutlosslevel      = (int)parameters[2];
            int trailingstoplevel = (int)parameters[3];
            int takeprofitlevel   = (int)parameters[4];

            for (int idx = 0; idx < data.Close.Count; idx++)
            {
                if (rule.isValid_forBuy(idx))
                {
                    BusinessInfo info = new BusinessInfo();
                    info.SetTrend(AppTypes.MarketTrend.Upward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
                    info.Short_Target = max[idx];
                    info.Stop_Loss    = min[idx];
                    BuyAtClose(idx, info);
                }
                else
                if (rule.isValid_forSell(idx))
                {
                    BusinessInfo info = new BusinessInfo();
                    info.SetTrend(AppTypes.MarketTrend.Downward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
                    info.Short_Target = min[idx];
                    info.Stop_Loss    = max[idx];
                    SellAtClose(idx, info);
                }
                if (is_bought && CutLossCondition(data.Close[idx], buy_price, cutlosslevel))
                {
                    SellCutLoss(idx);
                }

                if (is_bought && TakeProfitCondition(data.Close[idx], buy_price, takeprofitlevel))
                {
                    SellTakeProfit(idx);
                }

                if (trailingstoplevel > 0)
                {
                    TrailingStopWithBuyBack(rule, data.Close[idx], trailingstoplevel, idx);
                }
            }
        }