Could someone help me create a very simple EA?

 

Hi!


I´m new to mql5 programming, and still learning. I´ve been trying to create a very simple mt5 expert advisor, with no success. It works like this: If candle0 low <= candle1 low, than buy 200 lots at market price, with a stop loss and take profit of 1 point. Could someone send me a code for this, so i can study it?


Thanks!

 
psmcs83:

Hi!


I´m new to mql5 programming, and still learning. I´ve been trying to create a very simple mt5 expert advisor, with no success. It works like this: If candle0 low <= candle1 low, than buy 200 lots at market price, with a stop loss and take profit of 1 point. Could someone send me a code for this, so i can study it?


Thanks!

Hi,

I did, you have to make very simple corrections and study programming:)


#define Candle0     1
#define Candle1     2

#define LOTS        10
#define SL          10
#define TP          10

void OnTick()
{
  static datetime lastTime=0;
  double point, price[Candle1-Candle0+1];
  MqlTick tick;
  MqlTradeRequest request;
  MqlTradeResult tradeResult;
  MqlTradeCheckResult checkResult;
  datetime lastbarTime=(datetime)SeriesInfoInteger(Symbol(),0,SERIES_LASTBAR_DATE);
  if(lastTime==0) lastTime=lastbarTime; else if(lastTime!=lastbarTime) {
    lastTime=lastbarTime;
    ZeroMemory(request);
    if(SymbolInfoTick(Symbol(),tick)) {
      point=SymbolInfoDouble(Symbol(),SYMBOL_POINT);
      if(CopyLow(NULL,0,Candle0,Candle1-Candle0+1,price) &&
      price[Candle0-1]<=price[Candle1-1]) { // BUY CONDITION
        request.price        = tick.ask;
        request.sl           = tick.bid-SL*point;
        request.tp           = tick.ask+TP*point;
        request.type         = ORDER_TYPE_BUY;
      }/* else if(CopyHigh(NULL,0,Candle0,Candle1-Candle0+1,price) &&
      price[Candle0-1]>=price[Candle1-1]) { // SELL CONDITION
        request.price        = tick.bid;
        request.sl           = tick.ask+SL*point;
        request.tp           = tick.bid-TP*point;
        request.type         = ORDER_TYPE_SELL;
      }*/ else return;
    } else return;
    request.action       = TRADE_ACTION_DEAL;
    request.symbol       = Symbol();
    request.volume       = LOTS;
    request.type_filling = ORDER_FILLING_FOK;
    request.type_time    = ORDER_TIME_GTC;
    if(OrderCheck(request,checkResult) && OrderSend(request,tradeResult))
    Print("Ok #",tradeResult.order); else Print("Error: ",checkResult.retcode);
  }
}

 
psmcs83:

Hi!


I´m new to mql5 programming, and still learning. I´ve been trying to create a very simple mt5 expert advisor, with no success. It works like this: If candle0 low <= candle1 low, than buy 200 lots at market price, with a stop loss and take profit of 1 point. Could someone send me a code for this, so i can study it?


Thanks!

What I did to learn, was forget about trading and just learn the basics of loops, arrays etc. Then progress onto accessing prices, time and bars. And then look at how to place orders and set stop loss etc..
 
Philipp Negreshniy:

Hi,

I did, you have to make very simple corrections and study programming:)


Thank you! I will study it.

Reason: