此策略是一个指标,您可以在其中查看不同时间段的平均值。
您可以在参数中管理时间范围。策略是在两条线超买或超卖时站稳脚跟,在斯托克指数和RSI走到中间时收盘。
回测测试
/*backtest start: 2021-12-01 00:00:00 end: 2022-05-30 00:00:00 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_CTP","currency":"FUTURES"}] args: [["ContractType","rb2210",360008]] */ ////////////////////////////////////////// MTF Stochastic & RSI Strategy ©️ bykzis ///////////////////////////////////////// // // *** Inspired by "Binance CHOP Dashboard" from @Cazimiro and "RSI MTF Table" from @mobester16 *** and LOT OF COPY of Indicator-Jones MTF Scanner // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //@version=5 //strategy('MTF RSI & STOCH Strategy', overlay=false,initial_capital=100, currency=currency.USD, commission_value=0.01, commission_type=strategy.commission.percent) // Pair list var string GRP1 = '══════════ General ══════════' overbought = input.int(80, '超买 水平', minval=1, group=GRP1) oversold = input.int(20, '超卖 水平', minval=1, group=GRP1) /// Timeframes var string GRP2 = '══════════ Timeframes ══════════' timeframe1 = input.timeframe(title="时间框架 1", defval="60", group=GRP2) timeframe2 = input.timeframe(title="时间框架 2", defval="30", group=GRP2) timeframe3 = input.timeframe(title="时间框架 3", defval="15", group=GRP2) timeframe4 = input.timeframe(title="时间框架 4", defval="5", group=GRP2) // RSI settings var string GRP3 = '══════════ RSI settings ══════════' rsiLength = input.int(14, minval=1, title='RSI 周期', group=GRP3) rsiSource = input(close, 'RSI 数据源', group=GRP3) rsioverbought = input.int(70, 'RSI 超买 水平', minval=1, group=GRP3) rsioversold = input.int(30, 'RSI 超卖 水平', minval=1, group=GRP3) /// Get RSI values of each timeframe ///////////////////////////////////////////////////// rsi = ta.rsi(rsiSource, rsiLength) callRSI(id,timeframe) => rsiValue = request.security(id, str.tostring(timeframe), rsi, gaps=barmerge.gaps_off) rsiValue RSI_TF1 = callRSI(syminfo.tickerid, timeframe1) RSI_TF2 = callRSI(syminfo.tickerid, timeframe2) RSI_TF3 = callRSI(syminfo.tickerid, timeframe3) RSI_TF4 = callRSI(syminfo.tickerid, timeframe4) /////// Calculate Averages ///////////////////////////////////////////////////////////////// calcAVG(valueTF1, valueTF2, valueTF3, valueTF4) => math.round((valueTF1 + valueTF2 + valueTF3 + valueTF4) / 4, 2) AVG=calcAVG(RSI_TF1, RSI_TF2, RSI_TF3, RSI_TF4) // Stochastic settings var string GRP4 = '══════════ Stochastic settings ══════════' periodK = input.int(14, '%K 长度', minval=1, group=GRP4) smoothK = input.int(3, '平滑 K', minval=1, group=GRP4) stochSource = input(close, 'Stochastic 数据源', group=GRP4) stochoverbought = input.int(70, 'Stochastic 超买 水平', minval=1, group=GRP4) stochoversold = input.int(30, 'Stochastic 超卖 水平', minval=1, group=GRP4) /// Get Stochastic values of each timeframe //////////////////////////////////////////////// stoch = ta.sma(ta.stoch(stochSource, high, low, periodK), smoothK) getStochastic(id,timeframe) => stochValue = request.security(id, str.tostring(timeframe), stoch, gaps=barmerge.gaps_off) stochValue Stoch_TF1 = getStochastic(syminfo.tickerid, timeframe1) Stoch_TF2 = getStochastic(syminfo.tickerid, timeframe2) Stoch_TF3 = getStochastic(syminfo.tickerid, timeframe3) Stoch_TF4 = getStochastic(syminfo.tickerid, timeframe4) AVG_STOCH=calcAVG(Stoch_TF1, Stoch_TF2, Stoch_TF3, Stoch_TF4) plot(AVG, color = color.blue, title='RSI') plot(AVG_STOCH, color = color.yellow,title='STOCH') hline(rsioverbought,color=color.red) hline(rsioversold, color=color.lime) hline(50, color=color.white) //============ signal Generator ==================================// if AVG <= rsioversold and AVG_STOCH <=stochoversold strategy.entry('Buy_Long', strategy.long) strategy.close("Buy_Long",when=(AVG_STOCH >=70 and AVG >=50 and close >=strategy.position_avg_price),comment="Long_OK") if AVG >=rsioverbought and AVG_STOCH >=stochoverbought strategy.entry('Buy_Short', strategy.short) strategy.close("Buy_Short",when=(AVG_STOCH <=30 and AVG <=50 and close <=strategy.position_avg_price),comment="Short_OK") ///////////////////////////////////////////////////////////////////////////////////////////template: strategy.tpl:40:21: executing "strategy.tpl" at <.api.GetStrategyListByName>: wrong number of args for GetStrategyListByName: want 7 got 6