{MQL4) How to know OrdersTotal() is decreased.

To add comments, please log in or register
Cromo
259
Cromo  

Hi,I want to know how to code the OrdersTotal() is changed(decreased).


For example, I have 5 orders now. OrdersTotal()=5.

If one order is closed (either TP or SL)  and OrdersTotal() is now 4 orders, The number of order was  decreased.

How can I know this?

Fernando Carreiro
4986
Fernando Carreiro  

kajironpu: Hi,I want to know how to code the OrdersTotal() is changed(decreased).For example, I have 5 orders now. OrdersTotal()=5. If one order is closed (either TP or SL)  and OrdersTotal() is now 4 orders, The number of order was  decreased. How can I know this?

By using Static Variables:

void OnTick()
{
   static int intOrdersTotalCurrent = OrdersTotal(); 
   int intOrdersTotalPrevious = intOrdersTotalCurrent;
   intOrdersTotalCurrent = OrdersTotal();

   if( intOrdersTotalCurrent > intOrdersTotalPrevious )
   {
      // Orders increased
   }

   if( intOrdersTotalCurrent < intOrdersTotalPrevious )
   {
      // Orders decreased
   }

   return;
}
Static Variables - Variables - Language Basics - MQL4 Reference
Static Variables - Variables - Language Basics - MQL4 Reference
  • docs.mql4.com
A static variable can be initialized by a constant or constant expression corresponding to its type, unlike a simple local variable, which can be initialized by any expression. Static variables exist from the moment of program execution and are initialized only once after the program is loaded. If the initial values are not specified, variables...
Cromo
259
Cromo  

Hi, Fernando san

Thank you so much.

This is what I was looking for. Static Variables

I need to strudy  Static Variables.

Gracious.

Static Variables - Variables - Language Basics - MQL4 Reference
Static Variables - Variables - Language Basics - MQL4 Reference
  • docs.mql4.com
A static variable can be initialized by a constant or constant expression corresponding to its type, unlike a simple local variable, which can be initialized by any expression. Static variables exist from the moment of program execution and are initialized only once after the program is loaded. If the initial values are not specified, variables...
Fernando Carreiro
4986
Fernando Carreiro  
kajironpu:

Hi, Fernando san

Thank you so much.

This is what I was looking for. Static Variables

I need to strudy  Static Variables.

Gracious.

You are welcome!

PS! When you used the word "Gracious", were you trying to say "Thank you" in my language?

If so, "Gracias" is Spanish. In Portuguese it would be "Obrigado", which sounds similar to the equivalent Japanese word "Arigatō" ("ありがとう")!

Cromo
259
Cromo  

Obrigado!!

Fernando Carreiro
4986
Fernando Carreiro  
kajironpu: Obrigado!!

How would I say the equivalent of "You are welcome!" in Japanese?

This is what I got from Google translate:

どういたしまして!

Fernando Carreiro
4986
Fernando Carreiro  
M.R.:

No, it is not what you present! "People want and see the thing as they are in their head, and never as they are OUT".

Middle English: via Old French from Latin gratiosus, from gratia ‘esteem, favour’

(But now I would need to explain 'favour' or ''esteem'' meaning, which are totally different... no way)

But if You insist from where came that another "S" in the word Gracio(s)us from him/her, it is from the oldest language (before any others, and you don't know it), and it is joke "sus" add to any other word.

Sus means similar to "get away". And in his/her word would be understandable meaning of emotion 'thank you' from inside to go away the word 'thank you' because that word does not make pleasant feeling in him/her. Reality is better. Helps me helps you is better.

""Ancients are not monkeys, but humans with time are becoming adapted to Earth and becoming more to monkeys.""

It is not intended to You this sentence Fernando.

From time to time someone on the globe gets memory from the some of the oldest words and makes combinations of words without any intention, it is written in 'some' of the dna banks, and gets 'read' upon specific emotion. With time will be lost and people will adapt to be monkeys "again", as it happened in past. It is not thousands years, not millions, not billions, more but you can imagine.

English Wisdom (which I do not follow) : "Someone not knowing the truth, can not cover it with lies or un-knowledge".

What on earth are you on about?

I know very well what "gracious" means in English (I am a native English speaker even though I'm Portuguese), but as you can see from the OP's response, he misspelled the word while trying to say "thank you" to me in my own language. He was under the impression that in Portuguese and Spanish they would be the same.

Also, please spare me the linguistics lesson when you have to resort to Google translate to explain English to me.

M.R.
44
M.R.  
Fernando Carreiro:

What on earth are you on about?

I know very well what "gracious" means in English (I am a native English speaker even though I'm Portuguese), but as you can see from the OP's response, he misspelled the word while trying to say "thank you" to me in my own language. He was under the impression that in Portuguese and Spanish they would be the same.

Also, please spare me the linguistics lesson when you have to resort to Google translate to explain English to me.

I speak English and German since my 3-rd. Between other 2 languages, with time 5-th and more. I will not make any more lessons, sorry .
Cromo
259
Cromo  

Fernando san

I have an another question.

How can I select the ordest order (I mean not closed but open orders) ? 

static variable is used to compare with OpenOrder time?

for(int i = OrdersTotal() - 1; i >= 0; i--){
   if(OrderSelect(i, SELECT_BY_POS) == true)
    
    *****************
     }
}
Fernando Carreiro
4986
Fernando Carreiro  
kajironpu: Fernando san I have an another question. How can I select the ordest order (I mean not closed but open orders) ? 

static variable is used to compare with OpenOrder time?

No need for static variables this time. You can do it with local variables!

int intTicketOldestOpenOrder = WRONG_VALUE;                          // For identifing Ticket of Oldest Open Order
datetime dtOldestOpenOrder   = WRONG_VALUE;                          // For identifing Time   of Oldest Open Order

for( int i = OrdersTotal(); i>= 0; i -- )                            // Loop through all Open Orders backwards
{
   if(   OrderSelect( i, SELECT_BY_POS )        &&                   // Select Order by Index and Check it
       ( OrderMagicNumber() == intMagicNumber ) &&                   // Check if Magic Number is correct
       ( OrderSymbol()      == _Symbol        ) &&                   // Check if Symbol is correct
       ( ( OrderType()      == OP_BUY  ) ||                          // Make sure it is a valid Market Order ...
         ( OrderType()      == OP_SELL )      )    )                 // ... and not a Pending Order
   {
      if( ( dtOldestOpenOrder > OrderOpenTime() ) ||                 // Check if order is older
          ( dtOldestOpenOrder == WRONG_VALUE    )    )               // or if it is the first iteration
      {
         dtOldestOpenOrder        = OrderOpenTime();                 // Update the Time   of Oldest Open Order
         intTicketOldestOpenOrder = OrderTicket();                   // Update the Ticket of Oldest OPen Order
      }
   }
}

if( intTicketOldestOpenOrder != WRONG_VALUE )                        // Check if a valid oldest open order was found
{
   if( OrderSelect( intTicketOldestOpenOrder, SELECT_BY_TICKET ) )   // Select the Oldest Open Order found
   {
      // Do Something
   }
}
NB! Please note that this will not work correctly if there is more than one oldest order with the same time, however, the probability of that happening is almost zero if using market orders at different prices. If however, your strategy places pending orders at the same price that might be triggered at the same time (I've never seen this happen, but one never knows), then you will have to adapt the logic of the loop accordingly.
Cromo
259
Cromo  
Fernando Carreiro:

No need for static variables this time. You can do it with local variables!

NB! Please note that this will not work correctly if there is more than one oldest order with the same time, however, the probability of that happening is almost zero if using market orders at different prices. If however, your strategy places pending orders at the same price that might be triggered at the same time (I've never seen this happen, but one never knows), then you will have to adapt the logic of the loop accordingly.

Fernando san  Obrigado!

WRONG_VALUE is first time to see. Is it kind of EMPTY_VALUE?

I will study your code deeply...

12
To add comments, please log in or register