Alerta dinámica de pérdida de detención de operacionesEstrategia de visualización

El autor:¿ Qué pasa?, Fecha: 2023-09-18 17:20:06
Las etiquetas:

Resumen general

Esta estrategia demuestra pasar precios de stop loss dinámicos a través de alertas de TradingView para su ejecución en plataformas MT4/5 utilizando TradingConnector. Las entradas se determinan utilizando el indicador estocástico con paradas dinámicas establecidas en pivotes recientes. También es posible obtener ganancias parciales.

Estrategia lógica

Las entradas largas y cortas en los cruces de las líneas estocásticas K y D. Los máximos / mínimos recientes del pivote se calculan como precios de stop loss dinámicos. Estos se transmiten en tiempo real al corredor a través de alertas en la entrada. Se obtienen ganancias parciales a cierto porcentaje de la distancia de stop loss. Los precios de ganancias también se pueden alertar dinámicamente.

Ventajas

  • Las paradas dinámicas permiten la colocación quirúrgica de la pérdida de parada
  • La obtención parcial de beneficios mejora la eficiencia del capital
  • Transmisión en tiempo real del precio de stop loss a la cuenta del corredor
  • El sistema de control de pérdidas en tiempo real se ha probado en vivo.

Los riesgos

  • Existe un retraso en el indicador estocástico
  • La participación en el capital de la empresa en el mercado de valores
  • Las variables dinámicas se comportan de manera diferente en los marcos de tiempo
  • El porcentaje de ganancia parcial necesita optimización

Los riesgos se pueden gestionar ajustando los parámetros estocásticos, ajustando la relación de ganancias parciales, etc.

Mejoras

  • Prueba diferentes combinaciones de parámetros estocásticos
  • Optimizar el ratio de ganancia parcial
  • Explore otros enfoques de stop loss como el stop de trailing
  • Prueba de robustez en todos los mercados y productos

Conclusión

Esta estrategia demuestra la ejecución de operaciones de stop loss dinámicas desde TradingView hasta MT4/5 utilizando nuevas características. Puede servir como marco para pruebas posteriores. Se requiere optimización para activos específicos.


/*backtest
start: 2023-08-18 00:00:00
end: 2023-09-17 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// strategy(title="TradingView Alerts to MT4 MT5 Strategy example", commission_type=strategy.commission.cash_per_order, commission_value=0.00003, overlay=false, default_qty_value=100000, initial_capital=1000)
// study(title="TradingView Alerts to MT4 MT5 Strategy example")  //uncomment this line and comment previous one to make it a study producing alerts
//
// This script was created for educational purposes only.
// It is showing how to use dynamic variables in TradingView alerts.
// And how to execute them in Forex, indices and commodities markets
// thanks to www.tradingconnector.com

TakeProfitLevel=input(400)
TakePartialProfitLevel=input(150)

// **** Entries logic **** {
periodK = input(14, title="K", minval=1)
periodD = input(3, title="D", minval=1)
smoothK = input(4, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)
plot(k, title="%K", color=color.blue)
plot(d, title="%D", color=color.orange)
h0 = hline(80)
h1 = hline(20)
fill(h0, h1, color=color.purple, transp=75)

GoLong=crossover(k,d)// and k<80
GoShort=crossunder(k,d)// and k>20
// } End of entries logic

// **** Pivot-points and stop-loss logic **** {
piv_high = pivothigh(high,1,1)
piv_low = pivotlow(low,1,1)
var float stoploss_long=low
var float stoploss_short=high

pl=valuewhen(piv_low,piv_low,0)
ph=valuewhen(piv_high,piv_high,0)

if GoLong 
    stoploss_long := low<pl ? low : pl
if GoShort 
    stoploss_short := high>ph ? high : ph
// } End of Pivot-points and stop-loss logic

// **** Trade counter and partial closing mechanism **** {
var int trade_id=0
if GoLong or GoShort
    trade_id:=trade_id[1]+1

TakePartialProfitLong = barssince(GoLong)<barssince(GoShort) and crossover(high,(valuewhen(GoLong,close,0)+TakePartialProfitLevel*syminfo.mintick))
TakePartialProfitShort = barssince(GoLong)>barssince(GoShort) and crossunder(low,(valuewhen(GoShort,close,0)-TakePartialProfitLevel*syminfo.mintick))
// } End of Trade counter and partial closing mechanism


strategy.entry("Long", strategy.long, when=GoLong)
strategy.exit("XPartLong", from_entry="Long", qty_percent=50, profit=TakePartialProfitLevel)
strategy.exit("XLong", from_entry="Long", stop=stoploss_long, profit=TakeProfitLevel)
strategy.entry("Short", strategy.short, when=GoShort)
strategy.exit("XPartShort", from_entry="Short", qty_percent=50, profit=TakePartialProfitLevel)
strategy.exit("XShort", from_entry="Short", stop=stoploss_short, profit=TakeProfitLevel)


// alertcondition("Long", when=GoLong, message="long slprice={{stoploss_long}} tradeid={{trade_id}} tp=TakeProfitLevel")
// alertcondition("Short", when=GoShort, message="short slprice={{stoploss_short}} tradeid={{trade_id}} tp=TakeProfitLevel")
// alertcondition("ClosePartLong", when=TakePartialProfitLong, message="closepart tradeit={{trade_id}} part=0.5")
// alertcondition("ClosePartShort", when=TakePartialProfitShort, message="closepart tradeit={{trade_id}} part=0.5")


Más.