Ejemplo n.º 1
0
        override protected void StrategyExecute()
        {
            TimeSeriesRule timeSeriesRule  = new TimeSeriesRule(data.Close, parameters[0]);
            LinearRegRule  lngRule         = new LinearRegRule(data.Close, parameters[1]);
            int            cutlosslevel    = (int)parameters[2];
            int            takeprofitlevel = (int)parameters[3];

            for (int idx = timeSeriesRule.tsf.FirstValidValue; idx < timeSeriesRule.tsf.Count; idx++)
            {
                //Buy Condition
                if ((timeSeriesRule.isValid_forBuy(idx) && lngRule.UpTrend(idx)) ||
                    (lngRule.isValid_forBuy(idx) && timeSeriesRule.UpTrend(idx)))
                {
                    BuyAtClose(idx);
                }

                //Sell Condition
                if (timeSeriesRule.isValid_forSell(idx) || lngRule.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.º 2
0
        override protected void StrategyExecute()
        {
            TimeSeriesRule timeSeriesRule = new TimeSeriesRule(data.Close, parameters[0]);
            LinearRegRule lngRule = new LinearRegRule(data.Close, parameters[1]);
            int cutlosslevel = (int)parameters[2];
            int takeprofitlevel = (int)parameters[3];

            for (int idx = timeSeriesRule.tsf.FirstValidValue; idx < timeSeriesRule.tsf.Count; idx++)
            {
                //Buy Condition
                if ((timeSeriesRule.isValid_forBuy(idx)&&lngRule.UpTrend(idx))
                    ||(lngRule.isValid_forBuy(idx)&&timeSeriesRule.UpTrend(idx)))
                    BuyAtClose(idx);

                //Sell Condition
                if (timeSeriesRule.isValid_forSell(idx)||lngRule.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);
            }
        }