Help closing order (programming)

 

Hi. I'm still trying to get the hang of the MT4 programming. My background is C++.

I open the order like this inside the EA.

OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Ask+500*Point,0,name,MagicNumber,0,Red);

Then I want to close that order and that order only.

So I use

OrderClose(MagicNumber,OrderLots(),Ask,Slippage,Red);

This doesn't work for me, though. What am I doing wrong? Thanks.

 
Morpheus:
Hi. I'm still trying to get the hang of the MT4 programming. My background is C++.

I open the order like this inside the EA.

OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Ask+500*Point,0,name,MagicNumber,0,Red);

Then I want to close that order and that order only.

So I use

OrderClose(MagicNumber,OrderLots(),Ask,Slippage,Red);

This doesn't work for me, though. What am I doing wrong? Thanks.

MagicNumber doesn't identify the order for OrderClose(), you must use the ticket number : OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);

 

My dilemma is what if I have the EA working on 7 different currencies. How does it know that orderticket is the right one?

 
Morpheus:
My dilemma is what if I have the EA working on 7 different currencies. How does it know that orderticket is the right one?

just use :

if (( OrderMagicNumber() == megic) && (OrderSymbol() == Curr))

to distinguish it from others

 
elihayun:
just use :

if (( OrderMagicNumber() == megic) && (OrderSymbol() == Curr))

to distinguish it from others

? What is "megic" and "curr" ? You mean test to see if they are the right ones? How exactly would I do that. I'm not very familiar with MT4.

 
Morpheus:
? What is "megic" and "curr" ? You mean test to see if they are the right ones? How exactly would I do that. I'm not very familiar with MT4.

magic is your magic number that u used when open the order. Curr is the currency that u want to check. you can use Symbol() instead

Reason: