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() { 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; // } } }
/// <summary> /// Static method to create Arron DataSeries /// </summary> /// <param name="ds"></param> /// <param name="period"></param> /// <param name="name"></param> /// <returns></returns> public static MIN Series(DataSeries ds, double period, string name) { //Build description string description = "(" + name + period.ToString() + ")"; //See if it exists in the cache object obj = ds.Cache.Find(description); if (obj != null) return (MIN)obj; //Create indicator, cache it, return it MIN indicator = new MIN(ds, period, description); ds.Cache.Add(description, indicator); return indicator; }
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); } } }
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> /// Static method to create Arron DataSeries /// </summary> /// <param name="ds"></param> /// <param name="period"></param> /// <param name="name"></param> /// <returns></returns> public static MIN Series(DataSeries ds, double period, string name) { //Build description string description = "(" + name + period.ToString() + ")"; //See if it exists in the cache object obj = ds.Cache.Find(description); if (obj != null) { return((MIN)obj); } //Create indicator, cache it, return it MIN indicator = new MIN(ds, period, description); ds.Cache.Add(description, indicator); return(indicator); }