Help with MT5 Code

 
Some One help me fix this CODE

the problems i face are:
1-suppose the atr value is 0.00589, i want it to be 589.
2-the correct atr value of the current bar never gets returned.

There is a huge problem with iATR or I simple can not use it properly so please teach me

#property indicator_separate_window

#property indicator_buffers   1

#property indicator_plots     1



#property indicator_type1     DRAW_LINE

#property indicator_style1    STYLE_SOLID

#property indicator_color1    clrBlanchedAlmond

#property indicator_width1    2



double   atr_spread[];



input int   Y  = 100;



//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int OnInit()

  {

   SetIndexBuffer(0,atr_spread,INDICATOR_DATA);

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//|                                                                  |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,const int prev_calculated,

                const datetime &time[],const double &open[],

                const double &high[],const double &low[],

                const double &close[],const long &tick_volume[],

                const long &volume[],const int &spread[])

  {

   for(int i=prev_calculated; i<rates_total; i++)

     {

      int x  =(((iATR(_Symbol,PERIOD_CURRENT,Y))*(10^Digits()) / MODE_SPREAD) -1);

      atr_spread[i] = x;

     }

   return(rates_total);

  }

//+------------------------------------------------------------------+

Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
Documentation on MQL5: Language Basics / Preprocessor / Program Properties (#property)
  • www.mql5.com
Program Properties (#property) - Preprocessor - Language Basics - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Mahir Muhtasim Alam Khan:

I Found this old code in MT4 Language, I need Help to turn it into MT5


First of all make it work in MQL4 - then paste it into MQL5 and resolve the issues.

I did a small migration some time back and I paste my notes below to give you an idea of some things you may need to change (I am sure there are others)


Functions

·        DoubleToStr                                   Now DoubleToString

·        TimeToStr                                        Now TimeToString

·        Time measurements                   use MqlDateTime structuture to get hh, mm, secs.
                                                             GetMicrosecondCount() gives runtime of program

·        StringConcatenate                       Now use manual join “str1” + “str2”

·        Bid/Ask price retrieval                Now use MqlTick  structure and SymbolInfoTick() to read prices and other data

·        AccountBalance()                         New MQL function is AccountInfoDouble(ACCOUNT_BALANCE)

·        iMA                                                     Last parameter obsolete (shift)
                                                             Null string for Symbol() must be NULL – not “” like in MQL4

·        “extern” keyword                        must use “input” keyword in MQL5

·        OrderSend                                       different function which uses MQLTradeRequest and MQLTradeResult structures

 

Array initialization

string         outputReport[] = {“”};     // No longer suitable in MQL5 – creates a static array which cannot be re-sized

 
R4tna C #:

First of all make it work in MQL4 - then paste it into MQL5 and resolve the issues.

I did a small migration some time back and I paste my notes below to give you an idea of some things you may need to change (I am sure there are others)


Functions

·        DoubleToStr                                   Now DoubleToString

·        TimeToStr                                        Now TimeToString

·        Time measurements                   use MqlDateTime structuture to get hh, mm, secs.
                                                             GetMicrosecondCount() gives runtime of program

·        StringConcatenate                       Now use manual join “str1” + “str2”

·        Bid/Ask price retrieval                Now use MqlTick  structure and SymbolInfoTick() to read prices and other data

·        AccountBalance()                         New MQL function is AccountInfoDouble(ACCOUNT_BALANCE)

·        iMA                                                     Last parameter obsolete (shift)
                                                             Null string for Symbol() must be NULL – not “” like in MQL4

·        “extern” keyword                        must use “input” keyword in MQL5

·        OrderSend                                       different function which uses MQLTradeRequest and MQLTradeResult structures

 

Array initialization

string         outputReport[] = {“”};     // No longer suitable in MQL5 – creates a static array which cannot be re-sized

Could you help me fix this code please

the one above

 

Forum on trading, automated trading systems and testing trading strategies

When you post code please use the CODE button (Alt-S)!

Use the CODE button

 
Sergey Golubev #:

thank you

 
had a similar problem, thank you!
 

You have Fixed it and How?

Could you share it

Reason: