Example MQL4 Code Moving Average EA Check Pending Order
In the last chapster we learn about how to build expert advisor properties and link the extern variable
Moving Average EA function. In this chapster we would learn open order condition from MetaTrader
Moving Average EA Code
Moving Average sample expert advisor by MetaQuotes designed the coding as 5 block of code
Calculate Pending order
Optimal Lot or Trading Money Management
Open order condition
Close order condition
Activate on Tick Function
This Chapter we would learn about Calculation The pending order.
Calculate Pending order
Calculate Pending order including function as below
Function | Feature |
int OrdersTotal(); | Returns the number of market and pending orders. |
bool OrderSelect | The function selects an order for further processing. |
Order index or order ticket | number of ticket |
Selecting flags | |
SELECT_BY_POS | index in the order pool |
SELECT_BY_TICKET | index is order ticket |
pool=MODE_TRADES | |
MODE_TRADES | opened and pending orders |
MODE_HISTORY | closed and canceled order |
string OrderSymbol(); | The symbol name of the currently selected order |
string Symbol(); | Returns a text string with the name of the current financial |
int OrderMagicNumber(); | The identifying (magic) number of the currently selected order |
int OrderType(); | |
OP_BUY | buy order |
OP_SELL | sell order |
OP_BUYLIMIT | buy limit pending order |
OP_BUYSTOP | buy stop pending order |
OP_SELLLIMIT | sell limit pending order |
OP_SELLSTOP | sell stop pending order |
Mention to the code and using function in this part
Basic MQL4 Function creation example from document page of MQL4
Explian the code MA EA calculate pending order
First Step specify function name and return value to function
From the MA EA code this part would return Integer value to function, which when we would like to use this
function that we should call this function with (string variable)
for(int i=0;i<OrdersTotal();i++) // check total pending order
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break; // no action if have pending order
//if have pending order Buy or Sell count buys and sells variable
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MAGICMA)
{
if(OrderType()==OP_BUY) buys++;
if(OrderType()==OP_SELL) sells++;
}
//--- return total orders pending
if(buys>0) return(buys);
else return(-sells);
}
Check order pending by function OrderSelect, which command in this part would check total order pass minor function SELECT_BY_POS and trade was opened or trade pending MODE_TRADE.
This if not have pending order would call open order function pass OrderType function
This Chapter we learn about how to check pending order in next chapter we would learn about Optimal Lot or money management
No comments:
Post a Comment