Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Pending Orders - MetaTrader 4 Expert | MT4 EA Download - MetaTrader 4 Resources

author EAcpu | 2 reads | 0 comments |

Pending Order - expert for MetaTrader 4

A pending order is an order that will be executed when the price hits a point specified by us. In other words, opening a pending order means an order to open a position at a certain price level. Therefore, if the price reaches a predetermined level, then we will automatically have an open trading position.

In EA, there are 6 order types:

There are 6 order types, and 4 pending order types are available. We will discuss the types of pending orders one by one, and then we will immediately take action on the EA.

A buy limit order is an order that runs below the price, so in order to need to change the order structure, it is an order type and the price is already booked.

Things to note when purchasing orders are as follows:

 orderSend ( symbol (), 0 , starting batch, ask , 3 , ask -SL* view , ask +TP* view , "" , magic, 0 , blue);

Nothing in the underlined section must be changed pending such use.

Another part that must be considered is the D distance between the current price and the pending order booking price.

 Q - D Distance * View

So as follows:

 orderSend ( symbol (), 2 , starting batch, ask - D distance * view , 3 , ask - D distance * view -SL* view , ask - D distance * view +TP* view , "" , magic, 0 , blue);

It can also be written as:

 orderSend ( symbol (), OP_BUYLIMIT , starting batch, ask - D distance * view , 3 , ask - D distance * view -SL* view , ask - D distance * view +TP* view , "" , magic, 0 , blue);


A sell limit order is an order above the price movement.

Since the important parts of a buy limit order are the sequence type and distance , compare the different

 orderSend ( symbol (), 3 , starting batch, bid + D distance * views , 3 , bid + D distance * views +SL* views , bid + D distance * views -TP* views , "" , magic, 0 , red);

It can also be written as:

 orderSend ( symbol (), OP_SELLLIMIT , starting lot, bid + D distance * views , 3 , bid + D distance * views +SL* views , bid + D distance * views - TP* views , "" , magic, 0 , red);

A stop buy order is an order above the price movement.

Please observe and compare with previous types

 orderSend ( symbol (), 4 , starting batch, ask + D distance * view , 3 , ask + D distance * view -SL* view , ask + D distance * view +TP* view , "" , magic, 0 , blue);

It can also be written as:

orderSend ( symbol (), OP_BUYSTOP , starting batch, ask + D distance * view , 3 , ask + D distance * view -SL* view , ask + D distance * view +TP* view , "" , magic, 0 , blue);

A sell stop order is an order placed at the current price.

Please observe and compare with previous types

 orderSend ( symbol (), 5 , starting batch, bid - D distance * view , 3 , bid - D distance * view +SL* view , bid - D distance * view -TP* view , "" , magic, 0 , red);

It can also be written as:

 orderSend ( symbol (), OP_SELLSTOP , starting batch, bid - D distance * view , 3 , bid - D distance * view +SL* view , bid - D distance * view -TP* view , "" , magic, 0 , red);

As I promised at the beginning, we will try to make the EA simple by using all four pendings!

But before we make we have to make the order based on the number of filters and their type, I have provided a convenient script which is a function that calculates the order type

 Integer total orders ( integer meters)
{ Integer total = 0 ; order ( integer i = 0 ; i < order total (); i++) {
if (! OrderSelect (i, SELECT_BY_POS , TradingMode )) continue ;
if ( OrderSymbol ()!= Symbol ()|| OrderMagicNumber ()!=Magic|| OrderType ()!=M) continue ;
  total++;
 } return (all);
}

How to call

 if (TOTAL ORDERS( OP_BUYLIMIT ) == 0 ) { res = ORDERSEND ( symbol (), 2 , starting_batch , Q - D_DIST * Views , 3 , Q - D_DIS * Views_SL * Views , Q_D_D_Distance * View + TP * Views , "" , MAGIC, 0 , blue ) ;}

or

 if (total orders ( 2 ) == 0 ) { res = order_send ( symbol (), OP_BUYLIMIT , starting batch, ask - ddistance * views , 3 , ask - ddistance * views -SL* views , ask - ddistance * views + TP * views , "" , magic, 0 , blue);}

sell limit

if (TOTAL ORDERS( OP_SELLLIMIT ) == 0 ) { res = ORDERSEND ( SIGNS (), 3 , starting_lot, bid +distance* views , 3 , bid +distance* views +SL* views , bid +distance* views -TP* views , "" , magic, 0 , red);}

or

 if (total orders( 3 )== 0 ){res= ordersSend ( symbol (), OP_SELLLIMIT , starting batch, bid +distance* views , 3 , bid +distance* views +SL* views , bid +distance* views -TP* views , "" , magic, 0 , red);}

Continue with EA....

But I try to make EA just to understand better

//+------------------------------------------------------------------+
//| EA pending order.mq4 |
//| Copyright 2016, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#Property Copyright "Copyright 2016, WidiPramana."
#Property association "https://www.mql5.com"
# Property version "1.00"
#propertystrict

outer string name_EA = "Pending Orders" ; outer integer start_time = 6 ; outer integer end_time = 20 ; outer integer TP = 20; outer integer SL = 100 ; outer double mass = 0.01 ; outer integer distance = 15 ; outer integer magic = 69 ; Double slb, tpb, sls, tps, pt; integers res, wt, wk, air tickets, air tickets; //+----------------------------------------------------------------------------------+
//|Expert initialization function |
//+------------------------------------------------------------------+
integer_initialize ()
  { //---- if ( number == 3 || number == 5 ) points = 10 * views ; else points = views ; //---- return ( 0 );
  } //+------------------------------------------------------------------+
//|Expert to initialize function |
//+------------------------------------------------------------------+
integer deinitialization()
  { //----

//---- Return ( 0 );
  } //+------------------------------------------------------------------+
//|Expert start function |
//+------------------------------------------------------------------+
integer start()
  {
Label();
 
if (Hour_trade()== 1 ){
if (total orders( 2 )== 0 ){res= ordersSend ( symbol (), OP_BUYLIMIT ,NR(lot), ask -distance* views , 3 , ask -distance* views -SL* views , ask -distance* views +TP* views , "" ,magic, 0 ,blue);}
if (TotalOrders( 3 )== 0 ){res= OrdersSend ( Token (), OP_SELLLIMIT,NR(lots) , bid +distance* views , 3 , bid +distance* views +SL* views , bid +distance* views -TP* views , ”” , magic, 0 , red);} if (total orders ( 4 ) == 0 ){res= orders sent ( symbol (), OP_BUYSTOP ,NR(lots) , ask +distance* views , 3 , ask +distance* view -SL* view , ask +distance* view +TP* view , ”” , magic, 0 , blue); } if (total orders ( 5 ) == 0 ) { res = order_send ( symbol (), OP_SELLSTOP , NR(lot) , bid -distance* view , 3 , bid -distance* view +SL* view , bid -distance* view -TP* view , ”” , magic, 0 , red); } } return ( 0 ); } //+------------------------------------------------------------------+ integer Hour_trade() { boolean trade = False ; if (StartTime > End_Hour) { if ( Hour () >= StartTime || Hour () < End_Hour) trade = True ; } else if ( Hour () >= StartTime&& Hour () < End_Hour) trade = True ; return (Trade); } integer total orders( integer tipe) { integer total = 0 ; for ( integer i = 0 ; i < order total (); i++) { if (! orderselect (i, SELECT_BY_POS , trading mode ))) continue ; if ( order_symbol ()!= symbol ()|| order_magic_number ()!=magic|| order_type ()!=tip) continue ; total++; } return (all); } double NR( double lot) { double maximum lot = market information ( symbol (), mode_max_quantity ), small lot = market information( symbol (), MODE_MINLOT ), l step = market information ( symbol (), MODE_LOTSTEP ); double lot size = lstep * normalized double (thelot/lstep, 0 ); Lots = Math Max(Math Min (Max Lots, Lots), Mini Lots); return (many); } blank tag() { comments ( "\n" , "\n" , "\n ------------------------------------------------" , "\n::Pending+Orders" , "\n------------------------------------------------" , "\n :: propagation: " , market information ( symbol (), mode_propagation ), "\n :: Leverage: 1 : "/span>, Account Leverage (), "\n :: Equity : " , Account Equity (), "\n ::Hour Server :" , Hour (), ":" , Minute (), "\n------------------------------------------------" ); }

The EA runs as follows:

Pending Order - expert for MetaTrader 4

Hope it's useful, comments are welcome

Happy profits, good luck, and have a nice day…


Attachment download

📎ea_pending_order.mq4 (3.9 KB)

Source: MQL5 #14883

Verification code Refresh