Order Functions and Technical Indicators
This section discusses some of the important functions,
which are used in almost every EA. In fact the MQL 4
functions that many, but let's discuss the first 2 basic
functions only, namely the order and function of technical
analysis.
1. Order Function
This function is certainly there in all of EA. The
point is to open, close, or change the position (I actually
function a lot) ...
more details on its help MQL4, in the section "Trading
Functions"
here we are few (the rest can be read alone), that
is how important ngerti read & life
OrderSend (): to open the order
code:
int OrderSend( string symbol, int cmd, double
volume, double price, int slippage, double stoploss,
double takeprofit, string comment=NULL, int magic=0,
datetime expiration=0, color arrow_color=CLR_NONE)
example, open to buy 1 lot, without tp and sl:
code:
OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"My order
#1",1,0,Green);
Symbol is filled symbol () if you want the same in
order to chart the way in which EA .. if for example
would like to order a pair, I just write "GBPUSD"
or "EURUSD" for example ...
cmd is 6: OP_BUY, OP_SELL, OP_SELLSTOP, OP_SELLLIMIT,
OP_BUYLIMIT, OP_BUYSTOP
the lot number of the volume of its
price, the buy, make sure the Ask price, the sell,
bid price. If it is not the error.
slippage is only 0-5 pip content, though there is no
requote. Depending on the strategy but also, if only
3 pip TP yah automatic slippage do not great ...
stoploss = stoploss price (not the pips SL) ...
takeprofit take profit = price
comment = would fill what's up ..... charge only for
the user information
magic = magic magicnumber this, use to identify the
position. For instance, EA is only in the program to
manage the order with a certain magic number, then EA
will not modify / close the order u (the order because
there is no magic number)
expiration = special order for the pending
color = color marks on the chart
OrderSend function () this will return the value -1
if the order fails, if the order is successful, it will
return the order number is
failed to find out what the order, can use the function
getLastError ()
for example like this:
code:
int ticket;
if(iRSI(NULL,0,14,PRICE_CLOSE,0)<25)
{
ticket=OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point,"My
order #2",16384,0,Green);
if(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
return(0);
}
}
error code number can be seen in its help it, in MQL4
Reference -> Standard constants -> Error codes
Well, after the order is opened, the order can also
modify (modified SL / TP it) with the function OrderModify
()
code:
bool OrderModify( int ticket, double price, double
stoploss, double takeprofit, datetime expiration, color
arrow_color=CLR_NONE)
OrderModify () this value will be true if the modification
was successful, and false if the modification fails
...
code:
if(TrailingStop>0)
{
OrderSelect(12345,SELECT_BY_TICKET);
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Blue);
return(0);
}
}
}
Ok, there is 1 more important function, namely OrderSelect
()
OrderSelect () is useful to select the order will be
modified / diclose
code:
bool OrderSelect( int index, int select, int pool=MODE_TRADES)
OrderSelect () can be used to choose (select-men -
the right English language is what?) Whether the order
is closed, open again, or still pending (limit / stop
order) ..
index = index order is (0,1,2,3, dst) in the mode SELECT_BY_POS;
or number on the ticket mode SELECT_BY_TICKET
select = select a type that it can SELECT_BY_POS (choose
based on the position, if it does not get his ticket
number, use this one), or SELECT_BY_TICKET (if the ticket
already know that this is life) ...
pool = MODE_TRADES is to have an active order (limit
/ stop order / order is still open), MODE_HISTORY to
choose
example:
code:
if(OrderSelect(12470, SELECT_BY_TICKET)==true)
{
Print("order #12470 open price is ", OrderOpenPrice());
Print("order #12470 close price is ", OrderClosePrice());
}
else
Print("OrderSelect returned the error of ",GetLastError());
ok, after in-select, we can use functions to get information
about the order, such as lot number, SL, TP, Symbol,
etc.
functions include:
OrderLots () = to know the number of lot
OrderTakeProfit () = TP know
OrderStopLoss () = SL know
OrderSymbol () = pair know it
... simply complete the check in MQL4 Reference ->
Trading functions; if less clear about how life can
be in post in this topic ...
------
ok, I can in order modify, in select, it's time to
close the order or delete the pending order is not so
to close the open position, use OrderClose () (or OrderCloseBy
() if hedging)
to delete the pending order, use OrderDelete ()
code:
bool OrderClose( int ticket, double lots, double
price, int slippage, color Color=CLR_NONE)
ticket = ticket number
= number of lots the lot is closed .. for example if
I want to close all the contents are OrderLots ()
price = close, if want to sell, use Ask price, if want
to get close, type Bid
slippage contents = 0-5 suit ...
color = color sign in chartnya ..
the same as OrderModify (), OrderClose () this value
will be True if successful close, and the value false
if failed close position
for OrderDelete (), is much more simple from OrderClose
()
code:
bool OrderDelete( int ticket, color Color=CLR_NONE)
example :
code:
if(Ask>var1)
{
OrderDelete(order_ticket);
return(0);
}
4 functions before these functions are the basis for
trade .... well then, we will study the functions to
read the value of the technical indicators such as Moving
Average, MACD, etc.
after discussion of the technical functions of this
indicator, should be able make a simple EA (for exercise
......)
2. Technical Indicator
Functions
Help in mql4, can check in at the MQL4 Reference -
Technical indicators

I love the example just moving average ...
its function IMA ()
code:
double iMA( string symbol, int timeframe, int
period, int ma_shift, int ma_method, int applied_price,
int shift)
for example, according to the picture above, the rule
is if the previous candle close above 144 EMA, I get
open ...
code:
/ / first variable should be prepared
double ma1=0;
ma1=iMA(Symbol(),0,144,0,MODE_EMA,PRICE_CLOSE,1);
if (iClose(Symbol(),0,1)>ma1)
{
//open buy......
}
for ma_method, there are 4 (I can click on
the help it), there MODE_SMA, MODE_EMA, MODE_SMMA, MODE_LWMA
for applied_price, that have 7, just click the link
in its help for its detail (more than I write ...)
another example, the strategy most popular throughout
the period, MA cross
If EMA 10 EMA 20 pieces from the top, open sell
if translated into computer commands, roughly as well
1) check EMA 10 and 20 in the candle before it is 2
2) check EMA 10 and 20 in the candle before it is 1
3) What EMA 10 EMA is higher than 20 on the candle 2,
EMA and 10 EMA is lower than 20 on the candle 1, it
means going cross
I live in the coding course ....
code:
double ma10_1, ma20_1, ma10_2, ma20_2 = 0;
/ / 1) check EMA 10 and 20 in the candle before
it is 2
IMA ma10_2 = (Symbol (), 0,144,0, MODE_EMA, PRICE_CLOSE,
2);
IMA ma20_2 = (Symbol (), 0,144,0, MODE_EMA, PRICE_CLOSE,
2);
/ / 2) check EMA 10 and 20 in the candle before
it is 1
IMA ma10_1 = (Symbol (), 0,144,0, MODE_EMA, PRICE_CLOSE,
1);
IMA ma20_1 = (Symbol (), 0,144,0, MODE_EMA, PRICE_CLOSE,
1);
/ / 3) I EMA 10 EMA is higher than 20 on the
candle 2, EMA and 10 EMA is lower than 20 on the candle
1, it means going cross
if (ma10_2> ma20_2 & & ma10_1 <ma20_1)
(
/ / open sell ......
)
less sophisticated .... would be a filter to detect
overbought RSI (that better) ...
code:
double ma10_1, ma20_1, ma10_2, ma20_2 = 0;
double rsi1 = 0;
/ / 1) check EMA 10 and 20 in the candle before it
is 2
IMA ma10_2 = (Symbol (), 0,144,0, MODE_EMA, PRICE_CLOSE,
2);
IMA ma20_2 = (Symbol (), 0,144,0, MODE_EMA, PRICE_CLOSE,
2);
/ / 2) check EMA 10 and 20 in the candle before it
is 1
IMA ma10_1 = (Symbol (), 0,144,0, MODE_EMA, PRICE_CLOSE,
1);
IMA ma20_1 = (Symbol (), 0,144,0, MODE_EMA, PRICE_CLOSE,
1);
rsi1 = iRSI (Symbol (), 0.14, PRICE_CLOSE, 1);
/ / 3) I EMA 10 EMA is higher than 20 on the candle
2, EMA and 10 EMA is lower than 20 on the candle 1,
it means going cross
if (ma10_2> ma20_2 & & ma10_1 <ma20_1
& & rsi1> 70)
(
/ / open sell ......
)
is easy
for other indicators such as MACD, par-sar, sto, Envelope,
etc. can be read on its own referencenya ....
further discussion is to create a complete EA simple
(and can be dicompile way) (but not profitable or not
...)
Hopefully useful to all
of us ..
Click the register when
you are ready!
Part 8
- Developing EA: discuss how to prepare EA. It is expected
that the reader is able to make a simple EA.
|