Tradeprofit

 
Does anyone have code that searches open orders(by magicnumber or another parameter) and then assesses that trade's profit? I have an EA that closes orders based on Accountprofit but want to be able to single out individual orders also. Any help would be greatly appreciated! Daniel
 

int i, N ; N = OrdersTotal ();
for ( i = 0 ; i < N ; i ++ )
{ OrderSelect ( i, SELECT_BY_POS, MODE_TRADES )

if (OrderMagicNo()==MagicNo)

{

if (OrderProfit() > what u want to do)

do something

}

}

 
ronaldosim:

int i, N ; N = OrdersTotal ();
for ( i = 0 ; i < N ; i ++ )
{ OrderSelect ( i, SELECT_BY_POS, MODE_TRADES )

if (OrderMagicNo()==MagicNo)

{

if (OrderProfit() > what u want to do)

do something

}

}

Thanks! That is real close to what I was looking for........how do I select the order that has that MagicNumber though? THAT would be perfectly what I need...thanks!!! Dan

 
forexman05 wrote >>

Thanks! That is real close to what I was looking for........how do I select the order that has that MagicNumber though? THAT would be perfectly what I need...thanks!!! Dan

extern int MagicNo = 333;

void start()

{

//say you have set a certain condition to fire your orders

if (TimeHour(TimeCurrent())==1 && TimeMinute(TimeCurrent())==0)
{
double x = NormalizeDouble((iHigh(Symbol(),PERIOD_H1,1)+iLow(Symbol(),PERIOD_H1,1))/2.0,Digits);
OrderSend(Symbol(),OP_BUYSTOP,Lots,x+Step*Point,3,x+(Step-SL)*Point,x+(Step+TP)*Point,"",MagicNo,0,Green);
OrderSend(Symbol(),OP_SELLSTOP,Lots,x-Step*Point,3,x+(-Step+SL)*Point,x-(Step+TP)*Point,"",MagicNo,0,Red);
}

//then you want to look for an order that has already been fired and chk its profit/loss

int i, N ; N = OrdersTotal ();
for ( i = 0 ; i < N ; i ++ )
{ OrderSelect ( i, SELECT_BY_POS, MODE_TRADES )

if (OrderMagicNo()==MagicNo

&& ( OrderType()==OP_BUY || OrderType()==OP_SELL)) // if order is a buy or sell order that has MagicNo=333

{

if (OrderProfit() > what u want to do)

do something

}

}

}

}

Reason: