Download MetaTrader 5
To add comments, please log in or register
Do you want to order an application? Find out how to obtain the desired result
Tiago Cetto Pietralonga
436
Tiago Cetto Pietralonga 2016.08.11 21:48 

How select last order for one symbol in the history and get value of lots and profit?

 

Thank you 

Vladimir Karputov
Moderator
33515
Vladimir Karputov 2016.08.11 22:10  
Tiago Cetto Pietralonga:

How select last order for one symbol in the history and get value of lots and profit?

 

Thank you 

Order? Deal or Position?
Marco vd Heijden
Moderator
4073
Marco vd Heijden 2016.08.11 22:14  
Tiago Cetto Pietralonga:

How select last order for one symbol in the history and get value of lots and profit?

 

Thank you 

https://www.mql5.com/en/docs/trading/historyordergetinteger

https://www.mql5.com/en/docs/constants/tradingconstants/orderproperties

https://www.mql5.com/en/docs/constants/tradingconstants/positionproperties

https://www.mql5.com/en/docs/trading/historyordergetdouble

ENUM_ORDER_PROPERTY_DOUBLE

Identifier

Description

Type

ORDER_VOLUME_INITIAL

Order initial volume

double

ORDER_VOLUME_CURRENT

Order current volume

double

ORDER_PRICE_OPEN

Price specified in the order

double

ORDER_SL

Stop Loss value

double

ORDER_TP

Take Profit value

double

ORDER_PRICE_CURRENT

The current price of the order symbol

double

ORDER_PRICE_STOPLIMIT

The Limit order price for the StopLimit order

double

Documentation on MQL5: Trade Functions / HistoryOrderGetInteger
Documentation on MQL5: Trade Functions / HistoryOrderGetInteger
  • www.mql5.com
Trade Functions / HistoryOrderGetInteger - Reference on algorithmic/automated trading language for MetaTrader 5
Vladimir Karputov
Moderator
33515
Vladimir Karputov 2016.08.11 22:17  

For example, a hedge account in MetaTrader 5:

Deals, orders 


As you can see, if the order is "IN" - it has not arrived.
Marco vd Heijden
Moderator
4073
Marco vd Heijden 2016.08.11 22:22  
Tiago Cetto Pietralonga:

How select last order for one symbol in the history and get value of lots and profit?

 

Thank you 

Please specify which is your target language as i see most of your previous questions were MQL4.

In that case its

OrdersHistoryTotal()


https://docs.mql4.com/trading/ordershistorytotal

OrdersHistoryTotal - Trade Functions - MQL4 Reference
OrdersHistoryTotal - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrdersHistoryTotal - Trade Functions - MQL4 Reference
Tiago Cetto Pietralonga
436
Tiago Cetto Pietralonga 2016.08.11 23:08  
Karputov Vladimir:
Order? Deal or Position?
last position closed, look imagem... exemple
Files:
IMAGEM.png 122 kb
Tiago Cetto Pietralonga
436
Tiago Cetto Pietralonga 2016.08.12 19:40  

I did. It's working 

void OnStart()
  {
  
datetime dia=TimeCurrent();  
MqlDateTime diamqldate; 
TimeToStruct(dia,diamqldate);
datetime auxhora;
MqlDateTime auxhoramqldate;
double auxprofit,lot; 

diamqldate.mon=diamqldate.mon-1;
   if(diamqldate.mon==0){
      diamqldate.mon=12;
      diamqldate.year=diamqldate.year-1;
   }
   
diamqldate.hour=-1;
diamqldate.min=-1;
diamqldate.sec=-1; 
  
for(int i=OrdersHistoryTotal();i>=0;i--){ 
   if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)){
      if(OrderType()==OP_SELL || OrderType()==OP_BUY){
         if(OrderSymbol()==Symbol()){
            auxhora=OrderCloseTime();
            TimeToStruct(auxhora,auxhoramqldate);         
            if(auxhoramqldate.year > diamqldate.year || auxhoramqldate.year==diamqldate.year  ){
               if(auxhoramqldate.mon > diamqldate.mon || auxhoramqldate.mon == diamqldate.mon){
                  if(auxhoramqldate.day > diamqldate.day || auxhoramqldate.day== diamqldate.day){
                     if(auxhoramqldate.hour > diamqldate.hour || auxhoramqldate.hour==diamqldate.hour){
                        if(auxhoramqldate.min > diamqldate.min || auxhoramqldate.min == diamqldate.min){
                           if(auxhoramqldate.sec > diamqldate.sec || auxhoramqldate.sec ==diamqldate.sec){
                              auxprofit=OrderProfit();
                              lot=OrderLots();
                              diamqldate.year=auxhoramqldate.year;
                              diamqldate.mon=auxhoramqldate.mon;
                              diamqldate.day= auxhoramqldate.day;
                              diamqldate.hour=auxhoramqldate.hour;
                              diamqldate.min=auxhoramqldate.min;
                              diamqldate.sec=auxhoramqldate.sec;
                           }
                        }
                     }
                  }
               }
            }
         }
      }              
   }
}

Alert("profit",auxprofit); //TEST
Alert("lot",lot); //TEST     

Marco vd Heijden
Moderator
4073
Marco vd Heijden 2016.08.12 19:54  
Tiago Cetto Pietralonga:

I did. It's working 


Well done
/
To add comments, please log in or register