Download MetaTrader 5

Implement Break Even

To add comments, please log in or register
We have launched Spanish and Portuguese versions of the website. Try them!
amando
423
amando 2014.12.20 15:54 

Hello,

 

i use an EA and have a working Sell Order, during the sell order working i also place some Long Order, but when i want to modify my order, i get always an error.

 

Code for Order Modify:

void OnTick()
  {

   if(PositionSelect(_Symbol))
     {

      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY && Ask-BreakEven*_Point>PositionGetDouble(POSITION_PRICE_OPEN) && PositionGetDouble(POSITION_PRICE_OPEN)!=PositionGetDouble(POSITION_SL))
        {

         PositionModify(_Symbol,PositionGetDouble(POSITION_PRICE_OPEN),PositionGetDouble(POSITION_TP));
         Print("BuyModify: ",PositionGetDouble(POSITION_PRICE_OPEN)," Ask: ",Ask," SL: ",PositionGetDouble(POSITION_PRICE_OPEN));
        }

      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL && Bid+BreakEven*_Point<PositionGetDouble(POSITION_PRICE_OPEN) && PositionGetDouble(POSITION_PRICE_OPEN)!=PositionGetDouble(POSITION_SL))
        {
         PositionModify(_Symbol,PositionGetDouble(POSITION_PRICE_OPEN),PositionGetDouble(POSITION_TP));
         Print("SellModify");

        }

     }

  }

 

 where PositionModify is: 

 

bool PositionModify(const string symbol,const double sl,const double tp)
  {

   MqlTradeRequest m_request = {0};
   MqlTradeResult result;

//--- setting request
   
   m_request.action=TRADE_ACTION_SLTP;
   m_request.symbol=symbol;
   m_request.sl    = sl;
   m_request.tp    = tp;
//--- action and return the result
   return(OrderSendAsync(m_request,result));
  }

 

 as result it get follwowing message ( i separated 1 single order)

 

2014.12.20 19:05:02 Core 3 2014.12.15 11:12:42   order performed buy 0.66 at 1.56844 [#8 buy 0.66 GBPUSD at 1.56844]

2014.12.20 19:05:02 Core 3 2014.12.15 11:12:42   deal performed [#5 buy 0.66 GBPUSD at 1.56844]

2014.12.20 19:05:02 Core 3 2014.12.15 11:12:42   deal #5 buy 0.66 GBPUSD at 1.56844 done (based on order #8)

2014.12.20 19:05:02 Core 3 2014.12.15 11:12:42   stop loss triggered sell 0.66 GBPUSD 1.56844 sl: 1.56844 [#8 buy 0.66 GBPUSD at 1.56844]

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:30   SellModify Bid: 1.56544 BreakEven*Point: 0.002 Bid + BE*Point: 1.56744

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:30   position modified [sell 0.66 GBPUSD 1.56844 sl: 1.56844]

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:29   SellModify Bid: 1.56544 BreakEven*Point: 0.002 Bid + BE*Point: 1.56744


2014.12.20 19:05:02 Core 3 2014.12.15 11:11:29   failed modify sell 0.66 GBPUSD sl: 1.57044, tp: 0.00000 -> sl: 1.56844, tp: 0.00000 [Invalid stops]

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:29   SellModify Bid: 1.56544 BreakEven*Point: 0.002 Bid + BE*Point: 1.56744


2014.12.20 19:05:02 Core 3 2014.12.15 11:11:29   failed modify sell 0.66 GBPUSD sl: 1.57044, tp: 0.00000 -> sl: 1.56844, tp: 0.00000 [Invalid stops]

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:29   SellModify Bid: 1.56544 BreakEven*Point: 0.002 Bid + BE*Point: 1.56744


2014.12.20 19:05:02 Core 3 2014.12.15 11:11:29   failed modify sell 0.66 GBPUSD sl: 1.57044, tp: 0.00000 -> sl: 1.56844, tp: 0.00000 [Invalid stops]

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:28   SellModify Bid: 1.56544 BreakEven*Point: 0.002 Bid + BE*Point: 1.56744


2014.12.20 19:05:02 Core 3 2014.12.15 11:11:28   failed modify sell 0.66 GBPUSD sl: 1.57044, tp: 0.00000 -> sl: 1.56844, tp: 0.00000 [Invalid stops]

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:28   SellModify Bid: 1.56544 BreakEven*Point: 0.002 Bid + BE*Point: 1.56744


2014.12.20 19:05:02 Core 3 2014.12.15 11:11:28   failed modify sell 0.66 GBPUSD sl: 1.57044, tp: 0.00000 -> sl: 1.56844, tp: 0.00000 [Invalid stops]

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:28   SellModify Bid: 1.56544 BreakEven*Point: 0.002 Bid + BE*Point: 1.56744


2014.12.20 19:05:02 Core 3 2014.12.15 11:11:28   failed modify sell 0.66 GBPUSD sl: 1.57044, tp: 0.00000 -> sl: 1.56844, tp: 0.00000 [Invalid stops]

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:27   SellModify Bid: 1.56544 BreakEven*Point: 0.002 Bid + BE*Point: 1.56744


2014.12.20 19:05:02 Core 3 2014.12.15 11:11:27   failed modify sell 0.66 GBPUSD sl: 1.57044, tp: 0.00000 -> sl: 1.56844, tp: 0.00000 [Invalid stops]

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:27   SellModify Bid: 1.56544 BreakEven*Point: 0.002 Bid + BE*Point: 1.56744


2014.12.20 19:05:02 Core 3 2014.12.15 11:11:27   failed modify sell 0.66 GBPUSD sl: 1.57044, tp: 0.00000 -> sl: 1.56844, tp: 0.00000 [Invalid stops]

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:27   order performed sell 0.66 at 1.56844 [#7 sell stop 0.66 GBPUSD at 1.56844]

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:27   deal performed [#4 sell 0.66 GBPUSD at 1.56844]

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:27   deal #4 sell 0.66 GBPUSD at 1.56844 done (based on order #7)

2014.12.20 19:05:02 Core 3 2014.12.15 11:11:27   order [#7 sell stop 0.66 GBPUSD at 1.56844] triggered

2014.12.20 19:05:02 Core 3 2014.12.15 01:00:00   sell stop 0.66 GBPUSD at 1.56844 sl: 1.57044 (1.57228 / 1.57247 / 1.57228)

 

interresting is, that it works few tick later

is this normal?

 

amando 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Deal Properties - Reference on algorithmic/automated trading language for MetaTrader 5
To add comments, please log in or register