protected override void StrategyExecute() { DataSeries line1 = Indicators.EMA.Series(data.Close, parameters[0], "ema"); DataSeries line2 = Indicators.EMA.Series(data.Close, parameters[1], "ema"); AppTypes.MarketTrend trend = AppTypes.MarketTrend.Unspecified; AppTypes.MarketTrend lastTrend = AppTypes.MarketTrend.Unspecified; for (int idx = 0; idx < line1.Count; idx++) { double d1 = line1[idx]; double d2 = line2[idx]; if (d1 == 0 || d2 == 0) { continue; } trend = (d1 > d2 ? AppTypes.MarketTrend.Upward : AppTypes.MarketTrend.Downward); if (lastTrend == AppTypes.MarketTrend.Downward && trend == AppTypes.MarketTrend.Upward) { BuyAtClose(idx); } if (lastTrend == AppTypes.MarketTrend.Upward && trend == AppTypes.MarketTrend.Downward) { SellAtClose(idx); } lastTrend = trend; } }
override protected void StrategyExecute() { DataSeries sma5 = Indicators.SMA.Series(data.Close, parameters[0], ""); DataSeries sma10 = Indicators.SMA.Series(data.Close, parameters[1], ""); int VOLUME_FILTER = (int)parameters[2]; AppTypes.MarketTrend lastTrend = AppTypes.MarketTrend.Unspecified;; AppTypes.MarketTrend currentTrend = AppTypes.MarketTrend.Unspecified;; bool bVolumeCondition = false; for (int idx = 0; idx < sma5.Count - 1; idx++) { currentTrend = ((data.Close[idx] > sma5[idx]) && (sma5[idx] > sma10[idx]) ? AppTypes.MarketTrend.Upward : AppTypes.MarketTrend.Downward); bVolumeCondition = data.Volume[idx] > VOLUME_FILTER ? true : false; if (bVolumeCondition && lastTrend == AppTypes.MarketTrend.Downward && currentTrend == AppTypes.MarketTrend.Upward) { BuyAtClose(idx); } if (is_bought && lastTrend == AppTypes.MarketTrend.Upward && currentTrend == AppTypes.MarketTrend.Downward) { SellAtClose(idx); } lastTrend = currentTrend; } }
public BusinessInfo(AppTypes.MarketTrend shortTerm, AppTypes.MarketTrend mediumTerm, AppTypes.MarketTrend longTerm, double weight) { this.ShortTermTrend = shortTerm; this.MediumTermTrend = mediumTerm; this.LongTermTrend = longTerm; this.Weight = weight; }
protected override void StrategyExecute() { DataSeries sma20 = Indicators.SMA.Series(data.Close, parameters[0], ""); Indicators.MACD macd = Indicators.MACD.Series(data.Close, parameters[1], parameters[2], parameters[3], ""); Indicators.Stoch stoch = Indicators.Stoch.Series(data.Bars, parameters[4], parameters[5], parameters[6], ""); DataSeries line1 = stoch.SlowKSeries; DataSeries line2 = stoch.SlowDSeries; double delta = 0, lastDelta = 0; bool upTrend = false; AppTypes.MarketTrend stochasticTrend = AppTypes.MarketTrend.Unspecified; for (int idx = 1; idx < macd.Values.Length; idx++) { delta = (macd.HistSeries[idx] - macd.HistSeries[idx - 1]); stochasticTrend = ((line1[idx] > line2[idx]) ? AppTypes.MarketTrend.Upward : AppTypes.MarketTrend.Downward); upTrend = (data.Close[idx] > sma20[idx] ? true : false); if (upTrend && delta > 0 && lastDelta < 0 && stochasticTrend == AppTypes.MarketTrend.Upward) { BuyAtClose(idx); } if (is_bought && stochasticTrend == AppTypes.MarketTrend.Downward) { SellAtClose(idx); } lastDelta = delta; } }
protected override void StrategyExecute() { DataSeries sma5 = Indicators.SMA.Series(data.Close, parameters[0], ""); DataSeries sma10 = Indicators.SMA.Series(data.Close, parameters[1], ""); DataSeries sma20 = Indicators.SMA.Series(data.Close, parameters[2], ""); int RISKREWARD = (int)parameters[3]; int PERIOD = (int)parameters[4]; AppTypes.MarketTrend lastTrend = AppTypes.MarketTrend.Unspecified; AppTypes.MarketTrend currentTrend = AppTypes.MarketTrend.Unspecified; for (int idx = 0; idx < sma5.Count; idx++) { currentTrend = ((data.Close[idx] > sma5[idx]) && (sma5[idx] > sma10[idx]) && (sma10[idx] > sma20[idx]) ? AppTypes.MarketTrend.Upward : AppTypes.MarketTrend.Downward); if (lastTrend == AppTypes.MarketTrend.Downward && currentTrend == AppTypes.MarketTrend.Upward) { double risk_reward_ratio = strategyLib.RiskRewardRatio(data.Close, idx, PERIOD); if (risk_reward_ratio >= RISKREWARD) { BuyAtClose(idx); } } if (lastTrend == AppTypes.MarketTrend.Upward && currentTrend == AppTypes.MarketTrend.Downward) { SellAtClose(idx); } lastTrend = currentTrend; } }
override protected void StrategyExecute() { int sma_short_period = (int)parameters[0]; int sma_long_period = (int)parameters[1]; int fastK = (int)parameters[2]; int slowK = (int)parameters[3]; int slowD = (int)parameters[4]; DataSeries short_sma = Indicators.SMA.Series(data.Close, sma_short_period, ""); DataSeries long_sma = Indicators.SMA.Series(data.Close, sma_long_period, ""); Indicators.Stoch stoch = Indicators.Stoch.Series(data.Bars, fastK, slowK, slowD, ""); DataSeries stoch1 = stoch.SlowKSeries; DataSeries stoch2 = stoch.SlowDSeries; AppTypes.MarketTrend lastTrend = AppTypes.MarketTrend.Unspecified; AppTypes.MarketTrend currentTrend = AppTypes.MarketTrend.Unspecified; AppTypes.MarketTrend stochTrend = AppTypes.MarketTrend.Unspecified; for (int idx = 0; idx < short_sma.Count; idx++) { stochTrend = (stoch1[idx] > stoch2[idx] ? AppTypes.MarketTrend.Upward : AppTypes.MarketTrend.Downward); currentTrend = ((data.Close[idx] > short_sma[idx]) && (short_sma[idx] > long_sma[idx]) ? AppTypes.MarketTrend.Upward : AppTypes.MarketTrend.Downward); if (lastTrend == AppTypes.MarketTrend.Downward && currentTrend == AppTypes.MarketTrend.Upward && stochTrend == AppTypes.MarketTrend.Upward) { BuyAtClose(idx); } if (lastTrend == AppTypes.MarketTrend.Upward && currentTrend == AppTypes.MarketTrend.Downward) { SellAtClose(idx); } lastTrend = currentTrend; } }
override public TradePoints Execute(application.Data data, int[] parameters) { //application.Data vnidxData1 = data.New("^VNINDEX"); adviceInfo = new TradePoints(); DataSeries minusDmi_14 = new Indicators.MinusDI(data.Bars, parameters[0], ""); DataSeries plusDmi_14 = new Indicators.PlusDI(data.Bars, parameters[1], ""); AppTypes.MarketTrend lastTrend = AppTypes.MarketTrend.Unspecified; AppTypes.MarketTrend currentTrend = AppTypes.MarketTrend.Unspecified; for (int idx = 0; idx < minusDmi_14.Count; idx++) { currentTrend = ((plusDmi_14[idx] > minusDmi_14[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; } return(adviceInfo); }
override protected void StrategyExecute() { DataSeries sma20 = Indicators.SMA.Series(data.Close, parameters[0], ""); Indicators.MACD macd = Indicators.MACD.Series(data.Close, parameters[1], parameters[2], parameters[3], ""); DataSeries hist = macd.HistSeries; Indicators.Stoch stoch = Indicators.Stoch.Series(data.Bars, parameters[4], parameters[5], parameters[6], ""); DataSeries line1 = stoch.SlowKSeries; DataSeries line2 = stoch.SlowDSeries; double delta = 0, lastDelta = 0; bool macd_swicth_to_up_trend = false, macd_swicth_to_down_trend = false, sto_switch_to_up_trend = false, sto_switch_to_down_trend = false; AppTypes.MarketTrend stochasticTrend = AppTypes.MarketTrend.Unspecified; for (int idx = 1; idx < macd.Count; idx++) { delta = (hist[idx] - hist[idx - 1]); macd_swicth_to_up_trend = (delta > 0 && lastDelta < 0 ? true : false); macd_swicth_to_down_trend = (delta < 0 && lastDelta > 0 ? true : false); stochasticTrend = (line1[idx] > line2[idx] ? AppTypes.MarketTrend.Upward : AppTypes.MarketTrend.Downward); sto_switch_to_up_trend = (line1[idx] > line2[idx]) && (line1[idx - 1] < line2[idx - 1]) ? true : false; sto_switch_to_down_trend = (line1[idx] < line2[idx]) && (line1[idx - 1] > line2[idx - 1]) ? true : false; if (!is_bought && data.Close[idx] > sma20[idx]) { if (macd_swicth_to_up_trend && stochasticTrend == AppTypes.MarketTrend.Downward) { BuyAtClose(idx); } } if (is_bought) { if (sto_switch_to_down_trend || macd_swicth_to_down_trend) { SellAtClose(idx); } } lastDelta = delta; } }
public override bool isValid_forSell(int index) { if (index - 1 < short_indicator.FirstValidValue) { return(false); } AppTypes.MarketTrend currentTrend = (short_indicator[index] > long_indicator[index]) ? AppTypes.MarketTrend.Upward : AppTypes.MarketTrend.Downward; AppTypes.MarketTrend lastTrend = (short_indicator[index - 1] > long_indicator[index - 1]) ? AppTypes.MarketTrend.Upward : AppTypes.MarketTrend.Downward; if (lastTrend == AppTypes.MarketTrend.Upward && currentTrend == AppTypes.MarketTrend.Downward) { return(true); } return(false); }
public override bool isValid() { if (fastK.Count < 2) { return(false); } AppTypes.MarketTrend lastTrend = AppTypes.MarketTrend.Unspecified; AppTypes.MarketTrend currentTrend = AppTypes.MarketTrend.Unspecified; for (int idx = fastK.Count - 2; idx < fastK.Count; idx++) { currentTrend = ((fastK[idx] > fastD[idx]) ? AppTypes.MarketTrend.Upward : AppTypes.MarketTrend.Downward); if (lastTrend == AppTypes.MarketTrend.Downward && currentTrend == AppTypes.MarketTrend.Upward) { return(true); } lastTrend = currentTrend; } return(false); }
override protected void StrategyExecute() { Indicators.MACD macd = Indicators.MACD.Series(data.Close, parameters[0], parameters[1], parameters[2], ""); DataSeries ema = macd.SignalSeries; AppTypes.MarketTrend lastTrend = AppTypes.MarketTrend.Unspecified; AppTypes.MarketTrend currentTrend = AppTypes.MarketTrend.Unspecified; for (int idx = 0; idx < macd.Count; idx++) { currentTrend = (macd[idx] > ema[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() { 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() { DataSeries sma5 = Indicators.SMA.Series(data.Close, parameters[0], ""); DataSeries sma10 = Indicators.SMA.Series(data.Close, parameters[1], ""); DataSeries sma20 = Indicators.SMA.Series(data.Close, parameters[2], ""); AppTypes.MarketTrend lastTrend = AppTypes.MarketTrend.Unspecified; AppTypes.MarketTrend currentTrend = AppTypes.MarketTrend.Unspecified; for (int idx = 0; idx < sma5.Count; idx++) { currentTrend = ((data.Close[idx] > sma5[idx]) && (sma5[idx] > sma10[idx]) && (sma10[idx] > sma20[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; } }
public void SetTrend(AppTypes.MarketTrend shortTerm, AppTypes.MarketTrend mediumTerm, AppTypes.MarketTrend longTerm) { this.ShortTermTrend = shortTerm; this.MediumTermTrend = mediumTerm; this.LongTermTrend = longTerm; }