ProOrder no permite el uso de stops combinados
Forums › ProRealTime foro Español › Soporte ProOrder › ProOrder no permite el uso de stops combinados
- This topic has 5 replies, 2 voices, and was last updated 2 years ago by robertogozzi.
-
-
10/02/2022 at 7:21 PM #201792
Hola, alguien sabria decirme como pongo el trailing stop y el stop loss para que me deje hacer el proorder automatico, o es imposible???
// quitado filtro horario: AND Time > 143000 AND Time < 220000
periodos = 50
// Condiciones para entrada de posiciones largas
IF NOT LongOnMarket AND Open < ExponentialAverage[periodos](Close) AND Close > ExponentialAverage[periodos](Close) THEN
BUY lotes CONTRACTS AT MARKET
SET STOP LOSS sl pTRAILING tl
SET TARGET pPROFIT tp
ENDIF// Condiciones de entrada de posiciones cortas
IF NOT ShortOnMarket AND Open > ExponentialAverage[periodos](Close) AND Close < ExponentialAverage[periodos](Close) THEN
SELLSHORT lotes CONTRACTS AT MARKET
SET STOP LOSS sl pTRAILING tl
SET TARGET pPROFIT tp
ENDIF10/03/2022 at 12:58 AM #201795El manual dice que puedes usar:
1SET STOP LOSS sl pTRAILING tlpero en realidad solo puede hacerlo en backtests, NO en autotrading, ya que no puede escribir dos tipos diferentes de stop loss en la misma línea.
Necesitas usar uno de estos dos:
12SET STOP pLOSS sl //or SET STOP LOSS slSET STOP pTRAILING tl //or SET STOP TRAILING tlsi usa ambos, la segunda línea anulará la primera, ya que el código se lee secuencialmente de arriba a abajo.
10/03/2022 at 9:30 AM #201817Muchas gracias por contestar,Mila verdad que yo soy de letras y esto me cuesta mucho, entonces le agradezco si me puede ayudar…
lo que quiero es si por ejemplo entro en NQ al precio de 11000, poner un stop los de 50 puntos y un profit de 150, cuando el precio se haya ido a 11020, que el stop pase a breakeven +2, si el precio llega a 11025 que el stop pase a 11020 y ya vaya persiguiendo al precio a 5 puntos de distancia. Esto sería posible??
muchas graciasSusana Arias
10/03/2022 at 6:04 PM #201860Agregue, al final de su código, este escrito por Nicolás (lo modifiqué ligeramente para que los puntos se guardaran en el punto de breakeven).
Solo tienes que poner los valores que prefieras a los tres parámetros:
- trailingstart
- trailingstep
- PointsToKeep
1234567891011121314151617181920212223242526272829303132333435363738394041424344//*********************************************************************************// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/// (lines 17- 56)////trailing stop functiontrailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"PointsToKeep = 2 //keep rhese points when it is first triggered//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND (close-tradeprice(1)) >= trailingstart*pipsize THENnewSL = tradeprice(1)+PointsToKeep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-PointsToKeep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//*********************************************************************************10/04/2022 at 3:43 PM #201912Hola, pego tu código después del mío pero me da error, algo tengo que estar haciendo mal…puedes ayudarme por favor, lo que quiero es que haga la entrada tanto en corto como en largo al cierre de vela por encima (largo) o por debajo (corto) de la EMA 20, y si por ejemplo entro en NQ al precio de 11000, poner un stop loss de 50 puntos y un profit de 150, cuando el precio se haya ido a 11020, que el stop pase a breakeven +2, si el precio llega a 11025 que el stop pase a 11020 y ya vaya persiguiendo al precio a 5 puntos de distancia. cuando hago el backtesting me da error y no se porque, ya he cambiado mil cosas y nada…
saludos
Susana
// quitado filtro horario: AND Time > 143000 AND Time < 220000
periodos = 50
// Condiciones para entrada de posiciones largas
IF NOT LongOnMarket AND Open < ExponentialAverage[periodos](Close) AND Close > ExponentialAverage[periodos](Close) THEN
BUY lotes CONTRACTS AT MARKET
SET STOP LOSS sl pTRAILING tl
SET TARGET pPROFIT tp
ENDIF// Condiciones de entrada de posiciones cortas
IF NOT ShortOnMarket AND Open > ExponentialAverage[periodos](Close) AND Close < ExponentialAverage[periodos](Close) THEN
SELLSHORT lotes CONTRACTS AT MARKET
SET STOP LOSS sl pTRAILING tl
SET TARGET pPROFIT tp
ENDIF<span class=”crayon-c”>//*********************************************************************************</span><span class=”crayon-c”>// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/</span><span class=”crayon-c”>// (lines 17- 56)</span><span class=”crayon-c”>//</span><span class=”crayon-c”>//trailing stop function</span>trailingstart <span class=”crayon-o”>=</span> <span class=”crayon-cn”>20</span><span class=”crayon-h”> </span><span class=”crayon-c”>//trailing will start @trailinstart points profit</span>trailingstep<span class=”crayon-h”> </span><span class=”crayon-o”>=</span> <span class=”crayon-cn”>5</span><span class=”crayon-h”> </span><span class=”crayon-c”>//trailing step to move the “stoploss”</span>PointsToKeep<span class=”crayon-h”> </span><span class=”crayon-o”>=</span> <span class=”crayon-cn”>2</span><span class=”crayon-h”> </span><span class=”crayon-c”>//keep rhese points when it is first triggered</span><span class=”crayon-c”>//reset the stoploss value</span><span class=”crayon-st”>IF</span> <span class=”crayon-st”>NOT</span> <span class=”crayon-st”>ONMARKET</span> <span class=”crayon-st”>THEN</span>newSL<span class=”crayon-o”>=</span><span class=”crayon-cn”>0</span><span class=”crayon-st”>ENDIF</span><span class=”crayon-c”>//manage long positions</span><span class=”crayon-st”>IF</span> <span class=”crayon-st”>LONGONMARKET</span> <span class=”crayon-st”>THEN</span><span class=”crayon-c”>//first move (breakeven)</span><span class=”crayon-st”>IF</span> newSL<span class=”crayon-o”>=</span><span class=”crayon-cn”>0</span> <span class=”crayon-st”>AND</span> (<span class=”crayon-st”>close</span><span class=”crayon-o”>-</span><span class=”crayon-st”>tradeprice</span>(<span class=”crayon-cn”>1</span>)) <span class=”crayon-o”>>=</span> trailingstart<span class=”crayon-o”>*</span><span class=”crayon-st”>pipsize</span> <span class=”crayon-st”>THEN</span><span class=”crayon-h”> </span>newSL <span class=”crayon-o”>=</span> <span class=”crayon-st”>tradeprice</span>(<span class=”crayon-cn”>1</span>)<span class=”crayon-o”>+</span>PointsToKeep<span class=”crayon-o”>*</span><span class=”crayon-st”>pipsize</span><span class=”crayon-st”>ENDIF</span><span class=”crayon-c”>//next moves</span><span class=”crayon-st”>IF</span> newSL<span class=”crayon-o”>></span><span class=”crayon-cn”>0</span> <span class=”crayon-st”>AND</span> <span class=”crayon-st”>close</span><span class=”crayon-o”>-</span>newSL<span class=”crayon-o”>>=</span>trailingstep<span class=”crayon-o”>*</span><span class=”crayon-st”>pipsize</span> <span class=”crayon-st”>THEN</span><span class=”crayon-h”> </span>newSL <span class=”crayon-o”>=</span> newSL<span class=”crayon-o”>+</span>trailingstep<span class=”crayon-o”>*</span><span class=”crayon-st”>pipsize</span><span class=”crayon-st”>ENDIF</span><span class=”crayon-st”>ENDIF</span><span class=”crayon-c”>//manage short positions</span><span class=”crayon-st”>IF</span> <span class=”crayon-st”>SHORTONMARKET</span> <span class=”crayon-st”>THEN</span><span class=”crayon-c”>//first move (breakeven)</span><span class=”crayon-st”>IF</span> newSL<span class=”crayon-o”>=</span><span class=”crayon-cn”>0</span> <span class=”crayon-st”>AND</span> <span class=”crayon-st”>tradeprice</span>(<span class=”crayon-cn”>1</span>)<span class=”crayon-o”>-</span><span class=”crayon-st”>close</span><span class=”crayon-o”>>=</span>trailingstart<span class=”crayon-o”>*</span><span class=”crayon-st”>pipsize</span> <span class=”crayon-st”>THEN</span><span class=”crayon-h”> </span>newSL <span class=”crayon-o”>=</span> <span class=”crayon-st”>tradeprice</span>(<span class=”crayon-cn”>1</span>)<span class=”crayon-o”>-</span>PointsToKeep<span class=”crayon-o”>*</span><span class=”crayon-st”>pipsize</span><span class=”crayon-st”>ENDIF</span><span class=”crayon-c”>//next moves</span><span class=”crayon-st”>IF</span> newSL<span class=”crayon-o”>></span><span class=”crayon-cn”>0</span> <span class=”crayon-st”>AND</span> newSL<span class=”crayon-o”>-</span><span class=”crayon-st”>close</span><span class=”crayon-o”>>=</span>trailingstep<span class=”crayon-o”>*</span><span class=”crayon-st”>pipsize</span> <span class=”crayon-st”>THEN</span><span class=”crayon-h”> </span>newSL <span class=”crayon-o”>=</span> newSL<span class=”crayon-o”>-</span>trailingstep<span class=”crayon-o”>*</span><span class=”crayon-st”>pipsize</span><span class=”crayon-st”>ENDIF</span><span class=”crayon-st”>ENDIF</span><span class=”crayon-c”>//stop order to exit the positions</span><span class=”crayon-st”>IF</span> newSL<span class=”crayon-o”>></span><span class=”crayon-cn”>0</span> <span class=”crayon-st”>THEN</span><span class=”crayon-st”>SELL</span> <span class=”crayon-st”>AT</span> newSL <span class=”crayon-st”>STOP</span><span class=”crayon-st”>EXITSHORT</span> <span class=”crayon-st”>AT</span> newSL <span class=”crayon-st”>STOP</span><span class=”crayon-st”>ENDIF</span><span class=”crayon-c”>//*********************************************************************************</span>10/04/2022 at 7:15 PM #201927Te invito a releer el post https://www.prorealcode.com/topic/proorder-no-permite-el-uso-de-stops-combinados/#post-201795.
Esto funciona:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869DEFPARAM CumulateOrders = False// quitado filtro horario: AND Time > 143000 AND Time < 220000periodos = 100lotes = 1sl = 50tp = 150// Condiciones para entrada de posiciones largasIF NOT LongOnMarket AND Open < ExponentialAverage[periodos](Close) AND Close > ExponentialAverage[periodos](Close) THENBUY lotes CONTRACTS AT MARKETSET STOP LOSS slSET TARGET pPROFIT tpENDIF// Condiciones de entrada de posiciones cortasIF NOT ShortOnMarket AND Open > ExponentialAverage[periodos](Close) AND Close < ExponentialAverage[periodos](Close) THENSELLSHORT lotes CONTRACTS AT MARKETSET STOP LOSS slSET TARGET pPROFIT tpENDIF////*********************************************************************************// https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/// (lines 17- 56)////trailing stop functiontrailingstart = 20 //trailing will start @trailinstart points profittrailingstep = 5 //trailing step to move the "stoploss"PointsToKeep = 2 //keep rhese points when it is first triggered//reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND (close-tradeprice(1)) >= trailingstart*pipsize THENnewSL = tradeprice(1)+PointsToKeep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-PointsToKeep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//*********************************************************************************graphonprice TradePricegraphonprice NewSL coloured(255,0,0,255) -
AuthorPosts
Find exclusive trading pro-tools on