Ayuda para crear estrategia de stops
Forums › ProRealTime foro Español › Soporte ProOrder › Ayuda para crear estrategia de stops
- This topic has 5 replies, 2 voices, and was last updated 4 years ago by Juan Salas.
Tagged: ue
-
-
12/11/2019 at 6:29 PM #114697
Hola,
Lo primero saludar a toda la gente ya que este es mi 1º post y creo que no sera el último ya que me estoy iniciando en la creación de mi primer sistema de trading, y lo segundo dar las gracias a cualquier persona que me lea y me responda.
Bueno, estoy intentando crear un sistema escalonado de stops, ya que por ejemplo cuando el precio alcance +10 puntos de beneficio, el stop se ponga ya automáticamente a +2 y el siguiente paso, si el precio alcance los +15 el stop se mueva a +5, etc..y ya alcanzado por ejemplo +20, que haya un tralling stop de 10 en 10 puntos o un seguimiento de porcentaje en 30%
He estado buscando y leyendo algo al respecto y encontre este hilo https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/ y me puse manos al lio, pero siempre el stop se coloca a +10 y cuando va a corto ni me coloca el los stops, me podeis ayudar?
Estrategia de stops12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455//trailing stop functiontrailingstart = 10 //trailing will start @trailinstart points profittrailingstep = 10 //trailing step to move the "stoploss"//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//+10 a +2IF newSL=0 AND close-tradeprice(1)>=trailingstart THENnewSL = tradeprice(1)+2ENDIF//+15 a +5IF newSL=tradeprice(1)+2 AND tradeprice(1)+15 THENnewSL = tradeprice(1)+5ENDIF//+20 a +10IF newSL=tradeprice(1)+5 AND tradeprice(1)+20 THENnewSL = tradeprice(1)+10ENDIF//+20 a seguimiento de tralling 10pIF newSL=tradeprice(1)+10 AND tradeprice(1)+20 THENnewSL = tradeprice(1)+trailingstepENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//+10 a +2IF newSL=0 AND tradeprice(1)-close>=trailingstart THENnewSL = tradeprice(1)-2ENDIF//+10 a +5IF newSL=tradeprice(1)-2 AND tradeprice(1)-10 THENnewSL = tradeprice(1)-5ENDIF//+20 a +10IF newSL=tradeprice(1)-5 AND tradeprice(1)-20 THENnewSL = tradeprice(1)-10ENDIF//+20 a seguimiento de tralling 10pIF newSL=tradeprice(1)-10 AND tradeprice(1)-20 THENnewSL = tradeprice(1)-trailingstepENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIFGracias y un saludo
12/11/2019 at 11:34 PM #114717Hola moha85,
Bienvenido a Prorealcode. A continuación pongo un trailing que yo utilizo y que te permite como quieres tener muchos pasos de trailing. Ejemplo: Si estas en LARGO y el precio sube, al cierre de la vela captura el máximo valor y en relación a ese valor te pone un STOP. A medida que el precio sube va subiendo el STOP, pero ya nunca vuelve atrás.
Para poder personalizarlo, tienes que poner tus cantidades en pips/points en startbreakeven, que serán los valores del precio donde quieres que a partir de ahi, se empiecen a poner los STOP (pointstokeep).
Este código es una simple modificación de uno que he ido cogiendo de la librería de PRC. Cuando te familiarices con la programación, podrás modificarlo como quieras. El código, como puedes ver es para largos y cortos. Los puntos de trailing (startbreakeven y pointstokeep) son los mismos para las dos direcciones.
Espero que te sirva. Si tienes alguna duda, no tengas problema en volver a preguntar.
Saludos,
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422// TRAILING //////////////////////////////////////////////////////////////////////////////////////////////////////////startBreakeven1 =2startBreakeven2 =4startBreakeven3 =6startBreakeven4 =8startBreakeven5 =10startBreakeven6 =12startBreakeven7 =14startBreakeven8 =16startBreakeven9 =18startBreakeven10 =20startBreakeven11 =22startBreakeven12 =24startBreakeven13 =26startBreakeven14 =28startBreakeven15 =30startBreakeven16 =32startBreakeven17 =34startBreakeven18 =36startBreakeven19 =38startBreakeven20 =40//////////////////////PointsToKeep1 =2PointsToKeep2 =3PointsToKeep3 =4PointsToKeep4 =6PointsToKeep5 =7PointsTokeep6 =8PointsToKeep7 =8PointsToKeep8 =8PointsToKeep9 =10PointsTokeep10 =10PointsToKeep11 =10PointsToKeep12 =10PointsToKeep13 =12PointsToKeep14 =12PointsToKeep15 =12PointsTokeep16 =12PointsToKeep17 =14PointsToKeep18 =14PointsToKeep19 =14PointsTokeep20 =14//reset the breakevenLevel when no trade are on marketIF NOT ONMARKET THENbreakevenLevel=0maxprice=0minprice=closeENDIF// LARGOS// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven1*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep1*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven2*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep2*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven3*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep3*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven4*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep4*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven5*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep5*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven6*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep6*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven7*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep7*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven8*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep8*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven9*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep9*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven10*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep10*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven11*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep11*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven12*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep12*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven13*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep13*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven14*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep14*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven15*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep15*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven16*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep16*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven17*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep17*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven18*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep18*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven19*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep19*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF LONGONMARKET THENmaxprice=max(maxprice,close)IF maxprice-tradeprice(1)>=startBreakeven20*pipsize THEN//calculate the breakevenLevelbreakevenLevel = maxprice-PointsToKeep20*pipsizeENDIFENDIF// CORTOS// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven1*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep1*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven2*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep2*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven3*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep3*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven4*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep4*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven5*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep5*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven6*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep6*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven7*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep7*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven8*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep8*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven9*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep9*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven10*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep10*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven11*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep11*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven12*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep12*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven13*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep13*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven14*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep14*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven15*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep15*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven16*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep16*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven17*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep17*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven18*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep18*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven19*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep19*pipsizeENDIFENDIF// test if the price have moved favourably of "startBreakeven" points alreadyIF SHORTONMARKET THENminprice=min(minprice,close)IF tradeprice(1)-minprice>=startBreakeven20*pipsize THEN//calculate the breakevenLevelbreakevenLevel = minprice+PointsToKeep20*pipsizeENDIFENDIF//place the new stop orders on market at breakevenLevelIF breakevenLevel>0 THENSELL AT breakevenLevel STOPEXITSHORT AT breakevenLevel STOPENDIF1 user thanked author for this post.
12/12/2019 at 5:44 PM #114757Muchisimas gracias de verdad Juan Salas,
Solo he usa 6 startBreakeven y PointsToKeep, pero no se si realmente está haciendo bien lo que yo le he determinado, hay alguna manera visualizar ese seguimiento a través de un graph?
Tambien me gustaria que pasado el starbreakeven6, este realice un trallingstop del 70%, pero imagino que esto sera ya otra función diferente, como sería esto?
Otra cosilla que estoy buscando pero todavía no la he encontrado, podría usar esta función de breakeven pero determinado pasados X periodos desde la entrada del trade?
Perdon por tantas preguntas, pero llevando tan solo 5 dias metido en el mundillo, me abrumo con tanta información en el foro
De nuevo gracias por todo 🙂
Un saludo
12/12/2019 at 7:33 PM #114769No sabría como verlo a través de la función graph en un backtest. En mi opinion, aunque rudimentaria, la mejor forma de visualizarlo es ponerlo en demo y ver como va moviéndose el stop loss a medida que avanza el precio.
Si solo utilizas 6 pasos, puedes borrar o descomentar el resto. En cuanto a lo que me comentas del trailing, no sabría ahora mismo como hacerlo.
En cuanto a que el breakeven entre después de x periodos, puedes probar lo siguiente:
12345//place the new stop orders on market at breakevenLevelIF barindex-tradeindex(1)>=10 AND breakevenLevel>0 THENSELL AT breakevenLevel STOPEXITSHORT AT breakevenLevel STOPENDIFNo lo he probado, pero sería algo parecido. Puedes cambiar el 10, por el numero de periodos que prefieras.
Saludos
12/13/2019 at 10:12 AM #114803Gracias de verdad,
Por lo que veo esa función está escrita para que entre el breakevenlevel1 a los 10 periodos, pero imagino que tendria que ponerlo también para el resto de breakeven,no? o ya solo con este afecta a los demás?
Lo de visualizar el movimiento del breakeven, en el codigo de mi primer post, utiliza la función graph enlazado a newSL y si que funcionaba, ahora en este caso, no se como enlazarlo 🙁
Lo de cubrir el 70% de ganancias después del breakeven6 ( es el ultimo que tengo puesto), quizás se podría reconducir esta función a un trallingstop que contenga esta función…
Un saludo y de nuevo mil gracias!!
12/13/2019 at 6:01 PM #114837El breakevenlevel afecta a todos los niveles. Como puedes ver en cada escalón de precio el valor del STOP es breakevenlevel, así que no hay breakevenlevel1, 2, etc.
En cuanto al graph, en vez de NewSL, ahora deberías poner “graph breakevenlevel”
En cuanto a mantener el 70% de ganancia, puedes calcularlo de esta manera:
si el startbreakeven8 (ejemplo) =100, el correspondiente pointstokeep8 sería=30. Dado que lo que hace el código es que una vez alcanza los 100 pips, pone el STOP LOSS a 100-30= 70pips en positivo desde el precio de compra. No tienes que hacerlo desde el principio. Los primeros pasos puedes poner los valores que creas, y a partir de un escalón determinado, podrías mantener la proporcionalidad del 70% en todos los pasos siguientes.
-
AuthorPosts
Find exclusive trading pro-tools on