Hi
I would like to make my first EA. Is a simple tactic:
When the par EUR / USD with time 1H and the price crosses or equals the SMA50 and SMA100 is above is buy signal .... If the price crosses or equals the SMA50 and SMA100 is below sell
At the moment only try that the price touch the moving average of 50, because the crossing still do not know.
//+------------------------------------------------------------------+//| proyect.mq4 |//| Greck |//| http://www.metaquotes.net |//+------------------------------------------------------------------+#property copyright "Greck"#property link "http://www.metaquotes.net"externint MagicNumber = 5432101;
externdouble Lots = 0.1;
externdouble TakeProfit=50;
externdouble StopLoss=20;
double MM50;
double MM100;
double MM200;
double Precio;
bool Compara;
bool Compara2;
//+------------------------------------------------------------------+//| expert initialization function |//+------------------------------------------------------------------+int init()
{
return(0);
}
//+------------------------------------------------------------------+//| expert deinitialization function |//+------------------------------------------------------------------+int deinit()
{
return(0);
}
//+------------------------------------------------------------------+//| expert start function |//+------------------------------------------------------------------+int start()
{
int StopMultd,Slip=5;
int digits=MarketInfo("EURUSD",MODE_DIGITS);
StopMultd=10;
double TP=NormalizeDouble(TakeProfit*StopMultd,Digits);
// stop lossdouble SL=NormalizeDouble(StopLoss*StopMultd,Digits);
double Slippage=NormalizeDouble(Slip*StopMultd,Digits);
// stop lossdouble slb=NormalizeDouble(Ask-SL*Point,Digits);
double sls=NormalizeDouble(Bid+SL*Point,Digits);
// take profitdouble tpb=NormalizeDouble(Ask+TP*Point,Digits);
double tps=NormalizeDouble(Bid-TP*Point,Digits);
MM50 = iMA("EURUSD", PERIOD_H1, 50, 0, MODE_SMA, PRICE_CLOSE, 0);
MM100 = iMA("EURUSD", PERIOD_H1, 100, 0, MODE_SMA, PRICE_CLOSE, 0);
MM200 = iMA("EURUSD", PERIOD_H1, 200, 0, MODE_SMA, PRICE_CLOSE, 0);
Precio=iOpen("EURUSD", PERIOD_H1,0);
//-------------------------------------------------------------------+// Buy Orders//-------------------------------------------------------------------+if (((Precio==MM50)<MM100)&& OrdersTotal()<1)
{
int openbuy=OrderSend("EURUSD",OP_BUY,Lots,Ask,Slippage,slb,tpb,"Operaciones Raul",MagicNumber,0,Blue);
if(openbuy<1){int buyfail=1;}
}
//-------------------------------------------------------------------+// Sell Orders//-------------------------------------------------------------------+if (((Precio==MM50) > MM100)&&OrdersTotal()<1)
{
int opensell=OrderSend("EURUSD",OP_SELL,Lots,Bid,Slippage,slb,tpb,"Operaciones Raul",MagicNumber,0,Green);
if(opensell<1){int sellfail=1;}
return;
}
//-------------------------------------------------------------------+// Errors//-------------------------------------------------------------------+if(buyfail==1||sellfail==1){
int Error=GetLastError();
if(Error==130){Alert("Error en los stops. Intentandolo de nuevo."); RefreshRates();}
if(Error==133){Alert("Prohibido la posicion.");}
if(Error==2){Alert("Error comun.");}
if(Error==146){Alert("El sistema esta ocupado. Intentandolo de nuevo."); Sleep(500); RefreshRates();}
}
//-------------------------------------------------------------------return(0);
}
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.