Hi,
I was able to write a code to open a position when a condition is met (e.g. Sell if MA1 is smaller than MA2)... The problem I have is that when the the condition is when the condition is the other way around (i.e. MA1 is greater than MA2)... I want the EA to close the orginally opened Sell position and open the Buy...
Is there a function to close any open positoin after a condition is met and before executing the intended order?
Find the originally opened position, select it using OrderSelect() then close it using OrderClose() and OrderClosePrice() . . . then open your new position.
Hi,
Many thanks for your response... I have tried to play around with the functions you provided but was not able to get it to work.... I am not a coder and I am trying to find my way around using some of the MQ4 codes available on forums... Would you be kind to add the necessary line(s) into the code below..
if iMA(Symbol(),0,30,8,SMMA,PRICE_CLOSE,0) < iMA(Symbol(),0,100,8,SMMA,PRICE_CLOSE,0)
{
ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,50,0,0,"Sell",18234,0);
}
What I need is to perform the close function before giving value to "ticket"
Many thanks for your help...
Cheers,
IK
Hi,
Many thanks for your response... I have tried to play around with the functions you provided but was not able to get it to work.... I am not a coder and I am trying to find my way around using some of the MQ4 codes available on forums... Would you be kind to add the necessary line(s) into the code below..
No. You need to learn . . . .
Well... I wouldn't come here if I didn't want to learn... I knew about the OrderSelect() and OrderClose() but the issue is that it is not working as it should be and no error message was given... Which suggest a logical error... I've been struggling with this since yesterday hence I asked for help...
This is the code I used which is not functioning properly (does not close and reverse) and I don't know what I've got wrong...
if iMA(Symbol(),0,30,8,SMMA,PRICE_CLOSE,0) < iMA(Symbol(),0,100,8,SMMA,PRICE_CLOSE,0)
{
if(OrderSelect(OrderTicket(), SELECT_BY_TICKET)==true)
{
OrderClose(OrderTicket(),TheLots,Ask,10,Red);
}
else
Print("OrderSelect failed error code is",GetLastError());
ticket = OrderSend(Symbol(),OP_SELL,0.1,Bid,50,0,0,"Sell",18234,0);
}
Thanks...
Since there are no slaves here, there are only two choices: learn to code or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt and the nature of your problem.
I've asked with all kindness for help... and I did provide my modest attempt...
Well... I wouldn't come here if I didn't want to learn... I knew about the OrderSelect() and OrderClose() but the issue is that it is not working as it should be and no error message was given... Which suggest a logical error... I've been struggling with this since yesterday hence I asked for help...
This is the code I used which is not functioning properly (does not close and reverse) and I don't know what I've got wrong...
<SNIP>
Please use this to post code . . . it makes it easier to read.
Please read the documentation for the Functions you are trying to use . . . before you can use OrderTicket() . . . "Note: The order must be previously selected by the OrderSelect() function." you can't select the order using OrderTicket()
It is also a good idea to check return values from functions and report errors when the return value suggests that something has gone wrong: What are Function return values ? How do I use them ?
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I was able to write a code to open a position when a condition is met (e.g. Sell if MA1 is smaller than MA2)... The problem I have is that when the the condition is when the condition is the other way around (i.e. MA1 is greater than MA2)... I want the EA to close the orginally opened Sell position and open the Buy...
Is there a function to close any open positoin after a condition is met and before executing the intended order?
Appreciate your help...
Regards,
IK