Forums › ProRealTime foro Español › Soporte ProOrder › ProOrder no permite el uso de stops combinados › Reply To: ProOrder no permite el uso de stops combinados
10/03/2022 at 6:04 PM
#201860
Agregue, 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
//********************************************************************************* // https://www.prorealcode.com/blog/trading/complete-trailing-stop-code-function/ // (lines 17- 56) // //trailing stop function trailingstart = 20 //trailing will start @trailinstart points profit trailingstep = 5 //trailing step to move the "stoploss" PointsToKeep = 2 //keep rhese points when it is first triggered //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)+PointsToKeep*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)-PointsToKeep*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 //********************************************************************************* |