JegForex - Solusi Tepat Untuk Investasi
Home Register About Forex Platforms Education Jeg Blog
» Demo Account
» Real Account
» Open Account

» JegForex Basic
» Psychologys Tading
» Indicator Trading
» MetaTrader Platform

» Learn MQL4
 

Section 1
Introduction: the uses and about MQL4.
Section 2
Simple Example of EA: the Expert Advisor, its example
Section 3
The Syntax and Basics: the variable and comments.
Section 4
Data Type: the type of data on MQL4 with examples.
Section 5
Plans and expressions: the operator and its expression in the MQL4 example.
Section 6
Decision and Looping: the use of branching and looping to set the EA program flow.
Section 7
Order and Technical Analysis: EA discusses how to create order and make use technical indicators.
Section 8
Developing EA: discuss how to prepare EA. It is expected that the reader is able to make a simple EA.
Section 9
Use iCustom: discuss how to prepare the EA based on a custom basis entry indicator.

 
JegForex Registration
JegForex Contact
JegForex Education
 

 Back to Learn MQL4

Section 2 - Sample EA

The first criticism, is the EA (the EA, we will discuss the new custom indicator and the script).

To start making EA, after the entry MetaEditor, select File -> New -> select Expert Advisor, and enter the Link.

and you will get some code like this:

code:
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+

that in the init () is run at 1x EA first time in drag to chart
that in the deinit () is run at 1x EA remove from the chart, or chart is closed
that in the start () is executed each tick (each have new rates)

well, see EA super simple following:

code
extern double Lots=0.1;
extern int StopLoss=100;
extern int TakeProfit=150;
extern string txComment="Order EA1";
extern int MagicNumber=12345;
extern int Slippage=5;

//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----

//----
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
//----
if (OrdersTotal()==0)
{
if (iClose(Symbol(),0,1) > iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE,1) )
{
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,txComment,MagicNumber);
}
else if (iClose(Symbol(),0,1) < iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE,1) )
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,txComment,MagicNumber);
}

}
//----
return(0);
}
//+------------------------------------------------------------------+

EA this logic, kira2 (eg, EA is placed in the GBPUSD chart 1 Hour) If you do not have a position, if the candle hours ago closenya above 10 EMA, then buy, if the candle hours ago closenya below EMA 10, then sell.

about it like this ...... buy in the open the candle be the arrow (the candle closed above the previous EMA) at 1.7366 and close at 1.7516 (150 pips TP) ...

should be able to buy its price is 1.7369 and TP at 1.7519, but its core is about such

we try to study one by one part of it ..... explanation on this topic at a glance aja ... details will be explained later in each section.

code:
extern double Lots=0.1;
extern int StopLoss=100;
extern int TakeProfit=150;
extern string txComment="Order EA1";
extern int MagicNumber=12345;
extern int Slippage=5;

quite clearly is yes
extern essentially a variable that can be changed by end users who do not have access to source code EA.

code:
if (OrdersTotal()==0)

If all order = 0, which means that under the command (in the ()) will be executed if there is no order at all.
order is considered a good open position (buy / sell), or pending orders.

code:
if (iClose(Symbol(),0,1) > iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE,1) )

iClose () function to retrieve the price of the candle close (details will be explained in other parts)
syntax on this, he means taking a close price of the pair in which the EA attach, 1 candle before now.

IMA () that take a value of moving average, which means that this syntax in the period EMA 10 is calculated from the price close, 1 hour before now (though the same time a candle than ama)

code:
OrderSend(Symbol(),OP_BUY,Lots,Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,txComment,MagicNumber);

OrderSend () is used to do the order, will be explained later in other parts, including the use of catch its error does not occur so that the tragedy of the log file size

else if underneath it and the same, the signs are that it be reversed ..

.........

simple eh? .. so simple, it's EA is also very simple. No money management, there is no trailling stop it, no error is Catcher, etc. but it is EA's most simple, in the later part of the next described further details about the function-function ...

Hopefully useful to all of us ..
Click the register when you are ready!

Section 3 - The Syntax and Basics: the variable and comments.

 
 

 

 

 Jadikan homepage Anda | | Risk Disclosure | Contact | Links

Solusi tepat dalam investasi.
© 2010. all rights reserved
 
Sported by Polsend.com