Download MetaTrader 5

Converting MT4 Indicator to MT5

To add comments, please log in or register
pauleamonn
56
pauleamonn  

Oooops, I think I posted this in the wrong forum!  Sorry.  I've copied it here in the hope that someone may be able to help me.  After I got no reply I tried again to sort it out myself but just cannot seem to be able to work it out.

 

Hi All

Yesterday I had MT4 and on it I had a simple indicator that showed me both the 14 day ATR and the current range of today's price action in numbers in a 'Comment' in the top left corner of the chart.  The code I used was this-

 

       double My_ATR=iATR(NULL,1440,periods,1);

       double todays_range=iHigh(NULL,1440,0)-iLow(NULL,1440,0);

       Comment("\n14 day ATR = ",My_ATR,"   Todays Range = ",todays_range);

 

As you can see it is very simple and displays the extent of my coding skills perfectly!

Today I have MT5 and decided I would like to show the same information in my charts.  I have spent the last 5 hours trying to work out MT5 coding and have failed miserably.  I have got to the stage where I have lost the will to live!  I am sure that the MT5 coding is far more reliable and versatile than its MT4 predecessor but........................it ain't for simple folk!

Can someone convert my little bit of code to the MT5 equivalent for me please along with all the bits and pieces that need to be declared, talked about, eluded to etc?

Thanks in advance.

Regards

Paul Eamonn  

FXLife888
77
FXLife888  
suggest dont have this idea,
mt4 and mt5 are not compatible!
please give up mql4
Tonny Obare
37054
Tonny Obare  
pauleamonn:

Oooops, I think I posted this in the wrong forum!  Sorry.  I've copied it here in the hope that someone may be able to help me.  After I got no reply I tried again to sort it out myself but just cannot seem to be able to work it out.

 

Hi All

Yesterday I had MT4 and on it I had a simple indicator that showed me both the 14 day ATR and the current range of today's price action in numbers in a 'Comment' in the top left corner of the chart.  The code I used was this-

 

       double My_ATR=iATR(NULL,1440,periods,1);

       double todays_range=iHigh(NULL,1440,0)-iLow(NULL,1440,0);

       Comment("\n14 day ATR = ",My_ATR,"   Todays Range = ",todays_range);

 

As you can see it is very simple and displays the extent of my coding skills perfectly!

Today I have MT5 and decided I would like to show the same information in my charts.  I have spent the last 5 hours trying to work out MT5 coding and have failed miserably.  I have got to the stage where I have lost the will to live!  I am sure that the MT5 coding is far more reliable and versatile than its MT4 predecessor but........................it ain't for simple folk!

Can someone convert my little bit of code to the MT5 equivalent for me please along with all the bits and pieces that need to be declared, talked about, eluded to etc?

Thanks in advance.

Regards

Paul Eamonn  

Yes https://www.mql5.com/en/job
MQL5 jobs
  • www.mql5.com
Orders for the development of automated trading programs
Daniel Lewis
85757
Daniel Lewis  

It's a sad day when someone is looking for money to display ATR and daily range on a chart.  WOW!!!!

#property indicator_chart_window
#property indicator_plots 0

//--- User Inputs
input int ATR_Period = 14;

//--- Global Variables
double ATR[1],
       High[1],
       Low[1];
int ATRhandle;

void OnInit() {
   ATRhandle = iATR(NULL,PERIOD_D1,ATR_Period);
   ArraySetAsSeries(ATR,true);
   return;
}

void OnDeinit(const int reason) {
   IndicatorRelease(ATRhandle);
   Comment("");
   return;
}

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const int begin,
                const double &price[]) {
   CopyBuffer(ATRhandle,0,1,1,ATR);
   CopyHigh(NULL,PERIOD_D1,1,1,High);
   CopyLow(NULL,PERIOD_D1,1,1,Low);
   Comment("\n"+(string)ATR_Period+" day ATR = "+DoubleToString(ATR[0],_Digits)+"   Todays Range = "+DoubleToString(High[0]-Low[0],_Digits));
   return(rates_total);
}

 

To add comments, please log in or register