How can I get last second trade in history is profitable or not?

 

Hi everyone,

I try to obtain last second trade in history is profitable or not. I can get last trade in history is profitable or not as follows;


if (OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY )
  {
   if (OrderProfit()>0)
    { 
      success=1;
    }
   else
    {
      success=0;
    }

I need to get last second trade in history is profitable or not. How can I do that?

Best.

 

if(OrderOpenTime()>...

or 

if(OrderCloseTime()>...

Depending on your needs.

Same idea as with profit but with time.

 
Marco vd Heijden:
if(OrderOpenTime()>...

Hi Marco,

I hope you are well. Can you give me more detail, please? How can I use OrderOpenTime?

 
Murat Yazici: I try to obtain last second trade in history is profitable or not. I can get last trade in history is profitable or not as follows;
if (OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY )
  1. No you can not. Do not assume history has only closed orders.
    Do not assume history is ordered by date, it's not.
              Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum

  2. Using OrdersTotal OrdersHistoryTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
              Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
              MagicNumber: "Magic" Identifier of the Order - MQL4 Articles

  3. Why did you post your MT4 question in the Root / MT5 General section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

 
William Roeder:

No you can not. Do not assume history has only closed orders.
Do not assume history is ordered by date, it's not.
          Could EA Really Live By Order_History Alone? (ubzen) - MQL4 programming forum

Hi William,

if History is empty, I do another things. Thank you. But, I could not select last second trade if history has closed orders.

 

Hi again Marco,

I can obtain last second order'S closetime with following code. What should be next step to get prafitable or not?

datetime orderclosetime[];
int orderstotal=OrdersHistoryTotal();
ArrayResize(orderclosetime,orderstotal,0);

for(int i=0;i<orderstotal;i++)
  {
   if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
     {
      orderclosetime[i]=OrderCloseTime();
     }
  }

int index;
index=ArrayMaximum(orderclosetime, WHOLE_ARRAY,0);
orderclosetime[index]=0;
index=ArrayMaximum(orderclosetime, WHOLE_ARRAY,0);
Reason: