Close All Open Ordes

 

i want to close all orders (buy orders or Sell Orders). But my script is error code 4109 please Help me

#property copyright "Copyright © 2008, Uluturk Yazılım A.S."
#property link "http://www.Uluturk.Com.Tr"
#property show_confirm
#include <stdlib.mqh>

int start()
{
int totalOrders=OrdersTotal();
if (totalOrders <=0)
MessageBox("Açık Pozisyonunuz YokTur");
Print("Kapatılacak Pozisyon Sayısı",totalOrders);

for (int k = 0;k < totalOrders;k++)
{
RefreshRates();
Print(k);
OrderSelect(k,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY)
{if (!OrderClose(OrderTicket(),OrderLots(),Bid,5))
MessageBox(DoubleToStr(GetLastError(),9));
}

RefreshRates();
if (OrderType()==OP_SELL)
{if (!OrderClose(OrderTicket(),OrderLots(),Ask,5))
MessageBox(DoubleToStr(GetLastError(),9));
}

}

return(0);
}

 
kuluturk25:

i want to close all orders (buy orders or Sell Orders). But my script is error code 4109 please Help me

#property copyright "Copyright © 2008, Uluturk Yazılım A.S."
#property link "http://www.Uluturk.Com.Tr"
#property show_confirm
#include <stdlib.mqh>

int start()
{
int totalOrders=OrdersTotal();
if (totalOrders <=0)
MessageBox("Açık Pozisyonunuz YokTur");
Print("Kapatılacak Pozisyon Sayısı",totalOrders);

for (int k = 0;k < totalOrders;k++)
{
RefreshRates();
Print(k);
OrderSelect(k,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY)
{if (!OrderClose(OrderTicket(),OrderLots(),Bid,5))
MessageBox(DoubleToStr(GetLastError(),9));
}

RefreshRates();
if (OrderType()==OP_SELL)
{if (!OrderClose(OrderTicket(),OrderLots(),Ask,5))
MessageBox(DoubleToStr(GetLastError(),9));
}

}

return(0);
}

 

Error document...


ERR_TRADE_NOT_ALLOWED 4109 Trade is not allowed. Enable checkbox "Allow live trading" in the expert properties
 
phy:

Error document...


ERR_TRADE_NOT_ALLOWED 4109 Trade is not allowed. Enable checkbox "Allow live trading" in the expert properties


Thank You. but i have a few orders. But my script is closed one. Please help me ?

 

when closing orders,

for (int k = 0;k < totalOrders;k++)


should be changed to:


for(int k = OrdersTotal()-1; k >= 0; k--)

 
phy:

when closing orders,

for (int k = 0;k < totalOrders;k++)


should be changed to:


for(int k = OrdersTotal()-1; k >= 0; k--)



2008.03.25 07:05:10 TumunuKapat EURUSD,M1: invalid price 1.55550000 for OrderClose function
 
Invalid price is unrelated to the direction of the loop counter.
 
phy:
Invalid price is unrelated to the direction of the loop counter.

How do close All Orders pratice code ?.