Trying to setup my own ea - beginner

 

Hi Guys

So I have a strategy that I have been using in Mexcel, but I want to be able to backtest it on Metatrader. Only problem is that I have no prior experience in MQL4. The idea of my strategy is to use the 15min, 30min, and 1 hr timeframes (i will write the strategy and laymans terms but I have also attached how far I have gotten in writing my EA. Let me know if I'm on the right track or not).

Must be true for 15 min, 30 min, and 1hr timeframes: if 8 Period EMA > 16 Period EMA, if ADX > 20 and ADX < 40, if RSI > 50

If all these criteria are met, a BUY signal is entered when the price intersects with the 8EMA on the 15 min chart.

For a sell signal everything is the opposite except for the ADX conditions, which stay the same. 

Also, I know it's possible but I don't know how I would be able to use this ea to scan these criteria for all possible currency pairs, and not just look at one pair. If any of you know how that would be awesome. 

 

#property strict
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
//Declaring Variables:
 
double EURUSD_Bid = MarketInfo("EURUSD",MODE_BID);   
double EURUSD_Ask = MarketInfo("EURUSD",MODE_ASK);
   
double ATR_4dp = iATR(Symbol(),PERIOD_M15,14,0)*10000;
double ATR_2dp = iATR(Symbol(),PERIOD_M15,14,0)*100;

double RSI_M15 = iRSI(Symbol(),PERIOD_M15,14,PRICE_CLOSE,0);
double RSI_M30 = iRSI(Symbol(),PERIOD_M30,14,PRICE_CLOSE,0);
double RSI_H1 = iRSI(Symbol(),PERIOD_H1,14,PRICE_CLOSE,0);

double ADX_M15 = iADX(Symbol(),PERIOD_M15,14,PRICE_CLOSE,0,0);
double ADX_M30 = iADX(Symbol(),PERIOD_M30,14,PRICE_CLOSE,0,0);
double ADX_H1 = iADX(Symbol(),PERIOD_H1,14,PRICE_CLOSE,0,0);

double eightEMA_M15 = iMA(Symbol(),PERIOD_M15,8,0,MODE_EMA,PRICE_CLOSE,0);
double eightEMA_M30 = iMA(Symbol(),PERIOD_M30,8,0,MODE_EMA,PRICE_CLOSE,0);
double eightEMA_H1 = iMA(Symbol(),PERIOD_H1,8,0,MODE_EMA,PRICE_CLOSE,0);

double sixteenEMA_M15 = iMA(Symbol(),PERIOD_M15,16,0,MODE_EMA,PRICE_CLOSE,0);
double sixteenEMA_M30 = iMA(Symbol(),PERIOD_M30,16,0,MODE_EMA,PRICE_CLOSE,0);
double sixteenEMA_H1 = iMA(Symbol(),PERIOD_H1,16,0,MODE_EMA,PRICE_CLOSE,0);

double Stop_Loss_4dp = ((ATR_4dp*1.5) + (Ask-Bid));
double Stop_Loss_2dp = ((ATR_2dp*1.5) + (Ask-Bid));   

double Take_Profit_4dp = Stop_Loss_4dp*1.3;
double Take_Profit_2dp = Stop_Loss_2dp*1.3;
   

   


//---------------------------------------------------------------------------------------

int init()
   {
   Alert ("Program has started");
   return;
   }

//----------------------------------------------------------------------------------------

int start()
   {
   
   if(eightEMA_H1 > sixteenEMA_H1 && ADX_H1 > 20 && ADX_H1 < 40 && RSI_H1 > 50 
      
      && eightEMA_M30 > sixteenEMA_M30 && ADX_M30 > 20 && ADX_M30 < 40 && RSI_M30 > 50
      
      && eightEMA_M15 > sixteenEMA_M15 && ADX_M15 > 20 && ADX_M15 < 40 && RSI_M15 > 50
      
      && EURUSD_Bid == eightEMA_M15);
      
      {
      
      int Long = OrderSend("EURUSD",OP_BUY,0.5,EURUSD_Ask,1,Stop_Loss_2dp,Take_Profit_2dp,"1",0,0,clrGreen);
      
      }   
   
//---------------------------------------------------------------------------------------------
   
   return(0);
   
   }
   
int deinit()
   {
   Alert ("Program has Ended");
   return;        
   }
Files:
adx1.mq4  3 kb
 

init and deinit return an int, so you must use

return(0);

Assign values to your variables in start not globally or their values will not change.

Check whether an order is already open before opening a new order. You may get a new order opening every tick.

Reason: