XavierAndreu

Stop Loss Take Profit Automático

May 2nd, 2022
3,673
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. //Youtube: https://youtu.be/w-ipm3nkvWs
  2.  
  3. #include<Trade\Trade.mqh> CTrade trade;
  4.  
  5. double AperturaVenta=0;double SLVenta=0;double TPVenta=0;bool Venta=false;
  6. double AperturaCompra=0; double SLCompra=0; double TPCompra=0;bool Compra=false;
  7.  
  8. void OnTick()
  9. {
  10. for(int a=0; a<PositionsTotal() ; a++)
  11. {
  12. ulong Ticket=PositionGetTicket(a);
  13.  
  14. if(_Symbol == PositionGetString(POSITION_SYMBOL))
  15. {
  16. //COMPRA
  17. if(PositionGetInteger(POSITION_TYPE)== POSITION_TYPE_BUY && Compra==false)
  18. {
  19. AperturaCompra=PositionGetDouble(POSITION_PRICE_OPEN);
  20. SLCompra= AperturaCompra - 500*_Point;
  21. TPCompra= AperturaCompra + 500*_Point;
  22.  
  23. trade.PositionModify(Ticket,SLCompra,TPCompra);
  24. Compra=true;
  25. }
  26. //VENTA
  27. if(PositionGetInteger(POSITION_TYPE)== POSITION_TYPE_SELL && Venta==false)
  28. {
  29. AperturaVenta=PositionGetDouble(POSITION_PRICE_OPEN);
  30. SLVenta= AperturaVenta + 500*_Point;
  31. TPVenta= AperturaVenta - 500*_Point;
  32.  
  33. trade.PositionModify(Ticket,SLVenta,TPVenta);
  34. Venta=true;
  35. }
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment