Need Help!

To add comments, please log in or register
antone
178
antone  

i need a code that would close only the buy position or the close position?

i have multiple trades on this..

if (OrderType()==OP_BUY)){

OrderClose ( OrderTicket (), OrderLots (), Ask, 3, Yellow); }

i use ticket before but it won't close? when i change the OrderTicker() to ticket but won't close anything..

what do i need to do or add a code?

kkb
6
kkb  

Looks like you are not selecting the order from the server. you need something like this will find all buy orders and close them

total = OrdersTotal();

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()== OP_BUY)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position

}

}

ralphronnquist
420
ralphronnquist  
kkb:
Looks like you are not selecting the order from the server. you need something like this will find all buy orders and close them

total = OrdersTotal();

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()== OP_BUY)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet); // close position

}

}

... so many times... Use the following loop instead:

for ( cnt = total-1; cnt >= 0; cnt--) {... }

Saves you a lot of headache.

antone
178
antone  

thanks guys.. i will try it..

how about if i also have sell? and my sell has a close signal while buy has not?

sorry still learning..

antone
178
antone  

if ihave sell is the code correct

total = OrdersTotal();

for(cnt=0;cnt<total;cnt++)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()== OP_BUY)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ; // close position

}

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if(OrderType()== OP_SELL)

{

OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

OrderClose(OrderTicket(),OrderLots(),Bid,3,Violet) ; // close position

}

}

}

i have tried this but it will only close a one trade.. how will it close all buy trade or sell trade?

antone
178
antone  

Need more help?

i also tried this to modify the orders SL and Tp.. but the problem is when it modify the SL all the buy order or sell order have the same SL and some don't produce any cause it is to close..

i want it to have different calculation in SL for each order.. can someone help me?

another thing? what is the code to limit the order for buy and limit order for sell?

antone
178
antone  

Also?

how to add, a code that would close all trades it if it reach a certain profit in equity or neg?

Sergey Golubev
Moderator
116862
Sergey Golubev  

Try to look at this thread https://www.mql5.com/en/forum/174329

May be it will help.

antone
178
antone  

i still can't find it.. if anyone can help me?

limit the order of sell or buy? LIKE only open 1 sell and 1 buy , total of 2 trades pair currency.. please help me?

also close all trades if the profit is reach a certain amount? and also close all trade if the profit is a lose at a certain amount..

antone
178
antone  

Anyone? or should i open a new thread?

Sergey Golubev
Moderator
116862
Sergey Golubev  
antone:
Anyone? or should i open a new thread?

Personally I can not help you as I am not a professional coder.

No need to open the other thread: your thread was visited by 117 people.

12
To add comments, please log in or register