Translate simple MQL4 indicator to MQL5

MQL5 Indicators

Job finished

Execution time 4 hours

Specification

Good afternoon,

I have a simple MT4 indicator I would like translated to MQL5, keeping code structure, functions, constants and comments.

The indicator has four buffers: two lines and two arrows, draws rectangles and labels, implements alerts and ignores unclosed bar.

The indicator is barely 200 lines with heavy comments. See below.


//+------------------------------------------------------------------+
//| ExampleIndicator.mq4
//+------------------------------------------------------------------+
#property copyright "Flaab"
#property link      "None"

//--- constants 
#define  OLabel    "ExLabel"
#define  ShortName "Example Indi"
#define  Shift     1

//---- indicator settings
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 DodgerBlue
#property indicator_color2 Red
#property indicator_color3 DodgerBlue
#property indicator_color4 Red
#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 2
#property indicator_width4 2

//---- indicator parameters
extern string Settins         = "------- Settings";
extern int    TradePeriod     = 20;     
extern int    TimingPeriod    = 3;     
extern color  BullBox         = LightBlue;
extern color  BearBox         = LightSalmon;
extern color  BullLabel       = DodgerBlue;
extern color  BearLabel       = Red;
extern string Alerts_ex       = "------- Alerts";
extern string AlertCaption    = "My Alert Name";
extern bool   DisplayAlerts   = true;
extern bool   EmailAlerts     = false;
extern bool   PushAlerts      = false;
extern bool   SoundAlerts     = false;
extern string SoundFile       = "alert.wav";

//---- indicator buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double TrendDirection[];

//---- internal
static int      AlertTriggered;
static datetime TimeStamp;
static int      AlertCount = 1;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   // 4 Visible buffers + invisible one
   IndicatorBuffers(5);
   
   // Drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_ARROW); SetIndexArrow(2,233);
   SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,234);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
   
   // Buffers
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexBuffer(4,TrendDirection);   // Invisible buffer.
   
   // Delete old objects 
   DeleteObjects();
   return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
void DeleteObjects()
{
   int obj_total=ObjectsTotal();
   for(int i = obj_total - 1; i >= 0; i--)
     {
       string label = ObjectName(i);
       if(StringFind(label, OLabel)==-1) continue;
       ObjectDelete(label); 
     }     
}
int deinit()
{
   DeleteObjects();
   return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   // More vars here too...
   int start = 1;
   int limit;
   int counted_bars = IndicatorCounted();

   // check for possible errors
   if(counted_bars < 0) 
      return(-1);
        
   // Only check these
   limit = Bars - 1 - counted_bars;
   
   // Comment account info
   CommentInfo();
     
   // Iterate from past to present
   // Ignore unclosed bar!
   for(int i = limit; i >= start; i--)
   {           
      // Highest and Lowest of the last N bars 
      double rhigh = iHigh(Symbol(),Period(),iHighest(Symbol(), Period(), MODE_HIGH, TradePeriod,i+1));
      double rlow  = iLow(Symbol(),Period(),iLowest(Symbol(), Period(), MODE_LOW, TradePeriod, i+1));
      double bhigh = iHigh(Symbol(),Period(),iHighest(Symbol(), Period(), MODE_HIGH, TimingPeriod,i+1));
      double blow  = iLow(Symbol(),Period(),iLowest(Symbol(), Period(), MODE_LOW, TimingPeriod, i+1));
    
      // Do not allow retracements 
      if(ExtMapBuffer1[i+1] != EMPTY_VALUE && rlow < ExtMapBuffer1[i+1]) rlow =  ExtMapBuffer1[i+1];
      if(ExtMapBuffer2[i+1] != EMPTY_VALUE && rhigh > ExtMapBuffer2[i+1]) rhigh =  ExtMapBuffer2[i+1];
         
      // Preserve trend direction
      TrendDirection[i] = TrendDirection[i+1];
         
      // Reset buffers
      ExtMapBuffer1[i] = EMPTY_VALUE;
      ExtMapBuffer2[i] = EMPTY_VALUE;
      ExtMapBuffer3[i] = EMPTY_VALUE;
      ExtMapBuffer4[i] = EMPTY_VALUE;
      
      // No Alert by default
      AlertTriggered = EMPTY_VALUE;
         
      //-- Check for uptrend
      if(Close[i] > rhigh && TrendDirection[i+1] != OP_BUY)
      {  
         AlertTriggered = OP_BUY;
         TrendDirection[i] = OP_BUY;
         ExtMapBuffer3[i] = rlow;
         
      //-- Check for downtrend
      } else if(Close[i] < rlow && TrendDirection[i+1] != OP_SELL) {
            
         AlertTriggered = OP_SELL;
         TrendDirection[i] = OP_SELL;
         ExtMapBuffer4[i] = rhigh;
      }
         
      // Draw lines 
      if(TrendDirection[i] == OP_BUY)  ExtMapBuffer1[i] = rlow;
      if(TrendDirection[i] == OP_SELL) ExtMapBuffer2[i] = rhigh;
      
      // Breakouts / Rectangles
      if(TrendDirection[i] == OP_BUY && Close[i] > bhigh && bhigh <= High[i+TimingPeriod])
      {
         DrawRectangle(i, TimingPeriod+1, BullBox);
         DrawLabel("Buy", i + MathCeil(TimingPeriod/2), OP_BUY, BullLabel);
      } else if(TrendDirection[i] == OP_SELL && Close[i] < blow && blow >= Low[i+TimingPeriod]){
         DrawRectangle(i, TimingPeriod+1, BearBox);
         DrawLabel("Sell", i + MathCeil(TimingPeriod/2), OP_SELL, BearLabel);
      }
   }
   
   // Alerts
   if(TimeStamp != Time[0])
   { 
      if(AlertTriggered == OP_BUY && AlertCount == 0)
      {
            if(DisplayAlerts == true) { Alert(ShortName +" ("+ AlertCaption +") ["+ Symbol() +"] BUY"); }
            if(PushAlerts == true)    { SendNotification(ShortName +" ("+ AlertCaption +") ["+ Symbol() +"] BUY"); }
            if(EmailAlerts == true)   { SendMail(ShortName +" ("+ AlertCaption +") ["+ Symbol() +"]", Symbol() +": BUY"); }
            if(SoundAlerts == true)   { PlaySound(SoundFile); }
      } else if (AlertTriggered == OP_SELL && AlertCount == 0) {
            if(DisplayAlerts == true) { Alert(ShortName +" ("+ AlertCaption +") ["+ Symbol() +"] SELL"); }
            if(PushAlerts == true)    { SendNotification(ShortName +" ("+ AlertCaption +") ["+ Symbol() +"] SELL"); }
            if(EmailAlerts == true)   { SendMail(ShortName +" ("+ AlertCaption +") ["+ Symbol() +"]", Symbol() +": SELL"); }
            if(SoundAlerts == true)   { PlaySound(SoundFile); }
      } 
      TimeStamp = Time[0];
      AlertCount = 0;
   }
   return(0);
}

/**
* Comments account info
*/
void CommentInfo()
{
   double balance = AccountBalance();
   double spread  = MarketInfo(Symbol(), MODE_SPREAD);
   Comment("Account Balance: "+ DoubleToStr(balance, 2) +"\n"+
           "Spread: "+ DoubleToStr(spread, 0) +" pts\n"+
           "Quote: "+ DoubleToStr(Bid, Digits) +"/"+ DoubleToStr(Ask, Digits));
}

/**
* Draws a rectangle
* @param    int   shift    Relative bar for rectangle 
* @param    int   pshift   Past bar for rectangle
* @param    int   vcolor   Color of rectangle
*/
void DrawRectangle(int shift, int pshift, color vcolor)
{
   // Times for rectangle
   datetime x1 = Time[shift];
   datetime x2 = Time[shift+pshift-1];
   
   // Label
   string label = OLabel +"Rect-"+ pshift + x2;
   
   // Prices for rectangle
   double rhigh = iHigh(Symbol(),Period(),iHighest(Symbol(), Period(), MODE_HIGH, pshift, shift));
   double rlow  = iLow(Symbol(),Period(),iLowest(Symbol(), Period(), MODE_LOW, pshift, shift));
   
   // Draw
   ObjectCreate(label, OBJ_RECTANGLE, 0, x1, rlow, x2, rhigh);
   ObjectSet(label, OBJPROP_COLOR, vcolor);
   ObjectSet(label, OBJPROP_BACK, true);
}

/**
* Draws a label 
* @param    string   text     Text to display
* @param    int      shift    Bar to display the text 
* @param    int      vType    OP_BUY is above the bar, OP_SELL below the bar 
* @param    color    vcolor   Color of the text
*/
void DrawLabel(string text, int shift, int vType, color vcolor)
{
   // Time
   datetime x1 = Time[shift];
   datetime x2 = Time[shift+1];
   double vPrice;
   
   // Color 
   if(vType == OP_BUY) 
   {
      vPrice = Low[shift];
   } else {
      vPrice = High[shift] + iATR(Symbol(), 0, 30, Shift)*0.90;
   }
   
   // Label
   string label = OLabel +"-"+ text +"-"+ x2;
   ObjectCreate(label, OBJ_TEXT, 0, x2, vPrice);
   ObjectSetText(label, text, 8, "Tahoma", vcolor);
   ObjectSet(label, OBJPROP_BACK, true);
}

Responded

1
Developer 1
Rating
(8)
Projects
24
38%
Arbitration
4
50% / 0%
Overdue
9
38%
Free
2
Developer 2
Rating
(337)
Projects
624
38%
Arbitration
40
23% / 65%
Overdue
93
15%
Free
Published: 4 articles, 19 codes
Similar orders
‎A trending candle followed by a smaller trending candle which is the second candle with no 5EMA ‎ ‎The 3rd candle is a reversal candle in which it and it's immidiate previous candle must be at least 70% of each other's body or equal body, with no 5EMA touch ‎ ‎the 3rd candle candle is followed immediately by the 4th candle which is the signal candle in which it and the 1st cabdle must be also at least 70% of
LynxMT5algo 30 - 100 USD
An mt5 add on indicator like gainalgo style to show entrance and exit areas for gold silver and Btc scalping. It will be used to make trading more easy for beginners
I have the Fisher Indicator shown below the chart. I need an alert added for when the Fisher Indicator hits the 50 point at the end of each period. GBPUSD and EURUSD 4H charts are provided and I can provide additional
Hello here, I need someone who can work on pinescript and also with Renko charts. My entries for my strategy would be based on stop orders Kindly let me know if you can work on this for me and i will send necessary file and quote in the chat
Freelance Task — EA Recovery Layer Hello. I have a ready-made MQL5 EA. The signals, SL/TP and lot calculation should essentially not be touched. I need a recovery system added. I am not a programmer — below is how the robot should behave. What stays Entry only from an EA signal. Stop-loss is not a new signal. Trailing is already built into my EA — recovery does not implement its own trailing. If trailing is disabled
# SNRZ BOT — SESSION PROGRESS LOG Last updated: 2026-09-16 (local late-evening session) ## SAN BOT (new — cloned from SNRZ) - `MQL5\Experts\AutomatedOrderBot_SAN.mq5` / `.ex5` — v1.0, compiled 0 errors/0 warnings - Signal source: custom indicator "SAN" (InpSANName, buy buf 0 / sell buf 1, target bar 1), same SNRZ-style read, MA fallback if missing - Magic number 234567 (separate from SNRZ 123456 so both bots can run
Should be as it but no alarms, also we need to add a deep search so he can see all the preves candles and a memory function so its not slowing down the indicator. for higher time frames daily 4h 1h around 365 days and for lower time frames we do up to 20k bars but both flexible so i can change it later. the memory is important so the indicator is not always recalculating everything when a new candle shows especially
Hi, I need an experienced NinjaTrader 8/NinjaScript developer to finish or rebuild an automated futures strategy, ideally by the end of this week. I already have the complete TradingView Pine Script reference strategy, an existing ~2,000-line NinjaScript implementation, Playback logs, and known historical benchmark trades. MOST IMPORTANT REQUIREMENT: TRADINGVIEW ↔ NINJATRADER PARITY. The Pine Script is the reference
I need a custom MQL5 indicator for MetaTrader 5. The indicator must automatically print entry, stop loss, and take profit zones on the chart using dots. A critical requirement is that these dots must be non-lagging and absolutely non-repainting. Additionally, the indicator needs to identify and display current supply and demand zones. Please provide the mq5 source code and the ex5 file upon completion
I need an experienced trading-data specialist who can help me obtain 3–4 years of historical market data compatible with NinjaTrader 8 . The data will be used for trading strategy development, backtesting, and analysis

Project information

Budget
10 - 100 USD
Deadline
to 5 day(s)