Download MetaTrader 5

How to select last profit order for chart?

To add comments, please log in or register
nadiawicket
397
nadiawicket  

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

Osama Shaban
1576
Osama Shaban  

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(); 
      }
   }
}
whroeder1
15902
whroeder1  
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
nadiawicket
397
nadiawicket  
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
nadiawicket
397
nadiawicket  

Ive got it working, nm!


Thx all

nicholishen
887
nicholishen  
nadiawicket:

Ive got it working, nm!


Thx all


Please post your solution!

To add comments, please log in or register