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() { 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); } } }
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); } } }
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); } } }
/// <summary> /// Calculation of RiskReward indicators /// </summary> /// <param name="db">data to calculate Aroon</param> /// <param name="period">period to calculate</param> /// <param name="name"></param> public RiskReward(DataSeries ds, double period, string name) : base(ds, name) { int begin = 0; Indicators.MIN min = Indicators.MIN.Series(ds, period, "min"); Indicators.MAX max = Indicators.MAX.Series(ds, period, "max"); DataSeries distance1 = ds - min; DataSeries distance2 = max - ds; DataSeries riskreward = distance2 / distance1; FirstValidValue = max.FirstValidValue; this.Name = name; for (int i = begin, j = 0; j < riskreward.Count; i++, j++) { this[i] = riskreward[j]; } }
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); } } }