View Single Post
  #10 (permalink)  
Old 03-30-2008, 08:50 PM
wolfe's Avatar
wolfe wolfe is offline
Senior Member
 
Join Date: Jan 2006
Posts: 702
wolfe is on a distinguished road
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()==intMagicdblProfit=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
PHP Code:
return(0);
  } 
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)>&& Count 0)
{
OrderSelect(intOffset,SELECT_BY_POS);
if(
OrderMagicNumber()==intMagic)
{
if(
OrderType()==OP_BUYOrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),999,Red);
else if(
OrderType()==OP_SELLOrderClose(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()==intMagicintCount++;
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.
Reply With Quote