Ejemplo n.º 1
0
 /// <summary>
 /// Buy at close with info
 /// </summary>
 /// <param name="index"></param>
 /// <param name="info"></param>
 public void BuyAtClose(int index, BusinessInfo info)
 {
     adviceInfo.Add(AppTypes.TradeActions.Buy, index,info);
     is_bought = true;
     last_position = index;
     buy_price = data.Close[index];
 }
Ejemplo n.º 2
0
 public void Set(BusinessInfo info)
 {
     this.ShortTermTrend = info.ShortTermTrend;
     this.MediumTermTrend = info.MediumTermTrend;
     this.LongTermTrend = info.LongTermTrend;
     this.Weight = info.Weight;
 }
Ejemplo n.º 3
0
        override protected void StrategyExecute()
        {
            int Bar = data.Close.Count - 1;
            if (Bar <= 1) return;
            // Dong sau tao mot data moi cua ^VNINDEX 
            application.AnalysisData vnidxData = data.New("^VNINDEX");
            int Barindex = vnidxData.Close.Count - 1;
            if (Barindex <= 1) return;
//            if (Bar == vnidxData.Close.Count - 1)
            {

                int period = (int)parameters[0];

                Indicators.ROCR100 roc = Indicators.ROCR100.Series(data.Close, period, "");
                Indicators.ROCR100 roc_index = Indicators.ROCR100.Series(vnidxData.Close, period, "");

                if (roc_index[Barindex] != 0)
                {
                    double rs = roc[Bar] / roc_index[Barindex];
                    BusinessInfo info = new BusinessInfo();
                    info.Weight = rs * 100;
                    SelectStock(Bar, info);
                }
                //if (roc_index[Bar] != 0)
                //{
                //    double rs = roc[Bar] / roc_index[Bar];
                //    BusinessInfo info = new BusinessInfo();
                //    info.Weight = rs * 100;
                //    SelectStock(Bar, info);
                //}
            }
        }
Ejemplo n.º 4
0
        override protected void StrategyExecute()
        {
            BasicSARRule sarRule = new BasicSARRule(data.Bars, parameters[0], parameters[1]);
            TwoEMARule emaRule = new TwoEMARule(data.Close, parameters[2], parameters[3]);
            int cutlosslevel = (int)parameters[4];
            int takeprofitlevel = (int)parameters[5];


            for (int idx = 0; idx < data.Close.Count; idx++)
            {
                if ((!is_bought) && ((sarRule.isValid_forBuy(idx) && emaRule.UpTrend(idx))))
                {
                    BusinessInfo info = new BusinessInfo();
                    info.SetTrend(AppTypes.MarketTrend.Upward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
                    BuyAtClose(idx, info);
                }
                if (is_bought && (sarRule.isValid_forSell(idx) || emaRule.isValid_forSell(idx)))
                //if (dmiRule.isValid_forSell(idx))
                {
                    BusinessInfo info = new BusinessInfo();
                    info.SetTrend(AppTypes.MarketTrend.Downward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
                    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);
            }
        }
Ejemplo n.º 5
0
        override protected void StrategyExecute()
        {
            int weight = 0; //weight the hien weight cua 

            int period = (int)parameters[0];
            //double distance = (double)parameters[1];

            int Bar = data.Close.Count - 1;
            if (Bar <= 1) return;
            //double support = strategyLib.findSupport(data.Close, Bar, period);
            //if (support == -1) return;
            //if ((data.Close[Bar] - support) / support * 100 < distance)
            //{
            //    BusinessInfo info = new BusinessInfo();
            //    info.Weight = support;
            //    SelectStock(Bar, info);
            //}

            //Tinh diem cong cho tung chien luoc
            Indicators.SMA smaVolume = new Indicators.SMA(data.Volume, parameters[0], "sma");
            if (data.Volume[Bar] > 1.2 * smaVolume[Bar])
                weight++;

            if (data.Volume[Bar] < 1.2 * smaVolume[Bar])
                weight--;
            


            BusinessInfo info = new BusinessInfo();
            info.Weight = weight;
            SelectStock(Bar, info);
        }
Ejemplo n.º 6
0
        override protected void StrategyExecute()
        {
            BasicATRRule rule = new BasicATRRule(data.Bars, parameters[0], "atr");
            Indicators.MIN min = Indicators.MIN.Series(data.Close, parameters[0], "min");
            Indicators.MAX max = Indicators.MAX.Series(data.Close, parameters[0], "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.º 7
0
        override protected void StrategyExecute()
        {
            BasicSARRule rule = new BasicSARRule(data.Bars, parameters[0], parameters[1]);
            int cutlosslevel = (int)parameters[2];
            int takeprofitlevel = (int)parameters[3];

            Indicators.MIN min = Indicators.MIN.Series(data.Close, 30, "min");
            Indicators.MAX max = Indicators.MAX.Series(data.Close, 30, "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);
                }
                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);
            }
        }
Ejemplo n.º 8
0
        override protected void StrategyExecute()
        {
            PriceTwoSMARule smarule = new PriceTwoSMARule(data.Close, parameters[0], parameters[1]);

            int cutlosslevel = 5;
            Indicators.MIN min = Indicators.MIN.Series(data.Close, parameters[0], "min");
            Indicators.MAX max = Indicators.MAX.Series(data.Close, parameters[1], "max");
            Indicators.Fibonnanci fibo = Indicators.Fibonnanci.Series(data.Bars, parameters[1], "fibo");


            for (int idx = smarule.long_indicator.FirstValidValue; idx < smarule.long_indicator.Count; idx++)
            {
                if (smarule.isValid_forBuy(idx))
                {
                    BusinessInfo info = new BusinessInfo();
                    info.SetTrend(AppTypes.MarketTrend.Upward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
                    info.Short_Resistance = max[idx];
                    info.Short_Support = min[idx];
                    info.Short_Target = fibo.Fibo23pc[idx];
                    info.Stop_Loss = data.Close[idx] * (1 - cutlosslevel / 100);
                    BuyAtClose(idx,info);
                }
                else
                    if (smarule.isValid_forSell(idx))
                    {
                        BusinessInfo info = new BusinessInfo();
                        info.SetTrend(AppTypes.MarketTrend.Upward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
                        info.Short_Resistance = max[idx];
                        info.Short_Support = min[idx];
                        info.Short_Target = fibo.Fibo23pc[idx];
                        info.Stop_Loss = data.Close[idx] * (1 - cutlosslevel / 100);
                        SellAtClose(idx,info);
                    }
            }
        }
Ejemplo n.º 9
0
 public void Set(BusinessInfo info)
 {
     this.ShortTermTrend  = info.ShortTermTrend;
     this.MediumTermTrend = info.MediumTermTrend;
     this.LongTermTrend   = info.LongTermTrend;
     this.Weight          = info.Weight;
 }
Ejemplo n.º 10
0
 override protected void StrategyExecute()
 {
     int Bar = data.Close.Count - 1;
     if (Bar <= 1) return;
     BusinessInfo info = new BusinessInfo();
     info.Weight = data.Close[Bar];
     SelectStock(Bar, info);
 }
Ejemplo n.º 11
0
 public void Set(BusinessInfo info)
 {
     this.ShortTermTrend   = info.ShortTermTrend;
     this.MediumTermTrend  = info.MediumTermTrend;
     this.LongTermTrend    = info.LongTermTrend;
     this.Weight           = info.Weight;
     this.Short_Target     = info.Short_Target;
     this.Stop_Loss        = info.Stop_Loss;
     this.Short_Resistance = info.Short_Resistance;
     this.Short_Support    = info.Short_Support;
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Screening following basic MACD rule
 /// </summary>
 override protected void StrategyExecute()
 {
     BasicMACDRule rule = new BasicMACDRule(data.Close, (int)parameters[0], (int)parameters[1], (int)parameters[2]);
     if (rule.isValid())
     {
         int Bar = data.Close.Count - 1;
         BusinessInfo info = new BusinessInfo();
         info.Weight = rule.macd[Bar] * 100;
         SelectStock(Bar, info);
     }
 }
Ejemplo n.º 13
0
 override protected void StrategyExecute()
 {
     Rule rule = new MACD_HistogramRule(data.Close, parameters[0], parameters[1], parameters[2]);
     if (rule.isValid())
     {
         int Bar = data.Close.Count - 1;
         BusinessInfo info = new BusinessInfo();
         info.Weight = data.Close[Bar];
         SelectStock(Bar, info);
     }
 }
Ejemplo n.º 14
0
 protected override void StrategyExecute()
 {
     Indicators.ADX adx = new Indicators.ADX(data.Bars, parameters[0], "");
     int Bar = adx.Count - 1;
     if (Bar < adx.FirstValidValue) return;
     BusinessInfo info = new BusinessInfo();
     info.SetTrend(AppTypes.MarketTrend.Unspecified,
         AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
     info.Weight = adx[Bar];
     SelectStock(Bar, info);
 }
Ejemplo n.º 15
0
 protected override void StrategyExecute()
 {
     Rule rule = new BasicSARRule(data.Bars, parameters[0], parameters[1]);
     if (rule.isValid())
     {
         int Bar = data.Close.Count - 1;
         BusinessInfo info = new BusinessInfo();
         info.SetTrend(AppTypes.MarketTrend.Upward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
         info.Weight = data.Close[Bar];
         SelectStock(Bar, info);
     }
 }
Ejemplo n.º 16
0
 override protected void StrategyExecute()
 {
     StockFastRule rule = new StockFastRule(data.Bars, parameters);
     if (rule.isValid())
     {
         int Bar = data.Close.Count - 1;
         BusinessInfo info = new BusinessInfo();
         info.SetTrend(AppTypes.MarketTrend.Upward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
         info.Weight = rule.stoch[Bar];
         SelectStock(Bar, info);
     }
 }
Ejemplo n.º 17
0
        override protected void StrategyExecute()
        {
            int Bar = data.Close.Count - 1;
            if (Bar < data.Close.FirstValidValue) return;

            ////If Volume>2*Average Volume of 1 month
            Indicators.SMA smaVolume=new Indicators.SMA(data.Close,parameters[0],"sma");
            if (data.Volume[Bar]>1.5*smaVolume[Bar]){
                BusinessInfo info = new BusinessInfo();
                info.Weight = data.Volume[Bar];
                SelectStock(Bar, info);
            }
        }
Ejemplo n.º 18
0
        override protected void StrategyExecute()
        {
            int Bar = data.Close.Count - 1;
            int period = (int)parameters[0];//period la gia cua Bar phia truoc, default=30
            if (Bar-period < 0) return;

            //Tim cac stocks co Price hom nay lon hon SMA
            BusinessInfo info = new BusinessInfo();
            if (data.Close[Bar - period] != 0)
                info.Weight = (data.Close[Bar] - data.Close[Bar - period]) / data.Close[Bar - period] * 100;
            else
                info.Weight = double.NegativeInfinity;
            SelectStock(Bar, info);
        }
Ejemplo n.º 19
0
        override protected void StrategyExecute()
        {
            int Bar = data.Close.Count-1;
            if (Bar <= 1) return;

            int period = (int)parameters[0];
            DataSeries sma = Indicators.SMA.Series(data.Close,period,"");

            //Tim cac stocks co Price hom nay lon hon SMA
            if (data.Close[Bar] > sma[Bar])
            {
                BusinessInfo info = new BusinessInfo();
                info.Weight = data.Close[Bar];
                SelectStock(Bar, info);
            }
        }
Ejemplo n.º 20
0
        override protected void StrategyExecute()
        {
            int period = (int)parameters[0];
            double distance = (double)parameters[1];

            int Bar = data.Close.Count - 1;
            if (Bar <= 1) return;
            double support = strategyLib.findSupport(data.Close, Bar, period);
            if (support == -1) return;
            if ((data.Close[Bar] - support) / support*100 < distance)
            {
                BusinessInfo info = new BusinessInfo();
                info.Weight = support;
                SelectStock(Bar, info);
            }
        }
Ejemplo n.º 21
0
        override protected void StrategyExecute()
        {
            int period = (int)parameters[0];
            double distance = (double)parameters[1];

            int Bar = data.Close.Count - 1;
            if (Bar <= 1) return;
            double resistance = strategyLib.findResistance(data.Close, Bar, period);
            if (resistance == -1) return;

            if ((resistance - data.Close[Bar]) / data.Close[Bar]*100 < distance)
            {
                BusinessInfo info = new BusinessInfo();
                info.Weight = resistance;
                SelectStock(Bar, info);
            }
        }
Ejemplo n.º 22
0
        protected override void StrategyExecute()
        {
            //BasicRSI_Rule rule = new BasicRSI_Rule(data.Close, parameters[0], parameters[1], parameters[2]);
            DataSeries rsi = Indicators.RSI.Series(data.Close, parameters[0], "rsi");
            double OVERBOUGHT_LEVEL = parameters[1];
            int Bar = data.Close.Count - 1;
            if (Bar < rsi.FirstValidValue) return;

            if (rsi[Bar] > OVERBOUGHT_LEVEL)
            {
                BusinessInfo info = new BusinessInfo();
                info.SetTrend(AppTypes.MarketTrend.Unspecified,
                    AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
                info.Weight = data.Close[Bar];
                SelectStock(Bar, info);
            }
        }
Ejemplo n.º 23
0
        override protected void StrategyExecute()
        {
            BasicSARRule sarRule = new BasicSARRule(data.Bars, parameters[0], parameters[1]);
            TwoSMARule smarule = new TwoSMARule(data.Close, parameters[2], parameters[3]);
            //BasicDMIRule dmiRule = new BasicDMIRule(data.Bars, 14, 14);
            Indicators.ADX adx = new Indicators.ADX(data.Bars, 14, "");

            int cutlosslevel = (int)parameters[4];
            int takeprofitlevel = (int)parameters[5];

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

            for (int idx = 0; idx < data.Close.Count - 1; idx++)
            {
                if (adx[idx] > 25)
                {
                    if ((!is_bought) && ((sarRule.isValid_forBuy(idx) && smarule.UpTrend(idx))))
                    //if (dmiRule.isValid_forBuy(idx)&&sarRule.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);
                    }
                }
                if (is_bought && (sarRule.isValid_forSell(idx) || smarule.isValid_forSell(idx)))
                //if (dmiRule.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);
            }
        }
Ejemplo n.º 24
0
        override protected void StrategyExecute()
        {
            BasicTRIXRule rule = new BasicTRIXRule(data.Close, parameters[0],"TRIX");
            int cutlosslevel = (int)parameters[1];
            int takeprofitlevel = (int)parameters[2];

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

            for (int idx = rule.trix.FirstValidValue; idx < data.Close.Count - 1; 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);
                }
                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);

                //Trailing stop strategy test
                //new_trailing_stop = price * 0.85;
                //if new_trailing_stop>trailing_stop trailing_stop=new_trailing_stop;
                //else if new_trailing_stop<trailing_stop SellTakeProfit(idx)
            }
        }
Ejemplo n.º 25
0
        override protected void StrategyExecute()
        {
            MACDHistATRRules rule = new MACDHistATRRules(data.Bars, parameters[0], parameters[1], parameters[2], parameters[3]);
            MarketTrend marketTrend = new ADXMarketTrend(data.Bars, parameters[4]);
            int cutlosslevel = (int)parameters[5];
            int trailingstoplevel = (int)parameters[6];
            int takeprofitlevel = (int)parameters[7];

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

            for (int idx = 0; idx < data.Close.Count; idx++)
            {
                if (rule.isValid_forBuy(idx) && (marketTrend.Trending(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);
            }
        }
Ejemplo n.º 26
0
        override protected void StrategyExecute()
        {
            HybridTestRules rule = new HybridTestRules(data.Bars, parameters[0], parameters[1], parameters[2]);
            int cutlosslevel = (int)parameters[3];
            int trailingstoplevel = (int)parameters[4];
            int takeprofitlevel = (int)parameters[5];

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

            Indicators.Fibonnanci fibo = Indicators.Fibonnanci.Series(data.Bars, parameters[1], "fibo");


        //    public double Short_Resistance;
        //public double Short_Support;
        //public double Short_Target;
        //public AppTypes.MarketTrend ShortTermTrend;
        //public double Stop_Loss;
            for (int idx = 1; 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_Resistance = max[idx];
                    info.Short_Support = min[idx];
                    info.Short_Target = fibo.Fibo23pc[idx];
                    info.Stop_Loss = data.Close[idx] * (1-cutlosslevel/100);
                    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_Resistance = max[idx];
                        info.Short_Support = min[idx];
                        info.Short_Target = fibo.Fibo23pc[idx];
                        info.Stop_Loss = data.Close[idx] * (1 - cutlosslevel / 100);
                        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);
            }
        }
Ejemplo n.º 27
0
 /// <summary>
 /// Screening following basic MACD rule
 /// </summary>
 override protected void StrategyExecute()
 {
     //BasicMACDRule rule = new BasicMACDRule(data.Close, (int)parameters[0], (int)parameters[1], (int)parameters[2]);
     //TwoSMARule rule1 = new TwoSMARule(data.Close, (int)parameters[3], (int)parameters[4]);
     TwoSMABasicMACDRule rule = new TwoSMABasicMACDRule(data.Close, parameters[0], parameters[1], parameters[2], parameters[3], parameters[4]);
     int Bar = data.Close.Count - 1;
     if (rule.DownTrend(Bar))
     {
         BusinessInfo info = new BusinessInfo();
         info.Weight = data.Close[Bar];
         SelectStock(Bar, info);
     }
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Strategy following hybrid : basic MACD rule&&2sma
        /// </summary>
        override protected void StrategyExecute()
        {
            //BasicMACDRule rule = new BasicMACDRule(data.Close, (int)parameters[0], (int)parameters[1], (int)parameters[2]);
            //TwoSMARule rule1 = new TwoSMARule(data.Close, (int)parameters[3], (int)parameters[4]);
            TwoSMABasicMACDRule rule = new TwoSMABasicMACDRule(data.Close, parameters[0], parameters[1], parameters[2], parameters[3], parameters[4]);
            int cutlosslevel = (int)parameters[5];
            int trailingstoplevel = (int)parameters[6];
            int takeprofitlevel = (int)parameters[7];

            
            for (int idx = 0; idx < data.Close.Count; idx++)
            {
                //Buy condition
                if (rule.isValid_forBuy(idx))
                {
                    BusinessInfo info = new BusinessInfo();
                    info.SetTrend(AppTypes.MarketTrend.Upward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
                    info.Weight = data.Close[idx];
                    BuyAtClose(idx, info);
                }
                //Sell condition
                else
                    if (rule.isValid_forSell(idx) )
                    {
                        BusinessInfo info = new BusinessInfo();
                        info.SetTrend(AppTypes.MarketTrend.Downward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
                        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);
            }
        }
Ejemplo n.º 29
0
 public TradePointInfo(AppTypes.TradeActions action, int dataIdx, BusinessInfo info)
 {
     this.TradeAction = action;
     this.DataIdx     = dataIdx;
     this.BusinessInfo.Set(info);
 }
Ejemplo n.º 30
0
 protected override void StrategyExecute()
 {
     HybridTestRules rule = new HybridTestRules(data.Bars, parameters[0], parameters[1], parameters[2]);
     int cutlosslevel = (int)parameters[3];
     int trailingstoplevel = (int)parameters[4];
     int takeprofitlevel = (int)parameters[5];
     int Bar = data.Close.Count - 1;
     if (rule.isValid_forBuy(Bar))
     {
         BusinessInfo info = new BusinessInfo();
         info.SetTrend(AppTypes.MarketTrend.Upward, AppTypes.MarketTrend.Unspecified, AppTypes.MarketTrend.Unspecified);
         info.Weight = data.Close[Bar];
         SelectStock(Bar, info);
     }
 }
Ejemplo n.º 31
0
 public void Set(BusinessInfo info)
 {
     this.ShortTermTrend = info.ShortTermTrend;
     this.MediumTermTrend = info.MediumTermTrend;
     this.LongTermTrend = info.LongTermTrend;
     this.Weight = info.Weight;
     this.Short_Target = info.Short_Target;
     this.Stop_Loss = info.Stop_Loss;
     this.Short_Resistance = info.Short_Resistance;
     this.Short_Support = info.Short_Support;
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Add constructor that initiates DateTime
 /// </summary>
 /// <param name="action"></param>
 /// <param name="dataIdx"></param>
 /// <param name="dt"></param>
 /// <param name="info"></param>
 public TradePointInfo(AppTypes.TradeActions action, int dataIdx, DateTime dt, BusinessInfo info)
 {
     this.TradeAction = action;
     this.DataIdx = dataIdx;
     this.BusinessInfo.Set(info);
     this.date_time = dt;
 }
Ejemplo n.º 33
0
 public TradePointInfo(AppTypes.TradeActions action, int dataIdx, BusinessInfo info)
 {
     this.TradeAction = action;
     this.DataIdx = dataIdx;
     this.BusinessInfo.Set(info);
 }