[MT4] Please Review My Simple EA and Give some Advice and Tips

To add comments, please log in or register
Musngi
470
Musngi  

I copied this code from JimDandy's MQL4 Youtube tutorials, and I want to know if this code is updated/new code style or best way to do this EA coding? I modified some parts of code.

What I don't understand are the 4/5 digits broker code computation, Ask/Bid, Takeprofit and Stoploss. How can I put the Stoploss below/above the wicks of candle??

It pissed me off when I need to calculate this, instead of putting number of stoploss and takeprofit in that built-in function OrderSend().

//+------------------------------------------------------------------+
//|                                                     My_EA_v1.mq4 |
//|                         Copyright 2016, MetaQuotes Software Corp |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, MetaQuotes Software Corp"
#property link      "https://www.mql5.com"
#property version   "1.00"

extern double lotsize = 0.02;
extern int take_profit = 50;
extern int stop_loss = 25;
extern int slippage = 5;
extern int magic_number = 28000;

extern int fast_ma = 5;
extern ENUM_MA_METHOD fast_ma_method = MODE_EMA;
extern ENUM_APPLIED_PRICE fast_ma_applied = PRICE_CLOSE;

extern int slow_ma = 10;
extern ENUM_MA_METHOD slow_ma_method = MODE_EMA;
extern ENUM_APPLIED_PRICE slow_ma_applied = PRICE_CLOSE;

double pips;
int ticket;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{
   double ticksize = MarketInfo(Symbol(), MODE_TICKSIZE);
   if(ticksize == 0.00001 || Point == 0.001)
      pips = ticksize*10;
   else 
      pips = ticksize;
   return(INIT_SUCCEEDED);
}


void OnTick()
{
   double prev_fast_ma = NormalizeDouble(iMA(Symbol(), Period(), fast_ma, 0, fast_ma_method, fast_ma_applied, 2), 4);
   double now_fast_ma = NormalizeDouble(iMA(Symbol(), Period(), fast_ma, 0, fast_ma_method, fast_ma_applied, 1), 4);
   
   double prev_slow_ma = NormalizeDouble(iMA(Symbol(), Period(), slow_ma, 0, fast_ma_method, fast_ma_applied, 2), 4);
   double now_slow_ma = NormalizeDouble(iMA(Symbol(), Period(), slow_ma, 0, fast_ma_method, fast_ma_applied, 1), 4);
   
   if((prev_fast_ma < prev_slow_ma) && (now_fast_ma > now_slow_ma))
      if(OrdersTotal()==0)
         ticket = OrderSend(Symbol(), OP_BUY, lotsize, Ask, slippage, Ask-(stop_loss*pips), Ask+(take_profit*pips), NULL, magic_number, 0, clrGreen);
         if(ticket>0)
         {
            if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
               Print("BUY order opened : ", OrderOpenPrice());
         }
         else
            Print("Error opening BUY order : ", GetLastError());
         
   if((prev_fast_ma > prev_slow_ma) && (now_fast_ma < now_slow_ma))
      if(OrdersTotal()==0)
         ticket = OrderSend(Symbol(), OP_SELL, lotsize, Bid, slippage, Bid+(stop_loss*pips), Bid-(take_profit*pips), NULL, magic_number, 0, clrRed);
         if(ticket>0)
         {
            if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
               Print("SELL order opened : ", OrderOpenPrice());
         }
         else
            Print("Error opening SELL order : ", GetLastError());
}
//+------------------------------------------------------------------+
William Roeder
18310
William Roeder  
Musngi:

I modified some parts of code.

What I don't understand are the 4/5 digits broker code computation, Ask/Bid, Takeprofit and Stoploss. How can I put the Stoploss below/above the wicks of candle??

It pissed me off when I need to calculate this, instead of putting number of stoploss and takeprofit in that built-in function OrderSend().

After four (4) years, you don't understand 4/5 digits? I had you listed in 2016 as a troll with your vague questions and absurd responses. Apparently you haven't changed. So I will mark you again, and ignore you.
Musngi
470
Musngi  
whroeder1:
After four (4) years, you don't understand 4/5 digits? I had you listed in 2016 as a troll with your vague questions and absurd responses. Apparently you haven't changed. So I will mark you again, and ignore you.

OMG! This forums is not beginner friendly. Only the Elitist are welcome here? 

My question very simple I ask if this code calculation is correct, and Is this code updated or not, and asking some tips/advice.

If you not willing to help beginner then please don't comment.


If TradingView supported my brokers, I will not used this MetaTrader platform. I feel that average users is not welcome in Metatrader community.

To add comments, please log in or register