Hola a todos!!
Estoy intentado configurar un stop dinámico en ProOrder, y que me lo muestre en el gráfico. Tanto para compras como ventas. Pero no consigo hacerlo funcionar. Veo que no funciona bien y luego tampoco los muestra correctamente. Por si alguien me puede orientar, añado el código, gracias!!
// Definición de los parámetros
DEFPARAM CumulateOrders = False
// RESET VALORES
StopVisualLong = UNDEFINED
StopVisualShort = UNDEFINED
// — 2. ENTRADAS —
indicator1 = WeightedAverage(close)
indicator2 = Average(close)
c1 = (indicator1 CROSSES OVER indicator2)
c3 = (indicator1 CROSSES UNDER indicator2)
IF c1 AND NOT LONGONMARKET THEN
BUY 5000 CASH AT MARKET
SET STOP %LOSS 15
SLCompra = tradeprice(1) * 0.85
ENDIF
IF c3 AND NOT SHORTONMARKET THEN
SELLSHORT 5000 CASH AT MARKET
SET STOP %LOSS 15
SLVenta = tradeprice(1) * 1.15
ENDIF
// — 3. LÓGICA DE TRAILING Y ASIGNACIÓN —
StopDinamico = 0.15
StopStep = 0.05
IF LONGONMARKET THEN
// Trailing Largos
IF close >= tradeprice(1) * (1 + StopDinamico) THEN
NivelTemporal = tradeprice(1) * (1 + StopStep)
IF NivelTemporal > SLCompra OR SLCompra = UNDEFINED THEN
SLCompra = NivelTemporal
ENDIF
ENDIF
IF SLCompra <> UNDEFINED AND close >= SLCompra * (1 + StopStep) THEN
SLCompra = SLCompra * (1 + StopStep)
ENDIF
// Asignación visual
StopVisualLong = SLCompra
SLVenta = UNDEFINED
SLCompra = UNDEFINED
ELSIF SHORTONMARKET THEN
// Trailing Cortos
IF close <= tradeprice(1) * (1 – StopDinamico) THEN
NivelTemporal = tradeprice(1) * (1 – StopStep)
IF NivelTemporal < SLVenta OR SLVenta = UNDEFINED THEN
SLVenta = NivelTemporal
ENDIF
ENDIF
IF SLVenta <> UNDEFINED AND close <= SLVenta * (1 – StopStep) THEN
SLVenta = SLVenta * (1 – StopStep)
ENDIF
// Asignación visual
StopVisualShort = SLVenta
ELSE
// RESET TOTAL (Usamos UNDEFINED para que no dibuje el nivel 0)
SLVenta = UNDEFINED
SLCompra = UNDEFINED
ENDIF
// — 4. ÓRDENES DE SALIDA —
IF SLCompra <> UNDEFINED THEN
IF LONGONMARKET THEN
SELL AT SLCompra STOP
ENDIF
ENDIF
IF SLVenta <> UNDEFINED THEN
IF SHORTONMARKET THEN
EXITSHORT AT SLVenta STOP
ENDIF
ENDIF
SET TARGET %PROFIT 40
// — 5. GRÁFICOS —
GRAPHONPRICE StopVisualLong AS “Stop Compra” COLOURED(0,255,0)
GRAPHONPRICE StopVisualShort AS “Stop Venta” COLOURED(255,0,0)