Buenos días amigos, en especial a gente que me ayuda muchisimo en este foro como robertogozzi , GraHal y Nicolas e Ivan , sois muy valiosos para este foro.
Quiero compartir esta estrategia en el foro por si a alguien le sirve de ayuda, la parte de trailing stop es de usuario Nicolas, a quien le agredezco su ayuda.
Necesitaria por favor alguien me pueda ayudar a incluir a las condiciones Long en caso que las condiciones Long se cumplan (c1 c2 c3, etc) que antes de la entrada verifique al menos 2 los 3 máximos anteriores y que si el precio actual se encuentra a menos de por ejemplo 2% oa menos 5pt de dicho maximo la condicion de entrada sea FALSA, lo mismo pero a la inversa en las condicones SHORT.
Creo que es realmente importante que la estrategia tenga agregada esa mejora y condición para reducir esa tasa de pérdidas por malas entradas cerca de máximos o de mínimos, y evitar reducir la ganancia acumulada por esas malas entradas por no tener esa condición de entrada revisando máximos y minimos anteriores an tes de entrar.
les agradeceria mucho me podais ayudar a incluir dicha condicion al codigo
Agradecido enormemente por la ayuda que me podéis aportar para la solución del problema.
¡¡¡¡¡¡¡Muchas gracias!!!!!!!
//————————————————————————-
// Código principal : SCALPING TRAIL GOZZI
//————————————————————————-
Timeframe(default)
//////// INICIO MONEY MANAGMENT /////////
IF STRATEGYPROFIT > 1000 THEN
QUIT
ENDIF
IF STRATEGYPROFIT < -200 THEN
QUIT
ENDIF
//////// FIN MONEY MANAGMENT /////////
/////////// INICIO HORARIOS DE TRADING ////////////
If date > 20241212 THEN // Stop the strategy after december 12, 2024
QUIT
ENDIF
HoraMadrugadaInicio = 003000 // las 00:20h minutos
HoraMadrugadaFin = 073000 // las 00:20h minutos
HoraDiarioInicio = 073100 // las 00:20h minutos
HoraDiarioFin = 214500 // las 00:20h minutos
IF Time = 215000 THEN
SELL AT MARKET
EXITSHORT AT MARKET
ENDIF
//////// FIN HOARIOS DE TRADING /////////
IF NOT longonmarket then
HacerTrading = 0
Alcista = 0
endif
//// VARIABLES DE SISTEMA //////
EMA9 = Average[9](Close)
EMA20 = Average[20](Close)
EMA50 = Average[50](Close)
VolumenAnterior = Volume[1]
RangoVelaAnterior1 = Range[1]
RangoVelaAnterior2 = Range[2]
IF close[1] > open[1] THEN
Alcista = 1
ENDIF
IF close[1] < open[1] THEN
Alcista = 0
ENDIF
NumeroEstrategia = 0
//REDUNDANCIA DE TAKEPROFIT Y DE STOP LOSS POR SI HAY ALGUNA COMBINACION QUE NO SE HAGA EN LAS SIGUIENTES
MiProfit = 2
MiStop = 0.50
IF NOT LONGONMARKET THEN
IF RangoVelaAnterior1 < 0.50 THEN
HacerTrading = 0
ENDIF
IF RangoVelaAnterior1 >= 0.50 AND RangoVelaAnterior1 <= 0.75 AND Alcista = 1 THEN
HacerTrading = 1
MiProfit = 7
MiStop = 0.50
ENDIF
IF RangoVelaAnterior1 > 0.75 AND RangoVelaAnterior1 <= 1.25 AND Alcista = 1 THEN
HacerTrading = 1
MiProfit = 5
MiStop = 0.50
ENDIF
IF RangoVelaAnterior1 >= 1.50 AND RangoVelaAnterior2 > 2 AND Alcista = 1 THEN
HacerTrading = 7
MiProfit = 10
MiStop = 0.50
ENDIF
ENDIF
////////////////////// FIN DE CONDICIONES DE RANGO Y DEFINICION DE TAKE PROFIT Y STOPS EN BASE A RANGOS DE VELA EN LA ENTRADA ///////////////////
//************************************************************************
//trailing stop function
trailingstart = 1 //trailing will start @trailinstart points profit
trailingstep = 0.75 //trailing step to move the “stoploss”
//reset the stoploss value
IF NOT ONMARKET THEN
newSL=0
ENDIF
//manage long positions
IF LONGONMARKET THEN
//first move (breakeven)
IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THEN
newSL = tradeprice(1)+trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND close-newSL>=trailingstep*pipsize THEN
newSL = newSL+trailingstep*pipsize
ENDIF
ENDIF
//manage short positions
IF SHORTONMARKET THEN
//first move (breakeven)
IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THEN
newSL = tradeprice(1)-trailingstep*pipsize
ENDIF
//next moves
IF newSL>0 AND newSL-close>=trailingstep*pipsize THEN
newSL = newSL-trailingstep*pipsize
ENDIF
ENDIF
//stop order to exit the positions
IF newSL>0 THEN
SELL AT newSL STOP
EXITSHORT AT newSL STOP
ENDIF
IF time >= HoraMadrugadaInicio AND time <= HoraMadrugadaFin OR time >= HoraDiarioInicio AND time <= HoraDiarioFin THEN
ENDIF
//************************************************************************
Timeframe(10 second,updateonclose)
IF HacerTrading = 1 THEN
IF NOT shortonmarket AND NOT longonmarket AND NumeroEstrategia = 0 THEN
C1 = close>close[1] AND high[1] > high[2] and open>open[1]
//C2 = summation[6](close>open) > 4
C3 = EMA9 > EMA20 AND EMA20 > EMA50
C4 = Average[50](Close) < low[1]
C5 = Average[50](Close) < open[1]
C6 = Average[20](Close) < low[1]
C7 = Average[20](Close) < open[1]
C8 = Average[9](Close) < low[1]
C9 = Average[9](Close) < open[1]
C10 = Average[50](Close) < low
C11 = Average[50](Close) < open
C12 = Average[20](Close) < low
C13 = Average[20](Close) < open
C14 = Average[9](Close) < low
C15 = Average[9](Close) < open
if C1 AND C3 AND C4 AND C5 AND C6 AND C7 AND C8 AND C9 AND C10 AND C11 AND C12 AND C13 AND C14 AND C15 then
BUY 1 CONTRACT at open LIMIT
SET TARGET pPROFIT 10
//SL = close / 100 * 1 //2% SL
SET STOP pLOSS 7
ENDIF
ENDIF
ENDIF
IF HacerTrading = 1 THEN
IF NOT shortonmarket AND NOT longonmarket AND NumeroEstrategia = 0 THEN
S1 = summation[2](close<open) < 3
S2 = summation[2](close<open) > 1
S3 = EMA9 < EMA20 AND EMA20 < EMA50
S4 = Average[50](Close) > low[1]
S5 = Average[50](Close) > open[1]
S6 = Average[20](Close) > low[1]
S7 = Average[20](Close) > open[1]
S8 = Average[9](Close) > low[1]
S9 = Average[9](Close) > open[1]
S10 = Average[50](Close) > low
S11 = Average[50](Close) > open
S12 = Average[20](Close) > low
S13 = Average[20](Close) > open
S14 = Average[9](Close) > low
S15 = Average[9](Close) > open
if S1 AND S2 AND S3 AND S4 AND S5 AND S6 AND S7 AND S8 AND S9 AND S10 AND S11 AND S12 AND S13 AND S14 AND S15 then
SELLSHORT 1 CONTRACT at open LIMIT
//SL = close / 100 * 1 //2% SL
SET STOP pLOSS 1.50
ENDIF
ENDIF
ENDIF