dOnT SeARcH In HeRE

Custom Search

CommenT AnYtHnG 2


ShoutMix chat widget
free counters

coMmEnT AnYThNg

Labels

Link Ur wEb

Get your own LinkBox!

Example EA

Saturday, February 20, 2010

The first discussion, is the EA (the EA, we will discuss the new custom indicators and scripts).

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

then you will get a codelike this:

//+------------------------------------------------------------------+

//| ContohEA2.mq4 |
//| Copyright © 2008, Forexindo |
//| http://www.forexindo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Forexindo"
#property link "http://www.forexindo.com"

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

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

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

//----
return(0);
}
//+------------------------------------------------------------------+
A little explanation,

that in the init () run 1x when EA first time in drag to a chart
which in deinit () run in 1x when EA remove from the chart, or chart is closed
that in the start () is run every tick (each a new price)


just look at EA's super-simple following:

//+------------------------------------------------------------------+

//| ContohEA1.mq4 |
//| Copyright © 2008, Forexindo |
//| http://www.forexindo.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Forexindo"
#property link "http://www.forexindo.com"

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) <>
The logic of this EA, about (eg EA GBPUSD chart placed in 1 Hour), If no position, if the candle hours ago close above EMA 10, then buy, if the candle hours ago close below EMA 10, then sell.





something like this is ...... buy on the open candle that I love the arrow (for previous candle closed above EMA) at 1.7366, and close at 1.7516 (150 pips TP) ...

um, I forgot to count the spread should be able to buy it at the price of 1.7369 and was at 1.7519 TP
yes but the point about it is

let us examine one by one part of it ..... explanation on this topic briefly wrote ... details will be explained in each section.

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 yes
extern variable point so that it can be changed by end users who do not have access to the source code EA.

if (OrdersTotal()==0)



If all order = 0, which means the command below it (didalem ()) will be executed if there is no order at all.
which is considered good order is an open position (buy / sell) or a pending order.

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




iClose () is a function to retrieve the candle close price (details will be explained in another section)
in this syntax, meaning he take close price of the pair in which the attach EA, 1 candle before now.

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


IMA () was created to take the value of moving averages, which in this syntax brarti EMA period of 10 diitung close price, 1 hour before now (same time let ya candles are compared)


OrderSend () is used to make order, will be described elsewhere, including the use of his catch errors that did not happen tragedy bergiga2 log file size

else if and which are the same underneath, his marks aja cuman reversed ..

.........

simple right? .. so simple, it is EA is also very simple. managementnya no money, no stop trailling her, ga There was an error catcher etc.

but yes it was the simplest EA, later in the next part be explained in more detail about fucntion itself.










0 comments:

Post a Comment

Join Traffic = Money