该策略通过计算移动平均线和价格差值来判断市场趋势方向,在符合趋势条件时开仓做多,避免在震荡行情中频繁开仓。
该策略结合移动平均线和价格波动幅度判断,旨在捕捉趋势行情中的价格上涨机会。
当价格上涨突破移动平均线时,表示当前处于多头行情。此时若最近3周期的最高价与最低价差值大于自身的20周期平均值,说明最近波动范围加大,价格可能出现较大幅度上涨,这时做多开仓。
在开仓后,设定一个固定比例的止损价格,当价格跌破该价格时主动止损平仓,控制下side风险。
风险解决方法:
本策略通过简单有效的指标判断来实现在趋势行情中高效开仓的思路,可有效过滤震荡小行情,避免无谓交易。同时,策略风险控制也比较到位,能够很好控制潜在亏损。通过进一步优化,可望获得更好的交易效果。
/*backtest
start: 2023-02-21 00:00:00
end: 2024-02-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Estrategia de Diferencia HL y MA para Criptomonedas", shorttitle="HL MA Crypto Strategy-Ortiz", overlay=true)
// Definir longitud de MA y HL
ma_length = input(20, title="Longitud MA")
hl_length = input(3, title="Longitud HL")
exit_below_price = input(0.98, title="Salir por debajo de precio")
// Calcular MA
ma = ta.sma(close, ma_length)
// Calcular HL
hh = ta.highest(high, hl_length)
ll = ta.lowest(low, hl_length)
hl = hh - ll
// Condiciones de tendencia alcista
bullish_trend = close > ma
// Condiciones de entrada y salida
long_condition = close > ma and close > ma[1] and hl > ta.sma(hl, ma_length)
short_condition = false // No operar en tendencia bajista
exit_condition = low < close * exit_below_price
// Entrada y salida de la estrategia
if (long_condition)
strategy.entry("Buy", strategy.long)
if (short_condition)
strategy.entry("Sell", strategy.short)
if (exit_condition)
strategy.close("Buy")
// Plot de señales en el gráfico
plotshape(long_condition, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(short_condition, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")