
La estrategia se basa en los puntos altos y bajos PIVOT y brechas para juzgar la reversión de la tendencia de la criptomoneda, y pertenece a la clase de estrategia de reversión de ruptura. La estrategia primero calcula los puntos PIVOT de los precios más altos y más bajos de los indicadores en el período más reciente, y luego determina si el precio se revirtió después de romper estos puntos clave para capturar los cambios de tendencia más grandes.
Utilizando las funciones ta.pivothigh ((() y ta.pivotlow ((() se calculan los puntos de precio más alto y más bajo de los últimos números de barras como puntos PIVOT clave.
Si el precio supera el PIVOT Bottom hacia arriba o el PIVOT Bottom hacia abajo, entonces se considera que la tendencia se ha invertido.
Se requiere que el precio tenga un cierto margen de ruptura con respecto al PIVOT y que supere el precio de cierre de 150 bares para evitar que se encuentre sujeto.
La entrada y salida de las entradas son iguales a las entradas y salidas de las entradas de las entradas.
La estrategia es más robusta en general y es adecuada para capturar grandes reveses. Sin embargo, se debe tener en cuenta el control del riesgo y ajustar los parámetros para adaptarlos a diferentes monedas. Se cree que la estrategia puede tener un mejor efecto sobre la base de la optimización de parámetros y el control del viento.
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
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/
// © nkrastins95
//@version=5
strategy("Swing Hi Lo", overlay=true, margin_long=100, margin_short=100)
//-----------------------------------------------------------------------------------------------------------------------//
tf = input.timeframe(title="Timeframe", defval="")
gr="LENGTH LEFT / RIGHT"
leftLenH = input.int(title="Pivot High", defval=10, minval=1, inline="Pivot High",group=gr)
rightLenH = input.int(title="/", defval=10, minval=1, inline="Pivot High",group=gr)
colorH = input(title="", defval=color.red, inline="Pivot High",group=gr)
leftLenL = input.int(title="Pivot Low", defval=10, minval=1, inline="Pivot Low", group=gr)
rightLenL = input.int(title="/", defval=10, minval=1, inline="Pivot Low",group=gr)
colorL = input(title="", defval=color.blue, inline="Pivot Low",group=gr)
//-----------------------------------------------------------------------------------------------------------------------//
pivotHigh(ll, rl) =>
maxLen = 1000
float ph = ta.pivothigh(ll, rl)
int offset = 0
while offset < maxLen
if not na(ph[offset])
break
offset := offset + 1
ph[offset]
pivotLow(ll, rl) =>
maxLen = 1000
float pl = ta.pivotlow(ll, rl)
int offset = 0
while offset < maxLen
if not na(pl[offset])
break
offset := offset + 1
pl[offset]
//-----------------------------------------------------------------------------------------------------------------------//
ph = request.security(syminfo.tickerid, tf, pivotHigh(leftLenH, rightLenH), barmerge.gaps_off, barmerge.lookahead_on)
pl = request.security(syminfo.tickerid, tf, pivotLow(leftLenL, rightLenL), barmerge.gaps_off, barmerge.lookahead_on)
drawLabel(_offset, _pivot, _style, _color) =>
if not na(_pivot)
label.new(bar_index[_offset], _pivot, str.tostring(_pivot, format.mintick), style=_style, color=_color, textcolor=#131722)
//-----------------------------------------------------------------------------------------------------------------------//
VWAP = ta.vwap(ohlc4)
longcondition = ta.crossunder(close,pl) and close > close[150]
exitcondition = close > ph
shortcondition = ta.crossover(close,ph) and close < close[150]
covercondition = close < pl
strategy.entry("long", strategy.long, when = longcondition)
strategy.close("long", when = exitcondition)
strategy.entry("Short", strategy.short, when = shortcondition)
strategy.close("Short", when = covercondition)