...
extern int Close_Profit_for2orders = 40;
extern double koef_close_profit = 1.4;
...
int start() {
...
//закрытие всех ордеров при общем профите
double prof;
for(int it=0; it<=OrdersTotal(); it++)
{
if(OrderSelect(it,SELECT_BY_POS)==true)
{
if(OrderMagicNumber()==MAGIC)
{
if (OrderType()==OP_BUY) prof+=(MarketInfo(OrderSymbol(),MODE_BID) - OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT);
if (OrderType()==OP_SELL) prof+=(OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK)) /MarketInfo(OrderSymbol(),MODE_POINT);
}
}
}
if(MarketInfo(Symbol(), MODE_DIGITS) == 3 || MarketInfo(Symbol(), MODE_DIGITS) == 5) prof/=10;
bool Cl_Pr = false;
if(prof>=Close_profit())
Cl_Pr = true;
...
}
//польщовательские функции
...
///////////////////////////////////////////////////////////
int All_countOpenPosition(int MAGIC)
{
All = 0;
for (int q=-1; q<OrdersTotal()+1; q++)
{
if (OrderSelect(q,SELECT_BY_POS,MODE_TRADES)==true)
{
if(OrderMagicNumber()!=MAGIC)continue;
{
All++;
}
}
}
return(All);
}
...
//////////////////////////////////////////////////////////////////
int Close_profit()
{
int TotalOrders = All_countOpenPosition(MAGIC);
int Close_Profit = Close_Profit_for2orders;
if(TotalOrders==1) Close_Profit=TP;
if(TotalOrders==2) Close_Profit=Close_Profit_for2orders;
if(TotalOrders==3) Close_Profit*=koef_close_profit;
if(TotalOrders==4) Close_Profit*=koef_close_profit*2;
if(TotalOrders==5) Close_Profit*=koef_close_profit*3;
if(TotalOrders==6) Close_Profit*=koef_close_profit*4;
return(Close_Profit);
}