Download MetaTrader 5

Doubt on OnTrade()

To add comments, please log in or register
Gopalakrishna R
416
Gopalakrishna R  
int one = 0;
int Magic = 1;
void OnTick()
{
   if(one == 0)
   if(Buy_Call(0.01, 1, "First_Buying_")) 
   Print("Bought");
}

void OnTrade()
  {
   one =1;
   Print("One Time");
  }

bool Buy_Call(double tp, double lot, string cmt)
{        
         MqlTick last_tick;
         SymbolInfoTick(_Symbol,last_tick);
         double Ask = last_tick.ask;
         MqlTradeRequest request={0};
         MqlTradeResult result;
         request.symbol = _Symbol;
         request.action = TRADE_ACTION_DEAL;
         request.price = NormalizeDouble(Ask,4);
         request.tp = NormalizeDouble(Ask+tp,4);
         request.volume = lot;
         request.deviation = 3;
         request.type = ORDER_TYPE_BUY;
         request.type_filling = ORDER_FILLING_IOC;
         if(OrderSend(request, result)) Print("OrderSent");
         return(true);
}

Using above code I'm placing only one order and I expected only two times (one for placing order and another for TP) the OnTrade() function will be executed. But its been executed for 5 times.  

Can anyone tell me why it happens?

Output from tester:

2013.07.09 21:19:43 2013.01.14 00:56:40   One Time

2013.07.09 21:19:43 2013.01.14 00:56:40   One Time

2013.07.09 21:19:43 2013.01.14 00:56:40   order performed sell 1.00 at 1.33680 [#3 sell 1.00 EURUSD at 1.33680]

2013.07.09 21:19:43 2013.01.14 00:56:40   deal performed [#3 sell 1.00 EURUSD at 1.33680]

2013.07.09 21:19:43 2013.01.14 00:56:40   deal #3 sell 1.00 EURUSD at 1.33680 done (based on order #3)

2013.07.09 21:19:43 2013.01.14 00:56:40   take profit triggered buy 1.00 EURUSD 1.32683 tp: 1.33680 [#3 sell 1.00 EURUSD at 1.33680]

2013.07.09 21:19:42 2013.01.02 04:07:00   One Time

2013.07.09 21:19:42 2013.01.02 04:07:00   One Time

2013.07.09 21:19:42 2013.01.02 04:07:00   One Time

2013.07.09 21:19:42 2013.01.02 04:07:00   OrderSent

 

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 - Documentation on MQL5
Alain Verleyen
Moderator
31473
Alain Verleyen  
krishna_gopal_2:

Using above code I'm placing only one order and I expected only two times (one for placing order and another for TP) the OnTrade() function will be executed. But its been executed for 5 times.  

Can anyone tell me why it happens?

...

You have to read the documentation about OnTradeTransaction.
Gopalakrishna R
416
Gopalakrishna R  
angevoyageur:
You have to read the documentation about OnTradeTransaction.
Can you please answer my question in How to Get Order details from Deal ?
Alain Verleyen
Moderator
31473
Alain Verleyen  
krishna_gopal_2:
Can you please answer my question in How to Get Order details from Deal ?
The answer is the same as above, you have to use OnTradeTransaction. Search the forum with this keyword for example. If you have difficulties to use it, show your code to receive help.
To add comments, please log in or register