Ruda动量趋势交易策略是一个基于动量和趋势指标的量化交易策略。该策略使用OBV(On Balance Volume)、EMA(Exponential Moving Average)和K线实体比例等指标来判断买入和卖出时机。当短期EMA上穿长期EMA,OBV创新高,且K线实体比例大于设定阈值时,策略会在次日开盘价买入;当价格跌破止损价或收盘价跌破短期EMA时,策略会平仓。
Ruda动量趋势交易策略是一个简单易用的量化交易策略,通过趋势和动量指标的结合,能够捕捉强势品种和趋势机会。但该策略也存在一定局限性,如指标滞后、参数固定等问题。未来可以从优化指标参数、引入自适应机制、扩大回测范围和加强风险管理等方面对策略进行优化和改进,以提高策略的稳健性和盈利能力。
/*backtest start: 2024-03-01 00:00:00 end: 2024-03-31 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © lhcbenac //@version=5 strategy('Ruda_Strategy', overlay=true , initial_capital=5000 , pyramiding = 3, commission_type = strategy.commission.cash_per_contract , commission_value = 1 ) // // //////////////////////////////////////////////////////// // // // // // Otimizações // // // // // //////////////////////////////////////////////////////// // // //////////////////////////////////////////////////////// // // // // // Codigo Operacional // // // // // //////////////////////////////////////////////////////// // // // Indica situação de Compra ou Venda // Condição True or False YEAR_BT= input.int(1,title="Nº Anos ", group = "Backtest") INPUT_ME1 = input.int(5,title="Momentum ", group = "RUDA") INPUT_ME2 = input.int(21,title="Trend ", group = "RUDA") INPUT_CORPO = input.int(50,title="CORPO ", group = "RUDA")/100 v_obv = ta.obv v_med1 = ta.ema(close , INPUT_ME1) v_med2 = ta.ema(close , INPUT_ME2) valid_1 = v_med1 > v_med2 valid_2 = v_obv >= ta.highest(v_obv[1], 10) valid_3 = math.abs(close - open) / (high-low) > INPUT_CORPO plot(v_med1) plot(v_med2) compra = valid_1 and valid_2 and strategy.position_size == 0 and valid_3 var float v_minima_ref = na dataInicio = timestamp(year(timenow) - YEAR_BT, month(timenow), dayofmonth(timenow), 00, 00) // Variáveis globais var float preco_entrada = na var float preco_stop = na if compra and time >= dataInicio and ta.change(time("D")) != 0 and ta.change(compra) v_minima_ref := low preco_entrada := open preco_stop := math.min(low, open - 0.01 * open) strategy.entry("Compra", strategy.long , stop = preco_stop ) if (not na(preco_entrada) and not na(preco_stop)) label.new(x=bar_index, y= low * 0.9, text= "Dia: " + str.tostring(dayofmonth) + "\nPreço de Entrada: " + str.tostring(preco_entrada) + "\nPreço de Stop Loss: " + str.tostring(preco_stop), style=label.style_label_up, color=color.green) // Lógica de saída // Saída no stop loss if (not na(preco_stop) and low < preco_stop and ta.change(low) < 0) strategy.close("Compra", comment="Saída no Stop") // Saída no lucro if (close < v_med1 and ta.change(close) < 0) strategy.close("Compra", comment="Saída na Media") venda =( (not na(preco_stop) and low < preco_stop and ta.change(low) < 0) or (close < v_med1 and ta.change(close) < 0) ) and strategy.position_size > 0 codiff = compra ? 1 : venda ? -1 : na plotarrow(codiff, colorup=#00c3ff, colordown=#ff0062,title="Compra", maxheight=20, offset=0)