i have been looking at tutorials and basic stuff just trying to figure out how to close a order
i created this program which should both open and close a buy position each tick
input double l=1;
void OnTick(void)
{
int p = OrderSend(Symbol(),OP_BUY,l,Ask,3,0,0,"buy",1,0,Green);
bool close = OrderClose(OrderTicket(),l,Bid,3,Red);
}
each tick a buy order is opened but they are not closed
i am aware this is a basic question but if you can clarify how i can edit the code so the orders are closed i would appreciate it
with the least amount of code
to simply answer: your variable p from the OrderSend will contain the ticket number IF the order was successful, so use p instead of OrderTicket() in the OrderClose function.
however, this is not a very good way of coding trading functions and you will likely end up with all sorts of issues in real use. There are plenty of code examples around that cover this topic have a look at them.
MT4 questions should be posted in the MT4 section of the forum (down the bottom - not clear I know)
regards
-
Why did you post your MT4
question in the Root / MT5 General
section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. - Please edit your (original) post and use the CODE
button (Alt-S)! (For large amounts of code, attach it.)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor -
int p = OrderSend(Symbol(),OP_BUY,l,Ask,3,0,0,"buy",1,0,Green); bool close = OrderClose(OrderTicket(),l,Bid,3,Red);
You can not use any Trade Functions unless you select an order first.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
i have been looking at tutorials and basic stuff just trying to figure out how to close a order
i created this program which should both open and close a buy position each tick
input double l=1;
void OnTick(void)
{
int p = OrderSend(Symbol(),OP_BUY,l,Ask,3,0,0,"buy",1,0,Green);
bool close = OrderClose(OrderTicket(),l,Bid,3,Red);
}
each tick a buy order is opened but they are not closed
i am aware this is a basic question but if you can clarify how i can edit the code so the orders are closed i would appreciate it
with the least amount of code