Translate simple MQL4 indicator to MQL5

MQL5 Indicatori

Lavoro terminato

Tempo di esecuzione 4 ore

Specifiche

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);
}

Con risposta

1
Sviluppatore 1
Valutazioni
(8)
Progetti
24
38%
Arbitraggio
4
50% / 0%
In ritardo
9
38%
Gratuito
2
Sviluppatore 2
Valutazioni
(336)
Progetti
620
38%
Arbitraggio
39
23% / 64%
In ritardo
93
15%
Gratuito
Ordini simili
I would like to modify the RSI Epert Avisor with a developer. I would like to use the RSI Expert on the inverse mode and the base setting doesnt conatain this strategy mode
EA DEJA FABRIQUE ? MODIFIER QUELQUE LIGNE POUR LE RENDRE RENTABLE /////////////////////++++++++++++++++++++++++++++++++++ EA AVEC UN SYTEME SIMPLE ; SEULEMENT A MODIFIER %%%%%%%%%%%%%%%%%% SI PERSONNE SACHANT CODER CORRECTEMENT , CE TRAVAIL EST POUR TOI
Buy an sell symbols and guide showing entry to buy or sell setups and I need it gives and tell me to enter buy or to enter sell by automation nnnnnnnnnn fgggghhuuuiijh hhrddfhuuufffff yygggg hhgt hiidcb hygdfbby gyytdv uttrdd. Httdd hyyydv. Yhygf. Uu juhgff uyttt uuuytdbhy uuuyyy hhhff jjueeiivhgffdgu hyuu7trg yyyyffj yyytd u6tttf uuyrrrhi uytrrfh utterly jyrfgkkttv uhyybhhyy hytfgivuyt utfbh utghjio7t. Uuytg uytru
Utilizing the MQL5 MetaEditor Wizard, I created an Expert Advisor, having the following Signal indicators: I was able to optimize the EA and reached a backtest with the following specifications: I was able to reach a profit level of 30K, as indicated below. However, the Bot is not without faults and following the backtest, I started a forward test with real live data and the results were not so great. The EA took a
Connect from Mt5 via binary deriv account api I have mt5 indicator, need to connect with binary deriv account through api. If anyone can setup via API then contact me. everything control mt5
Hello I am looking for a developer to create an 50% retracement Indicator of the previous candle . So once a candle close the Indicator is supposed to take the full candle size from high to low and make a 61% and 50% level on that candle and I would like the candle to show until the next previous candle is done creating. After this I would look to create an ea with it possibly
Hi, I have 2 indicators which are based on the super trend , the alerts on indicator (1) does not work at all , and on the other indicator the alerts do not come on time on time, which is kind of delayed. see attached file below
Looking for an experienced developer to modify my existing TDI strategy , want to add filter for Buy and Sell Signals, Arrows are displayed on chart and what only to leave high accurate arrows Source code to be provided
I have the mq5 file, I need a buffer adding to the indicator, so it appears in the data window so I can reference it later in an EA. As the below screenshot shows, there is a median ray line from yesterday (the dashed horizontal line) - I want this value in the data window called Median Ray. I want this to be a single value per day, so todays Median Ray would be 17868, and so on each day. So I want all the Developing
I would like to develop my own indicator on metatrader 4 and tradingview. We would start with a basic version that we would improve later. It is an indicator based on several analyses and which would provide several indications. I am looking for someone who can develop on MT4 and Mt5, initially I would like to do it on mt4 and then on mt5. If you have expertise in pinescript it is a plus because I would like to

Informazioni sul progetto

Budget
10 - 100 USD
Per lo sviluppatore
9 - 90 USD
Scadenze
a 5 giorno(i)