En la carga de los recursos... Cargando...

Estrategia de negociación con doble media móvil de regresión

El autor:¿ Qué pasa?, Fecha: 2024-05-24 17:08:38
Las etiquetas:RPKEl ATR

img

Resumen general

Esta estrategia utiliza dos líneas de regresión lineal con diferentes longitudes como señales comerciales, combinadas con ATR para detener pérdidas y tomar ganancias parciales. Cuando la línea de regresión lineal de período más corto cruza por encima de la línea de regresión lineal de período más largo desde abajo, genera una señal larga; por el contrario, cuando la línea de regresión lineal de período más corto cruza por debajo de la línea de regresión lineal de período más largo desde arriba, genera una señal corta. Después de abrir una posición, la estrategia utiliza ATR como una pérdida de stop de trailing, mientras emplea un método de toma de ganancias parciales para maximizar las ganancias.

Principios de estrategia

  1. Calcular dos líneas de regresión lineal con períodos diferentes (default 20 y 40) como señales de negociación
  2. Cuando la línea de regresión lineal de período más corto se cruce por encima de la línea de regresión lineal de período más largo, abrir una posición larga si no hay posición actual
  3. Cuando la línea de regresión lineal de período más corto se cruce por debajo de la línea de regresión lineal de período más largo, abrir una posición corta si no hay posición actual
  4. Una vez abierta una posición, utilizar el ATR para calcular el precio de stop loss trasero y cerrar todas las posiciones cuando el precio alcance el nivel de stop loss
  5. La estrategia también emplea un método de obtención parcial de beneficios, calculando 16 niveles diferentes de porcentaje de obtención de beneficios (del 5% al 80%) en función del precio de entrada y cerrando una cantidad correspondiente de posiciones en cada nivel de obtención de beneficios según el porcentaje de entrada.
  6. Hasta que todas las posiciones estén cerradas

Análisis de ventajas

  1. El uso de la regresión lineal como juicio de tendencia y señal de negociación puede capturar mejor las tendencias
  2. La combinación de dos regresiones lineales con períodos diferentes forma una confirmación de señal más confiable
  3. El uso de ATR como stop loss puede controlar mejor los riesgos y mantenerse sincronizado con las fluctuaciones de precios
  4. El método de obtención parcial de beneficios puede obtener mayores beneficios cuando la tendencia continúa, teniendo también en cuenta el control de riesgos
  5. El código está altamente modularizado con muchos parámetros de entrada, por lo que la estrategia es altamente personalizable

Análisis de riesgos

  1. Las señales de regresión lineal pueden generar señales falsas, lo que conduce a pérdidas
  2. La obtención parcial de beneficios puede dar lugar a períodos de retención más largos, con riesgos de extracción
  3. La configuración incorrecta de los parámetros puede llevar a un mal rendimiento de la estrategia
  4. En condiciones de mercado extremas, la estrategia puede enfrentar importantes reducciones

Direcciones de optimización

  1. Considere la posibilidad de introducir más indicadores o condiciones de filtrado para mejorar la precisión de la señal, como indicadores de confirmación de tendencia, indicadores de volatilidad, etc.
  2. Optimizar la posición y la estrategia del take-profit y el stop-loss, considerar el take-profit dinámico y el stop-loss
  3. Optimiza los parámetros para encontrar la mejor combinación de parámetros
  4. Añadir la gestión de posiciones para ajustar el tamaño de las posiciones de acuerdo con las condiciones de volatilidad del mercado

Resumen de las actividades

Esta doble estrategia de regresión de promedios móviles combina estrategias de seguimiento de tendencias y de toma de ganancias/detención de pérdidas, que pueden capturar eficazmente los mercados de tendencias mientras controlan las reducciones. Sin embargo, la estrategia puede tener un rendimiento inferior en los mercados variados y se enfrenta al problema de la optimización de parámetros. En general, esta estrategia es un representante típico de una estrategia de seguimiento de tendencias y puede usarse como una estrategia base para la optimización y mejora.


/*backtest
start: 2023-05-24 00:00:00
end: 2024-05-23 00:00:00
period: 1d
basePeriod: 1h
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/
// © fuatcakir9

//@version=5

strategy(title = "RPK_V4.3(1K$)_Shared", shorttitle="RPK_V4.3(1K$)_Shared",overlay=true)

////

regresyonUzunluk = input.int(20, minval=1,step = 20, group = "Strategy Condition")
off = 0
sapma = 2
cc1 = close
lreg1 = ta.linreg(cc1, regresyonUzunluk, off)
lreg_x1 = ta.linreg(cc1, regresyonUzunluk, off + 1)
b1 = bar_index
s1 = lreg1 - lreg_x1
intr1 = lreg1 - b1 * s1
dS1 = 0.0
for i1 = 0 to regresyonUzunluk - 1 by 1
    dS1 += math.pow(cc1[i1] - (s1 * (b1 - i1) + intr1), 2)
    dS1
de1 = math.sqrt(dS1 / regresyonUzunluk)
up1 = -de1 * sapma + lreg1
down1 = de1 * sapma + lreg1
t1 = 0
x11 = bar_index - regresyonUzunluk
x21 = bar_index
kirmizi = s1 * (bar_index - regresyonUzunluk) + intr1
yesil = lreg1

//
regresyonUzunlukUst = input.int(40, minval=1,step = 20, group = "Strategy Condition")
cc1Ust = close
lreg1Ust = ta.linreg(cc1Ust, regresyonUzunlukUst, off)
lreg_x1Ust = ta.linreg(cc1Ust, regresyonUzunlukUst, off + 1)
b1Ust = bar_index
s1Ust = lreg1Ust - lreg_x1Ust
intr1Ust = lreg1Ust - b1 * s1Ust
dS1Ust = 0.0
for i1Ust = 0 to regresyonUzunlukUst - 1 by 1
    dS1Ust += math.pow(cc1Ust[i1Ust] - (s1Ust * (b1Ust - i1Ust) + intr1Ust), 2)
    dS1Ust
de1Ust = math.sqrt(dS1Ust / regresyonUzunlukUst)
up1Ust = -de1Ust * sapma + lreg1Ust
down1Ust = de1Ust * sapma + lreg1Ust
t1Ust = 0
x11Ust = bar_index - regresyonUzunlukUst
x21Ust = bar_index
kirmiziUst = s1Ust * (bar_index - regresyonUzunlukUst) + intr1Ust
yesilUst = lreg1Ust
///


trendShort = plot(kirmizi,"RegresyonDown",color = color.rgb(248, 10, 10, 43),linewidth = 1,style = plot.style_line)
trendLong = plot(yesil,"RegresyonUp",color = color.rgb(8, 166, 13, 48),linewidth = 1,style = plot.style_line)

trendShortUst = plot(kirmiziUst,"RegresyonDown",color = color.rgb(255, 82, 82, 40),linewidth = 4,style = plot.style_line)
trendLongUst = plot(yesilUst,"RegresyonUp",color = color.rgb(76, 175, 79, 32),linewidth = 4,style = plot.style_line)

group_strategy = "Settings of Strategy"
Start_Time = input(defval=timestamp('01 January 2000 13:30 +0000'), title='Start Time of BackTest', group =group_strategy)
End_Time = input(defval=timestamp('30 April 2030 19:30 +0000'), title='End Time of BackTest', group =group_strategy)
yearCondition = true

trailingLongPrice = 0.0
trailingShortPrice = 0.0

atr = ta.atr(10)
atrCarpan = input.float(8,"ATR Carpan",step = 2,group = "Strategy Condition")

atrCarpan_changed = input.float(4,"Değişen ATR Carpan",step = 1,group = "Strategy Condition")
istenilen_kapatma_sayisi = input(defval = 16, title = "İstenilen Istem Sayısı",group = "Strategy Condition")



kapatilan_poz =strategy.closedtrades -  ta.valuewhen(strategy.opentrades[1] == 0 and strategy.opentrades == 1,strategy.closedtrades,0)

changed_color_up = color(na)
changed_color_down = color(na)

if kapatilan_poz >= istenilen_kapatma_sayisi
    atrCarpan := atrCarpan_changed
    changed_color_up := color.rgb(0, 255, 8)
    changed_color_down := color.rgb(255, 0, 0)
else
    changed_color_up := color.green
    changed_color_down := color.red

//

if strategy.position_size > 0
    stopValue = low - atrCarpan*atr
    trailingLongPrice := math.max(stopValue, trailingLongPrice[1])
else
    trailingLongPrice:=0


if strategy.position_size <0
    stopValue = high + atrCarpan*atr
    trailingShortPrice := math.min(stopValue, trailingShortPrice[1])
else
    trailingShortPrice :=99999

plot(strategy.position_size < 0 ? trailingShortPrice : na , color = changed_color_down, linewidth=3, style = plot.style_linebr)
plot(strategy.position_size > 0 ? trailingLongPrice : na , color=changed_color_up, linewidth=3,style = plot.style_linebr)



TP_Long_1_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=55"
TP_Long_2_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=60"
TP_Long_3_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=65"
TP_Long_4_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=66"
TP_Long_5_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=66"
TP_Long_6_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=67"
TP_Long_7_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=67"
TP_Long_8_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=68"
TP_Long_9_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=68"
TP_Long_10_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=69"
TP_Long_11_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=69"
TP_Long_12_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=70"
TP_Long_13_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=70"
TP_Long_14_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=71"
TP_Long_15_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=72"
TP_Long_16_Msg="\nYon=SELL\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=73"

TP_Short_1_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=55"
TP_Short_2_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=60"
TP_Short_3_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=65"
TP_Short_4_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=66"
TP_Short_5_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=66"
TP_Short_6_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=67"
TP_Short_7_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=67"
TP_Short_8_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=68"
TP_Short_9_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=68"
TP_Short_10_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=69"
TP_Short_11_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=69"
TP_Short_12_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=70"
TP_Short_13_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=70"
TP_Short_14_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=71"
TP_Short_15_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=72"
TP_Short_16_Msg="\nYon=BUY\nSembol={{ticker}}\nPiyasa=FUTURE\nTip=MARKET\nTutar=73"
//
longTSL = (ta.crossunder(close,trailingLongPrice)) and strategy.opentrades != 0
shortTSL = ta.crossover(close,trailingShortPrice) and strategy.opentrades != 0
 
longCondition3 = ta.crossover(yesil[1],kirmizi[1]) and yesilUst > kirmiziUst 
shortCondition3 = ta.crossunder(yesil[1],kirmizi[1]) and yesilUst < kirmiziUst 

longCondition =  longCondition3 and yearCondition and strategy.opentrades == 0 and strategy.position_size == 0
shortCondition =  shortCondition3 and yearCondition and strategy.opentrades == 0 and strategy.position_size == 0
//
tp1 = input.float(defval = 10.0, title = "TP1 Percent", inline = "1", group ="##### TP AND SL #####")/100
tp1_percent = input.int(defval = 5, title = "% TP1 Kapatma ", inline = "1", group ="##### TP AND SL #####")
tp2 = input.float(defval = 10.0, title = "TP2 Percent", inline = "2", group ="##### TP AND SL #####")/100
tp2_percent = input.int(defval = 5, title = "% TP2 Kapatma ", inline = "2", group ="##### TP AND SL #####")
tp3 = input.float(defval = 10.0, title = "TP3 Percent", inline = "3", group ="##### TP AND SL #####")/100
tp3_percent = input.int(defval = 5, title = "% TP3 Kapatma ", inline = "3", group ="##### TP AND SL #####")
tp4 = input.float(defval = 1.0, title = "TP4 Percent", inline = "4", group ="##### TP AND SL #####")/100
tp4_percent = input.int(defval = 5, title = "% TP4 Kapatma ", inline = "4", group ="##### TP AND SL #####")
tp5 = input.float(defval = 1.0, title = "TP5 Percent", inline = "5", group ="##### TP AND SL #####")/100
tp5_percent = input.int(defval = 5, title = "% TP5 Kapatma ", inline = "5", group ="##### TP AND SL #####")
tp6 = input.float(defval = 1.0, title = "TP6 Percent", inline = "6", group ="##### TP AND SL #####")/100
tp6_percent = input.int(defval = 5, title = "% TP6 Kapatma ", inline = "6", group ="##### TP AND SL #####")
tp7 = input.float(defval = 1.0, title = "TP7 Percent", inline = "7", group ="##### TP AND SL #####")/100
tp7_percent = input.int(defval = 5, title = "% TP7 Kapatma ", inline = "7", group ="##### TP AND SL #####")
tp8 = input.float(defval = 1.0, title = "TP8 Percent", inline = "8", group ="##### TP AND SL #####")/100
tp8_percent = input.int(defval = 5, title = "% TP8 Kapatma ", inline = "8", group ="##### TP AND SL #####")
tp9 = input.float(defval = 1.0, title = "TP9 Percent", inline = "9", group ="##### TP AND SL #####")/100
tp9_percent = input.int(defval = 5, title = "% TP9 Kapatma ", inline = "9", group ="##### TP AND SL #####")
tp10 = input.float(defval = 1.0, title = "TP10 Percent", inline = "10", group ="##### TP AND SL #####")/100
tp10_percent = input.int(defval = 5, title = "% TP10 Kapatma ", inline = "10", group ="##### TP AND SL #####")
tp11 = input.float(defval = 1.0, title = "TP11 Percent", inline = "11", group ="##### TP AND SL #####")/100
tp11_percent = input.int(defval = 5, title = "% TP11 Kapatma ", inline = "11", group ="##### TP AND SL #####")
tp12 = input.float(defval = 1.0, title = "TP12 Percent", inline = "12", group ="##### TP AND SL #####")/100
tp12_percent = input.int(defval = 5, title = "% TP12 Kapatma ", inline = "12", group ="##### TP AND SL #####")
tp13 = input.float(defval = 1.0, title = "TP13 Percent", inline = "13", group ="##### TP AND SL #####")/100
tp13_percent = input.int(defval = 5, title = "% TP13 Kapatma ", inline = "13", group ="##### TP AND SL #####")
tp14 = input.float(defval = 1.0, title = "TP14 Percent", inline = "14", group ="##### TP AND SL #####")/100
tp14_percent = input.int(defval = 5, title = "% TP14 Kapatma ", inline = "14", group ="##### TP AND SL #####")
tp15 = input.float(defval = 1.0, title = "TP15 Percent", inline = "15", group ="##### TP AND SL #####")/100
tp15_percent = input.int(defval = 5, title = "% TP15 Kapatma ", inline = "15", group ="##### TP AND SL #####")
tp16 = input.float(defval = 1.0, title = "TP16 Percent", inline = "16", group ="##### TP AND SL #####")/100
tp16_percent = input.int(defval = 5, title = "% TP16 Kapatma ", inline = "16", group ="##### TP AND SL #####")


v2takeprofit_level_long1 = strategy.position_avg_price * (1 + tp1 )
v2takeprofit_level_long2 = strategy.position_avg_price * (1 + (tp2+ tp1))
v2takeprofit_level_long3 = strategy.position_avg_price * (1 + (tp3 + tp2 + tp1))
v2takeprofit_level_long4 = strategy.position_avg_price * (1 + (tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_long5 = strategy.position_avg_price * (1 + (tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_long6 = strategy.position_avg_price * (1 + (tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_long7 = strategy.position_avg_price * (1 + (tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_long8 = strategy.position_avg_price * (1 + (tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_long9 = strategy.position_avg_price * (1 + (tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_long10 = strategy.position_avg_price * (1 + (tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_long11 = strategy.position_avg_price * (1 + (tp11 + tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_long12 = strategy.position_avg_price * (1 + (tp12 + tp11 + tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_long13 = strategy.position_avg_price * (1 + (tp13 + tp12 + tp11 + tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_long14 = strategy.position_avg_price * (1 + (tp14 + tp13 + tp12 + tp11 + tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_long15 = strategy.position_avg_price * (1 + (tp15 + tp14 + tp13 + tp12 + tp11 + tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_long16 = strategy.position_avg_price * (1 + (tp16 + tp15 + tp14 + tp13 + tp12 + tp11 + tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))

v2takeprofit_level_short1 = strategy.position_avg_price * (1 - tp1 )
v2takeprofit_level_short2 = strategy.position_avg_price * (1 - (tp2 + tp1))
v2takeprofit_level_short3 = strategy.position_avg_price * (1 - (tp3 + tp2 + tp1))
v2takeprofit_level_short4 = strategy.position_avg_price * (1 - (tp4 + tp3 + tp2 + tp1))
v2takeprofit_level_short5 = strategy.position_avg_price * (1 - (tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_short6 = strategy.position_avg_price * (1 - (tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_short7 = strategy.position_avg_price * (1 - (tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_short8 = strategy.position_avg_price * (1 - (tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_short9 = strategy.position_avg_price * (1 - (tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_short10 = strategy.position_avg_price * (1 - (tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_short11 = strategy.position_avg_price * (1 - (tp11 + tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_short12 = strategy.position_avg_price * (1 - (tp12 + tp11 + tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_short13 = strategy.position_avg_price * (1 - (tp13 + tp12 + tp11 + tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_short14 = strategy.position_avg_price * (1 - (tp14 + tp13 + tp12 + tp11 + tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_short15 = strategy.position_avg_price * (1 - (tp15 + tp14 + tp13 + tp12 + tp11 + tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))
v2takeprofit_level_short16 = strategy.position_avg_price * (1 - (tp16 + tp15 + tp14 + tp13 + tp12 + tp11 + tp10 + tp9 + tp8 + tp7 + tp6 + tp5 + tp4 + tp3 + tp2+ tp1))





if (longCondition)
    strategy.entry("Long", strategy.long, comment = "Long Giriş")

if (shortCondition)
    strategy.entry("Short", strategy.short, comment = "Short Giriş")

if longTSL 
    strategy.close("Long",comment = "Long TSL")
if shortTSL  
    strategy.close("Short", comment = "Short TSL")

if  strategy.position_size > 0 
    strategy.exit('TP_Long_1',from_entry = "Long", limit= v2takeprofit_level_long1 , qty_percent=tp1_percent, alert_message = TP_Long_1_Msg)
if  strategy.position_size > 0    
    strategy.exit('TP_Long_2',from_entry = "Long", limit= v2takeprofit_level_long2 ,qty_percent=tp2_percent, alert_message = TP_Long_2_Msg)
if  strategy.position_size > 0     
    strategy.exit('TP_Long_3',from_entry = "Long", limit= v2takeprofit_level_long3 ,qty_percent= tp3_percent, alert_message = TP_Long_3_Msg)
if  strategy.position_size > 0    
    strategy.exit('TP_Long_4',from_entry = "Long", limit= v2takeprofit_level_long4 ,qty_percent= tp4_percent, alert_message = TP_Long_4_Msg)
if  strategy.position_size > 0 
    strategy.exit('TP_Long_5',from_entry = "Long", limit= v2takeprofit_level_long5 , qty_percent=tp5_percent, alert_message = TP_Long_5_Msg)
if  strategy.position_size > 0    
    strategy.exit('TP_Long_6',from_entry = "Long", limit= v2takeprofit_level_long6 ,qty_percent=tp6_percent, alert_message = TP_Long_6_Msg)
if  strategy.position_size > 0     
    strategy.exit('TP_Long_7',from_entry = "Long", limit= v2takeprofit_level_long7 ,qty_percent= tp7_percent, alert_message = TP_Long_7_Msg)
if  strategy.position_size > 0    
    strategy.exit('TP_Long_8',from_entry = "Long", limit= v2takeprofit_level_long8 ,qty_percent= tp8_percent, alert_message = TP_Long_8_Msg)
if  strategy.position_size > 0 
    strategy.exit('TP_Long_9',from_entry = "Long", limit= v2takeprofit_level_long9 , qty_percent=tp9_percent, alert_message = TP_Long_9_Msg)
if  strategy.position_size > 0    
    strategy.exit('TP_Long_10',from_entry = "Long", limit= v2takeprofit_level_long10 ,qty_percent=tp10_percent, alert_message = TP_Long_10_Msg)
if  strategy.position_size > 0     
    strategy.exit('TP_Long_11',from_entry = "Long", limit= v2takeprofit_level_long11 ,qty_percent= tp11_percent, alert_message = TP_Long_11_Msg)
if  strategy.position_size > 0    
    strategy.exit('TP_Long_12',from_entry = "Long", limit= v2takeprofit_level_long12 ,qty_percent= tp12_percent, alert_message = TP_Long_12_Msg)
if  strategy.position_size > 0 
    strategy.exit('TP_Long_13',from_entry = "Long", limit= v2takeprofit_level_long13 , qty_percent=tp13_percent, alert_message = TP_Long_13_Msg)
if  strategy.position_size > 0    
    strategy.exit('TP_Long_14',from_entry = "Long", limit= v2takeprofit_level_long14 ,qty_percent=tp14_percent, alert_message = TP_Long_14_Msg)
if  strategy.position_size > 0     
    strategy.exit('TP_Long_15',from_entry = "Long", limit= v2takeprofit_level_long15 ,qty_percent= tp15_percent, alert_message = TP_Long_15_Msg)
if  strategy.position_size > 0    
    strategy.exit('TP_Long_16',from_entry = "Long", limit= v2takeprofit_level_long16 ,qty_percent= tp16_percent, alert_message = TP_Long_16_Msg)

if  strategy.position_size < 0 
    strategy.exit('TP_Short_1',from_entry = "Short", limit= v2takeprofit_level_short1 , qty_percent=tp1_percent, alert_message = TP_Short_1_Msg)
if  strategy.position_size < 0    
    strategy.exit('TP_Short_2',from_entry = "Short", limit= v2takeprofit_level_short2 ,qty_percent=tp2_percent, alert_message = TP_Short_2_Msg)
if  strategy.position_size < 0     
    strategy.exit('TP_Short_3',from_entry = "Short", limit= v2takeprofit_level_short3 ,qty_percent= tp3_percent, alert_message = TP_Short_3_Msg)
if  strategy.position_size < 0    
    strategy.exit('TP_Short_4',from_entry = "Short", limit= v2takeprofit_level_short4 ,qty_percent= tp4_percent, alert_message = TP_Short_4_Msg)
if  strategy.position_size < 0 
    strategy.exit('TP_Short_5',from_entry = "Short", limit= v2takeprofit_level_short5 , qty_percent=tp5_percent, alert_message = TP_Short_5_Msg)
if  strategy.position_size < 0    
    strategy.exit('TP_Short_6',from_entry = "Short", limit= v2takeprofit_level_short6 ,qty_percent=tp6_percent, alert_message = TP_Short_6_Msg)
if  strategy.position_size < 0     
    strategy.exit('TP_Short_7',from_entry = "Short", limit= v2takeprofit_level_short7 ,qty_percent= tp7_percent, alert_message = TP_Short_7_Msg)
if  strategy.position_size < 0    
    strategy.exit('TP_Short_8',from_entry = "Short", limit= v2takeprofit_level_short8 ,qty_percent= tp8_percent, alert_message = TP_Short_8_Msg)
if  strategy.position_size < 0 
    strategy.exit('TP_Short_9',from_entry = "Short", limit= v2takeprofit_level_short9 , qty_percent=tp9_percent, alert_message = TP_Short_9_Msg)
if  strategy.position_size < 0    
    strategy.exit('TP_Short_10',from_entry = "Short", limit= v2takeprofit_level_short10 ,qty_percent=tp10_percent, alert_message = TP_Short_10_Msg)
if  strategy.position_size < 0     
    strategy.exit('TP_Short_11',from_entry = "Short", limit= v2takeprofit_level_short11 ,qty_percent= tp11_percent, alert_message = TP_Short_11_Msg)
if  strategy.position_size < 0    
    strategy.exit('TP_Short_12',from_entry = "Short", limit= v2takeprofit_level_short12 ,qty_percent= tp12_percent, alert_message = TP_Short_12_Msg)
if  strategy.position_size < 0 
    strategy.exit('TP_Short_13',from_entry = "Short", limit= v2takeprofit_level_short13 , qty_percent=tp13_percent, alert_message = TP_Short_13_Msg)
if  strategy.position_size < 0    
    strategy.exit('TP_Short_14',from_entry = "Short", limit= v2takeprofit_level_short14 ,qty_percent=tp14_percent, alert_message = TP_Short_14_Msg)
if  strategy.position_size < 0     
    strategy.exit('TP_Short_15',from_entry = "Short", limit= v2takeprofit_level_short15 ,qty_percent= tp15_percent, alert_message = TP_Short_15_Msg)
if  strategy.position_size < 0    
    strategy.exit('TP_Short_16',from_entry = "Short", limit= v2takeprofit_level_short16 ,qty_percent= tp16_percent, alert_message = TP_Short_16_Msg)

Relacionados

Más.