Ask! - page 38

 

Ian,

Check Straddle&Trail expert. you can find it here https://www.mql5.com/en/forum/general

 

Hello all,

I want to close all my orders at the same time but i coudn't.

I tried this code but it didn't work :

''''''''''''''''''''''''''''''''''''''''

total = OrdersTotal();

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

{

if(OrderSelect(i, SELECT_BY_POS)==true)

{

OrderClose(OrderTicket(),OrderLots(),Ask,80,CLR_NONE);

OrderClose(OrderTicket(),OrderLots(),Bid,80,CLR_NONE);

}

}

''''''''''''''''''''''''''''''''''''''''

Can anybody help me ?

I would be very grateful if you can help me

 

Mehdi,

Put this code (procedure) outside start() section and when you if the condition is met to close all trades, just call the procedure like that:

int start()

{ // your code here .....

If (your condition here) ShutDownAllTrades();

}

void ShutDownAllTrades

{ int Retry;

While (OrdersTotal()>0)

{ for (int cnt=OrdersTotal()-1;cnt>=0;cnt--)

{ OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderType()==OP_BUY)

{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }

RefreshRates();

OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Yellow);

Sleep(1000);

}

else if (OrderType()==OP_SELL)

{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }

RefreshRates();

OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Yellow);

Sleep(1000);

}

else

{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }

OrderDelete(OrderTicket());

Sleep(1000);

}

}

}

}

HTH

Yannis

 

Dear Yannis,

Thanks for your help.

I wish you the best.

 
Yannis:
Mehdi,

Put this code (procedure) outside start() section and when you if the condition is met to close all trades, just call the procedure like that:

int start()

{ // your code here .....

If (your condition here) ShutDownAllTrades();

}

void ShutDownAllTrades

{ int Retry;

While (OrdersTotal()>0)

{ for (int cnt=OrdersTotal()-1;cnt>=0;cnt--)

{ OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

if (OrderType()==OP_BUY)

{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }

RefreshRates();

OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Yellow);

Sleep(1000);

}

else if (OrderType()==OP_SELL)

{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }

RefreshRates();

OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,Yellow);

Sleep(1000);

}

else

{ Retry=0; while (Retry<5 && !IsTradeAllowed()) { Retry++; Sleep(1000); }

OrderDelete(OrderTicket());

Sleep(1000);

}

}

}

}

HTH

Yannis

Dear Yannis,

I added your procedure between " int deinit() { } " (out of start) as you said but there is a problem via compiling after void ShutDownAllTrades { : '{' comma or semicolon expected .

I look forward to hearing from you.

Thanks a lot

 

Oops sorry.

What's missing is the () after void ShutDownAllTrades()

Be careful also for the variable named 'Slippage' in the orderclose function.

You might need to replace that with the one you are using when you place your orders.

Yannis

 
Yannis:
Oops sorry.

What's missing is the () after void ShutDownAllTrades()

Be careful also for the variable named 'Slippage' in the orderclose function.

You might need to replace that with the one you are using when you place your orders.

Yannis

It's working very well !

Thanks again

 

I am using MTF CCI indicator ftom Multi Time Frame indicators thread, it is a yellow step line, see image attached.

When the line is above 100 level (overbought)- the price will go down and when its below -100 (oversold) - the price will go up.

The only problem with it that it doesnt always refresh, i have to do it manually by right clicking on the chart and selecting 'Refresh'.

A question to programmers: Is there any function in MQ4 to do that kind of refresh automatically on every tick?

Would appreciate an advice.

euro pean

Files:
mtf_cci.jpg  37 kb
 

Try this:

void ObjectsRedraw()

Redraws all objects on the chart

Sample

ObjectsRedraw();

You may need to use ObjectCreate first.

 
richx7:
Try this:

void ObjectsRedraw()

Redraws all objects on the chart

Sample

ObjectsRedraw();

You may need to use ObjectCreate first.

Thanks for replying.

As far as I know ObjectsRedraw() refreshes objects that just been 'created' and 'set'.

I need to refresh an indicator which is not on the Object list, so ObjectsRedraw() doesnt work.

Or may be you know how to refer to an existing indicator?

Reason: