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); } } }
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 - 1; 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); } } }
override protected void StrategyExecute() { StockFastRule rule = new StockFastRule(data.Bars, parameters[0], parameters[1], "stoch"); int cutlosslevel = (int)parameters[2]; int trailingstoplevel = (int)parameters[3]; int takeprofitlevel = (int)parameters[4]; 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); } 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); } //Indicators.StochF stoch = Indicators.StochF.Series(data.Bars, parameters[0], parameters[1], ""); //DataSeries line1 = stoch.FastKSeries; //DataSeries line2 = stoch.FastDSeries; //AppTypes.MarketTrend lastTrend = AppTypes.MarketTrend.Unspecified; //AppTypes.MarketTrend currentTrend = AppTypes.MarketTrend.Unspecified; //for (int idx = 0; idx < line1.Count; idx++) //{ // currentTrend = ((line1[idx] > line2[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; //} } }
override protected void StrategyExecute() { BasicTRIXRule rule = new BasicTRIXRule(data.Close, parameters[0], "TRIX"); int cutlosslevel = (int)parameters[1]; int trailingstoplevel = (int)parameters[2]; int takeprofitlevel = (int)parameters[3]; 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); } if (trailingstoplevel > 0) { TrailingStopWithBuyBack(rule, data.Close[idx], trailingstoplevel, idx); } //Trailing stop strategtest //new_trailing_stop = data.Close[idx] * (1 - trailingstoplevel / 100); //if (new_trailing_stop > trailing_stop) //{ // trailing_stop = new_trailing_stop; // //Buy back share if // if ((!is_bought) && rule.UpTrend(idx)) BuyAtClose(idx); //} //else // if (data.Close[idx]<trailing_stop) // { // SellTakeProfit(idx); // trailing_stop = -1; // } } }
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); } } }
protected override void StrategyExecute() { Rule rule = new BasicATRRule(data.Bars, parameters[0], "atr"); 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); } }
override protected void StrategyExecute() { StockFastRule rule = new StockFastRule(data.Bars, parameters[0], parameters[1], "stoch"); 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); } }
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); } } }
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); } }
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); }
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); } } }
override protected void StrategyExecute() { TwoLineTRIXRule rule = new TwoLineTRIXRule(data.Close, parameters[0], parameters[1], "Two Line TRIX"); int cutlosslevel = (int)parameters[2]; int takeprofitlevel = (int)parameters[3]; double new_trailing_stop, trailing_stop = -1; int trailingstoplevel = 15; 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.long_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 strategtest //if (trailingstoplevel > 0) // TrailingStopWithBuyBack(rule, data.Close[idx], trailingstoplevel, idx); } }
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) } }
/// <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); } } }
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); } }
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); } } }
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); } } }