Question about Mas_Tip from mql4 book

 

I wonder if someone might try and explain how this line works from the terminal function in the mql4 book I just cant get my head around it

Mas_Tip[OrderType()]++; // Amount of orders of the type

How is that one line putting the correct amount of orders of each type into the separate array elements in Mas_Tip ?

according to the comment in the terminal function it is separating out the orders by type counting how many of each type

and then inserting them in the array like this

// Mas_Tip[6] // Array of the amount of orders of all types
// [] order type: 0=B,1=S,2=BL,3=SL,4=BS,5=SS

I understand it is getting the amount of each order type and putting those amounts in the respective array indexes but how is it doing it ?

According to the documentation on OrderType()

int OrderType()

int OrderType( )
Returns order operation type for the currently selected order. It can be any of the following values:
OP_BUY - buying position,
OP_SELL - selling position,
OP_BUYLIMIT - buy limit pending position,
OP_BUYSTOP - buy stop pending position,
OP_SELLLIMIT - sell limit pending position,
OP_SELLSTOP - sell stop pending position.

so where is

Mas_Tip[OrderType()]++; getting the 0=B,1=S,2=BL,3=SL,4=BS,5=SS from ? and how is it calculating how many of each type there is and

putting them in the relevent array indexes ?

I apologise if this is a really dumb question because I know I am probably missing something totaly obvious but I would appreciate any help on this because

I want to use a simalar method in my EA but I need to understand it before I can use it.

this is the rest of the source code for that function:

// Terminal.mqh
// The code should be used for educational purpose only.
//------------------------------------------------------------------------------ 1 --
// Order accounting function
// Global variables:
// Mas_Ord_New[31][9] // The latest known orders array
// Mas_Ord_Old[31][9] // The preceding (old) orders array
// 1st index = order number
// [][0] not defined
// [][1] order open price (abs. price value)
// [][2] StopLoss of the order (abs. price value)
// [][3] TakeProfit of the order (abs. price value)
// [][4] order number
// [][5] order volume in lots (abs. price value)
// [][6] order type 0=B,1=S,2=BL,3=SL,4=BS,5=SS
// [][7] order magic number
// [][8] 0/1 comment availability
// Mas_Tip[6] // Array of the amount of orders of all types
// [] order type: 0=B,1=S,2=BL,3=SL,4=BS,5=SS
//------------------------------------------------------------------------------ 2 --
int Terminal()
{
int Qnt=0; // Orders counter

//------------------------------------------------------------------------------ 3 --
ArrayCopy(Mas_Ord_Old, Mas_Ord_New);// Saves the preceding history
Qnt=0; // Zeroize orders counter
ArrayInitialize(Mas_Ord_New,0); // Zeroize the array
ArrayInitialize(Mas_Tip, 0); // Zeroize the array
//------------------------------------------------------------------------------ 4 --
for(int i=0; i<OrdersTotal(); i++) // For market and pending orders
{
if((OrderSelect(i,SELECT_BY_POS)==true) //If there is the next one
&&
(OrderSymbol()==Symbol())) //.. and our currency pair
{
//--------------------------------------------------------------------- 5 --
Qnt++; // Amount of orders
Mas_Ord_New[Qnt][1]=OrderOpenPrice(); // Order open price
Mas_Ord_New[Qnt][2]=OrderStopLoss(); // SL price
Mas_Ord_New[Qnt][3]=OrderTakeProfit(); // TP price
Mas_Ord_New[Qnt][4]=OrderTicket(); // Order number
Mas_Ord_New[Qnt][5]=OrderLots(); // Amount of lots
Mas_Tip[OrderType()]++; // Amount of orders of the type
Mas_Ord_New[Qnt][6]=OrderType(); // Order type
Mas_Ord_New[Qnt][7]=OrderMagicNumber(); // Magic number
if (OrderComment()=="")
Mas_Ord_New[Qnt][8]=0; // If there is no comment
else
Mas_Ord_New[Qnt][8]=1; // If there is a comment
//--------------------------------------------------------------------- 6 --
}
}
Mas_Ord_New[0][0]=Qnt; // Amount of orders
//------------------------------------------------------------------------------ 7 --
return;
}
//------------------------------------------------------------------------------

 

OP_BUY and the others are (pre)defined constants. So if you execute the following code

Print(OP_BUY);
Print(OP_SELL);

the output would be : 0 and 1

you can define constants too in your code on the global scope

#define STATE_CLOSE 0
#define STATE_TRAIL 1

int start(){
   Print(STATE_CLOSE);
   Print(STATE_TRAIL);
}

the output would be : 0 and 1


hth

 
Russell wrote >>

OP_BUY and the others are (pre)defined constants. So if you execute the following code

the output would be : 0 and 1

you can define constants too in your code on the global scope

the output would be : 0 and 1


hth


ahh ok so thats where it gets the values from, so its using the integer value of each order type to be the corrsponding array index ...it all makes sense now thanks Russell

Reason: