这是一个基于TRAMA(Triangular Moving Average)和简单移动平均线(SMA)的智能量化交易策略。策略结合了两种均线系统进行交易信号的生成,并设置了止盈止损机制来控制风险。该策略采用4周期和28周期的SMA交叉以及TRAMA指标来确认交易信号,通过多重信号确认提高交易的准确性。
策略使用两个核心组件来生成交易信号。首先是基于4周期和28周期SMA的交叉系统,当短期均线向上穿越长期均线时产生做多信号,向下穿越时产生做空信号。其次,策略引入了TRAMA指标作为辅助确认系统。TRAMA是一种改良的移动平均线,具有更快的响应速度和更低的滞后性。当价格突破TRAMA时,会产生额外的交易信号。策略同时设置了基于百分比的止盈止损机制,分别为2%的止盈和1%的止损。
这是一个结合了传统技术分析和现代量化交易理念的策略。通过多重信号确认和严格的风险控制,策略展现出较好的实用性。虽然存在一些需要优化的地方,但整体框架设计合理,具有良好的应用前景。建议交易者在实盘使用前,进行充分的历史数据回测和参数优化。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ivanvallejoc
//@version=5
strategy("MANCOS2.0", overlay=true, margin_long=80, margin_short=80)
longCondition = ta.crossover(ta.sma(close, 4), ta.sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = ta.crossunder(ta.sma(close, 4), ta.sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
// Parámetros de la TRAMA
length = input(1.5, title="TRAMA Length")
src = close
filt = 2 / (length + 1)
trama = 0.0
var tramaPrev = na(trama[1]) ? close : trama[1]
trama := (src - tramaPrev) * filt + tramaPrev
// Plot de la TRAMA
plot(trama, color=color.blue, linewidth=2, title="TRAMA")
// Señales de compra y venta basadas en TRAMA
buySignal = ta.crossover(close, trama)
sellSignal = ta.crossunder(close, trama)
// Configuración de Take Profit y Stop Loss
takeProfitPerc = input(2, title="Take Profit (%)") / 100
stopLossPerc = input(1, title="Stop Loss (%)") / 100
// Precios de TP y SL
takeProfitPrice = strategy.position_avg_price * (1 + takeProfitPerc)
stopLossPrice = strategy.position_avg_price * (1 - stopLossPerc)
// Condiciones de entrada en largo
if (buySignal)
strategy.entry("Long", strategy.long)
// Condiciones de salida para posición larga (TP/SL)
if (strategy.position_size > 0)
strategy.exit("TP/SL", "Long", limit=takeProfitPrice, stop=stopLossPrice)
// Entrada en corto basada en TRAMA
if (sellSignal)
strategy.entry("Short", strategy.short)
// Precios de TP y SL para posiciones cortas
takeProfitPriceShort = strategy.position_avg_price * (1 - takeProfitPerc)
stopLossPriceShort = strategy.position_avg_price * (1 + stopLossPerc)
if (strategy.position_size < 0)
strategy.exit("TP/SL", "Short", limit=takeProfitPriceShort, stop=stopLossPriceShort)