problem w/ orderhistory()

 

i need to check if the last order closed in profit ...

if true an additional sell or buy should be closed ( 2 orders floating sell order -profit + buy order + profit) 2 different magicnumbers

but my code close also order with different magicnumber

int step2;
for(int wt=0; wt<OrdersHistoryTotal(); wt++)
{
if(OrderSelect(wt,SELECT_BY_POS,MODE_HISTORY))
{
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber2 && OrderProfit()<0) step2=-1; // loser
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber2 && OrderProfit()>0) step2=1; // winner
}
}       

.... / loop
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber && step2==1)
{
close part is working
}
 
fulltilt:
  1. i need to check if the last order closed in profit ...
    and you posted that code. What is your problem with that code?
  2. but my code close also order with different magicnumber
    Code that you didn't post. No mind readers here.
 
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber2 && OrderProfit()>0) step2=1; // winner



if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber??? && step2==1)
{
 

you are right, it is working!

sorroy ;-)