Prepare EA
OK, basically, a simple EA / standard (non-EA complex
network such as humans, for example, or that consists
of several modules that control the trade separately)
... consists of several parts / structure .. this part
usually make in a distinctive function, so that coding
looks neat, while simplify debugging
part:
- BuySignal: what conditions on the EA open buy
- SellSignal: what conditions on the EA open cell
- CloseBuySignal: what conditions on the EA close
buy position (this should not have, because it can
use TP / SL as closing)
- CloseSellSignal: same as CloseBuySignal
- MoneyManagement: create automatically calculate
lotsize
- Trail: create trailling position, for example, what
is needed
- Confirmator: if for example EA cuman trade Monday-Thursday,
then usually put in this section ..
If section 7 is met, EA make it so more easily
for example like this, I want to make the EA as in
Section 2 - Sample EA
EA this logic, some (eg, EA is placed in the
GBPUSD chart 1 Hour) If you do not have a position,
if the candle hours ago close above its 10 EMA, then
buy, if the candle close to its days ago under the
EMA 10, then sell. TP and the SL 150 is its 100 pips
in the breakdown so that the earlier 7:
- BuySignal: if the previous candle close price is
greater / above 10 EMA on the previous candle
- SellSignal: if the price of the previous candle
close more small / under the 10 EMA on the previous
candle
- No
- No
- Lot is automatically calculated based on the SL
and the percent risk.
- No use trail, so there is no
- Posis new opened if there are not positions, and
also does not trade on Friday (I will add rule)
about the source code is so well
code:
extern double RiskPercent=5;
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 (bolehTrade()) //that can trade
{
if (BuySignal() ) //buy signal if there
{
OrderSend(Symbol(),OP_BUY,itungLot(),Ask,Slippage,Ask-StopLoss*Point,Ask+TakeProfit*Point,txComment,MagicNumber);
}
else if (SellSignal() ) // sell signal if there
{
OrderSend(Symbol(),OP_SELL,itungLot(),Bid,Slippage,Bid+StopLoss*Point,Bid-TakeProfit*Point,txComment,MagicNumber);
}
}
//----
return(0);
}
//+------------------------------------------------------------------+
bool BuySignal()
{
/ / if the previous candle close price is greater /
above 10 EMA on the previous candle
if (iClose(Symbol(),0,1) > iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE,1)
)
{
return(true);
}
else
{
return(false);
}
}
bool SellSignal()
{
/ / if the price of the previous candle close more small
/ under the 10 EMA on the previous candle
if (iClose(Symbol(),0,1) < iMA(Symbol(),0,10,0,MODE_EMA,PRICE_CLOSE,1)
)
{
return(true);
}
else
{
return(false);
}
}
bool bolehTrade()
{
/ / if the day Friday, EA does not trade, or if the
order is open, the EA does not trade
if (DayOfWeek()==5 || OrdersTotal()>0) { return (false);
} else { return(true); }
}
double itungLot()
{
/ / for this lot is calculated automatically based on
the SL and the risk of
double xLots=0;
xLots=NormalizeDouble(AccountBalance()*RiskPercent/100
/StopLoss / 10,1);
return (xLots);
}
logic is so neat and clear ...
Oya, the operator at a glance
| | & Means or means and (later will be described
in the section about the service)
EA is invisible to its simple coding of most need its
only 5-10 minutes .... but if in the backtest, profitable
(irrespective of its dradown large) ...

Hopefully useful to all
of us ..
Click the register when
you are ready!
Section 9
- Use iCustom: discuss how to prepare the EA based on
a custom basis entry indicator.
|