//-------------------------------------------------------------------+
// Close at profit Function |
//-------------------------------------------------------------------+
void CloseatProfit( string Symb )
{
total = OrdersTotal();
int ticket = 0;
if(OrdersTotal() < 1) return;
for( int cnt = total-1; cnt >= 0; cnt-- )
{
if ( OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES ))
{
if ( OrderSymbol() == Symb && OrderProfit() > 1 )
{
if ( OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 10, clrNONE ) ) Print("Close order success");
else Print( "Close order failed");
}
}
}
}
// Close at profit Function |
//-------------------------------------------------------------------+
void CloseatProfit( string Symb )
{
total = OrdersTotal();
int ticket = 0;
if(OrdersTotal() < 1) return;
for( int cnt = total-1; cnt >= 0; cnt-- )
{
if ( OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES ))
{
if ( OrderSymbol() == Symb && OrderProfit() > 1 )
{
if ( OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 10, clrNONE ) ) Print("Close order success");
else Print( "Close order failed");
}
}
}
}
tuoitrecuoi:
Thank you. Will try and test it...
//-------------------------------------------------------------------+
// Close at profit Function |
//-------------------------------------------------------------------+
void CloseatProfit( string Symb )
{
total = OrdersTotal();
int ticket = 0;
if(OrdersTotal() < 1) return;
for( int cnt = total-1; cnt >= 0; cnt-- )
{
if ( OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES ))
{
if ( OrderSymbol() == Symb && OrderProfit() > 1 )
{
if ( OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 10, clrNONE ) ) Print("Close order success");
else Print( "Close order failed");
}
}
}
}
// Close at profit Function |
//-------------------------------------------------------------------+
void CloseatProfit( string Symb )
{
total = OrdersTotal();
int ticket = 0;
if(OrdersTotal() < 1) return;
for( int cnt = total-1; cnt >= 0; cnt-- )
{
if ( OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES ))
{
if ( OrderSymbol() == Symb && OrderProfit() > 1 )
{
if ( OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 10, clrNONE ) ) Print("Close order success");
else Print( "Close order failed");
}
}
}
}
I hope you don't mind my last inquiry,
during the course of accumulation ( positions of more than 5 ),
it closes positions or tickets with negative result ( p/l ) when the
expression or conditions is supposed to be OrderProfit > 1 only.
Just like closing the whole positions with symb specific...
Thanks.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Please help, with this code platform becomes unresponsive for 100% cpu usage
Function is supposed to close one position at a time per ticket when reaching total position and profit,
Please note that this came from a loop of buying and selling and there are positions always left open with
positive and negative result - p/l.
Thanks.
This one doesn't work either
//-------------------------------------------------------------------+
// Close at profit Function |
//-------------------------------------------------------------------+
void CloseatProfit( string Symb )
{
total = OrdersTotal();
int ticket = 0;
if(OrdersTotal() <= 10) return;
for( int cnt = total-1; cnt >= 9; cnt-- )
{
if ( OrderSelect( cnt, SELECT_BY_POS, MODE_TRADES ))
{
if ( OrderSymbol() == Symb && OrderProfit() > 1 )
{
if ( OrderClose( OrderTicket(), OrderLots(), OrderClosePrice(), 10, clrNONE ) ) Print("Close order success");
else Print( "Close order failed");
}
}
}
}