Alert: MT4 Terminal Duplicating Orders Sent by Experts - page 6

To add comments, please log in or register
Keith Watford
Moderator
13965
Keith Watford  

There is a difference between

bool Buy_Ticket = OrderSend(........)

and what you are doing

bool Buy_Ticket = Ordersend > 0;   //SIMPLIFIED CODE FOR EASIER READING

in the first if an order fails a value of -1 will be returned, but the bool will interpret this as TRUE

in the second, you are using the condition (Ordersend>0) to assign true or false to the boolean.

BigFisherman
85
BigFisherman  
GumRai:


There is a difference between

and what you are doing

in the first if an order fails a value of -1 will be returned, but the bool will interpret this as TRUE

in the second, you are using the condition (Ordersend>0) to assign true or false to the boolean.



Is that true? I'm not able to test it out on a demo account (Live trade) now but I did some quick verification on a backtest purposely disrupting OrderSend() with invalid stoploss = ask (Market price) for a long trade. Result is OrderSend() returns a "-1" as expected & my bool var Buy_Ticket returns false as well.


** EDIT **

Did you missed out my conditions "> 0" behind OrderSend()? My original code shows:

bool Buy_Ticket = OrderSend(........) > 0;
Keith Watford
Moderator
13965
Keith Watford  
BigFisherman:



Is that true? I'm not able to test it out on a demo account (Live trade) now but I did some quick verification on a backtest purposely disrupting OrderSend() with invalid stoploss = ask (Market price) for a long trade. Result is OrderSend() returns a "-1" as expected & my bool var Buy_Ticket returns false as well.


** EDIT **

Did you missed out my conditions "> 0" behind OrderSend()? My original code shows:


Sorry, yes, I did miss the >0.

I guess that it is just such a strange way to go about it, that I didn't notice it.

qjol
3195
qjol  

@ BigFisherman check the code below

   bool Buy_Ticket;
   int TicketNo = 123456789;
   Buy_Ticket = TicketNo > 0;
   Alert(Buy_Ticket);

see here

The assignment operator can be used several times in an expression . In this case the processing of the expression is performed from left to right:

y=x=3;

First, the variable x will be assigned the value 3, then the y variable will be assigned the value of x, i.e. also 3.

BigFisherman
85
BigFisherman  
GumRai:


Sorry, yes, I did miss the >0.

I guess that it is just such a strange way to go about it, that I didn't notice it.


No problem.

I agree it's not a good practice to code it that way; I've coded that part at the early stage of my MQL learning, but since it looked correct to me all this while, I let it be until this duplicate trade problem happens. But apparently, now it "seems like" my original code though confusing appears valid, then it goes back to the original topic of this thread "Duplicate trades.."; this might be a serious & highly unwelcome "rare" bug in mt4, which unfortunately I'm not able to reproduce due to it's rare appearance (1 in over 500+ trades).

For anyone's info, due to how I coded my EA (refer to my 1st post in pg5), SL & TP was only assigned after it detected successful OrderSend() (IMHO is rather foolproof until now). And what happened to my previous duplicate trade was it NEVER made it to set SL & TP for some unknown reason; other than OrderSend() returning "-1" but opened a trade anyway OR "it" opened 2 simultaneous trades in one OrderSend() ** just my own speculation **. Luckily I was right infront of my PC when that happens, so I could just manually close it out; imagine what would happen if I'm away on a holiday.

BigFisherman
85
BigFisherman  
qjol:

@ BigFisherman check the code below

   bool Buy_Ticket;
   int TicketNo = 123456789;
   Buy_Ticket = TicketNo > 0;
   Alert(Buy_Ticket);


Buy_Ticket returns true as expected. What are you trying to say?

qjol
3195
qjol  

i'm not trying to say, i'm saying!

if you use it like this

bool Buy_Ticket = OrderSend(........) > 0;

of course you gonna get true if OrderSend() has been executed

because first is examined whether the result of OrderSend is > 0

and then it's been passed to

Buy_Ticket

but still not the way to handle it right

BigFisherman
85
BigFisherman  
qjol:

i'm not trying to say, i'm saying!

if you use it like this

of course you gonna get true if OrderSend() has been executed

because first is examined whether the result of OrderSend is > 0

and then it's been passed to

but still not the way to handle it right



Now I know whose post to filter in mql4, thanks for your input anyway.
Syed Naufal Gaddafi
1856
Syed Naufal Gaddafi  
y=x=3;
I did try to do that one but MetaEditor always stops me whenever I try to compile.
qjol
3195
qjol  
BigFisherman:


Now I know whose post to filter in mql4,

note: my username in mql5 is the same
To add comments, please log in or register