How to select last profit order for chart?

 

This is the last step to getting my system going. Really need this solved.


   for(int i=OrdersHistoryTotal();i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderProfit()>0)
              {
               Alert(OrderTicket());
              }
           }
        }
     }
  }


Does not work at all.

Need to select last profit order of the account history tab for current chart symbol. Its eluding me. Thanks in advanced.

How to do this?? Heres the EA attached for quick reference. It just selects like a zillion apparently and it locks the thing up..  HELP

 

I use the following code with no issues ...

void LastClosedTrade(){ 
   int cnt, total; 
   total = OrdersHistoryTotal(); 
   for(cnt=0;cnt<total; cnt++){ 
      if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)==true)
   
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC){
         LastOrderType = OrderType(); 
         LastOrderLots = OrderLots(); 
         LastOrderProfit = OrderProfit(); 
      }
   }
}
 
Osama Shaban: I use the following code with no issues ...
  1. No issues that you have yet seen.
  2. You assume history is ordered by date, it's not. Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum
 
Osama Shaban:

I use the following code with no issues ...

Thanks! I've tried using your code, however it doesn't work. Check out the EA I've attached. How to get it working?


I have a full account history with 1000s of orders. I just need the last order that returned in profit for current instrument.

Files:
sample.mq4  3 kb
 

Ive got it working, nm!


Thx all

 
nadiawicket:

Ive got it working, nm!


Thx all


Please post your solution!

Reason: