Tuesday, 18 September 2012

logic EA 2 SMA

//+------------------------------------------------------------------+
//| EA 2sma.mq4 |
//| Dwi M ea@dwim.web.id |
//| http://ea.dwim.web.id |
//+------------------------------------------------------------------+
#property copyright "Dwi M ea@dwim.web.id"
#property link "http://ea.dwim.web.id"



extern int TakeProfit = 30;
extern int StopLoss = 30;
extern int Slippage = 3;
extern double Lots = 1.0;

extern int SMA1Periode = 4;
extern int SMA2Periode = 8;

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

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

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

double dSMA1, dSMA2, dSMA1before, dSMA2before;

dSMA1=iMA(NULL,0,SMA1Periode,0,MODE_EMA,PRICE_CLOS E,0);
dSMA2=iMA(NULL,0,SMA2Periode,0,MODE_EMA,PRICE_CLOS E,0);

dSMA1before=iMA(NULL,0,SMA1Periode,0,MODE_EMA,PRIC E_CLOSE,1);
dSMA2before=iMA(NULL,0,SMA2Periode,0,MODE_EMA,PRIC E_CLOSE,1);


if (OrdersTotal()<1)
{
if (AccountFreeMargin()<1000*Lots)
{ Comment("EA tidak bekerja, dana kurang :", AccountFreeMargin()); return(0);}

if ((dSMA1>dSMA2) && (dSMA1before<dSMA2before)) 

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



if ((dSMA1<dSMA2) && (dSMA1before>dSMA2before))
{
OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,Ask+S topLoss*Point,Bid-TakeProfit*Point,0);
}

}



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

No comments:

Post a Comment