I need help please,
I am trying to close orders from different currency pairs ( long and short ) but with the same magic number when the profit reach define target " lets say 15 pips" without touching the other orders with different magic number
so I wrote this code to check open trades and count the profit on trades with magic number 111
PHP Code:
//+------------------------------------------------------------------+
//| check profitable positions with magic 111 |
//+------------------------------------------------------------------+
for(cnt=OrdersTotal();cnt>=0;cnt--)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if( OrderMagicNumber()==111 )
{
if(OrderType()==OP_BUY)
{
CurrentProfitB+=Bid-OrderOpenPrice() ;
}//if(OrderType()==OP_BUY)
if(OrderType()==OP_SELL)
{
CurrentProfitS+=OrderOpenPrice()-Ask;
}//if(OrderType()==OP_SELL)
} //if( OrderSymbol()==Symbol1 && OrderMagicNumber()==111 )
CurrentProfit=CurrentProfitB+CurrentProfitS;
}// for(cnt=OrdersTotal();cnt>=0;cnt--)
//======================
then I check if we make profit
PHP Code:
// Did we make a profit
//======================
if(profit>0 && CurrentProfit>=(profit*Point))
{
while(true)
{
CloseAllOrd(111);
}//while
}//if(profit>0 && CurrentProfit>=(profit*Point))
if we make a profit I call the function CloseAllOrd
PHP Code:
//+------------------------------------------------------------------+
//| Close all |
//+------------------------------------------------------------------+
void CloseAllOrd(int magic)
{
RefreshRates();
int total = OrdersTotal();
for (int cnt = 0 ; cnt < total ; cnt++)
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == magic)
if(IsTradeContextBusy()) Sleep(1000);
if(IsTradeContextBusy()) Sleep(2000);
if(OrderType()==OP_BUY)
OrderClose(OrderTicket(),OrderLots(),Bid,slippage,White);
if(OrderType()==OP_SELL)
OrderClose(OrderTicket(),OrderLots(),Ask,slippage,White);
}
}
however this will only close EURUSD after it reach 1 pip of profit sometimes 2
I need to close all orders( different currency pairs ) with magic number 111 at lets say 15 pips of profit , without touching other orders
can someone please help me