Minime,
I created the following piece of code to get the total profit of all orders with the same magic number:
PHP Code:
double OPBM(int intMagic)//OrderProfitByMagic
{
double dblProfit=0;
int intPOS=0;
bool boolTerm=false;
while(boolTerm==false)
{
if(OrderSelect(intPOS,SELECT_BY_POS))
{
if(OrderMagicNumber()==intMagic) dblProfit=dblProfit+OrderProfit();
intPOS++;
}
else
boolTerm=true;
}
return(dblProfit);
}
All you have to do is copy the above code and paste it in your EA, I usually put it at the bottom, after the
You will also want to use a Close By Magic function:
PHP Code:
int CBM(int intMagic)//CloseByMagic
{
int intOffset=0;
int Count = OTBM(intMagic);
while(OTBM(intMagic)>0 && Count > 0)
{
OrderSelect(intOffset,SELECT_BY_POS);
if(OrderMagicNumber()==intMagic)
{
if(OrderType()==OP_BUY) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);
else if(OrderType()==OP_SELL) OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),999,Orange);
Count--;
}
else {
intOffset++;
}
}
return(0);
}
Also include this Orders Total By Magic Function:
PHP Code:
int OTBM(int intMagic)//OrdersTotalByMagic
{
int intCount=0;
int intPOS=0;
bool boolTerm=false;
while(boolTerm==false)
{
if(OrderSelect(intPOS,SELECT_BY_POS))
{
if(OrderMagicNumber()==intMagic) intCount++;
intPOS++;
}
else
boolTerm=true;
}
return(intCount);
}
Then all you need to code is:
PHP Code:
if (OPBM(Your_Magic_Number) >= Your_Profit_Target)
{
CBM(Your_Magic_Number);
}
Hope this helps.
