Questions from Beginners MQL5 MT5 MetaTrader 5 - page 162

 

I wrote the simplest indicator in mql4, I wanted to translate it to mql5, and I have been struggling for a week, but it is not working! I'm getting on my nerves, I hate mql5 because I have already written 88 lines of a simple 34-line indicator in mql5!

Here is the code on mql4:

#property indicator_separate_window
#property  indicator_level1 0
#property indicator_buffers 3

extern int kol_vo_bar = 15;
extern string Symbol_1 = "GBPJPY";
extern string Symbol_2 = "EURJPY";

double SpreadA[];
double SpreadB[];
double Spread[];

int init()
{
   SetIndexBuffer(0,SpreadA);
   SetIndexBuffer(1,SpreadB);
   SetIndexBuffer(2,Spread);
   SetIndexStyle(0,DRAW_SECTION,EMPTY,2,Red);
   SetIndexStyle(1,DRAW_SECTION,EMPTY,2,Blue);
   SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,1,Gray);
   return(0);
}

int start()
{
   int k;
   for(k = 0; k < iBars(Symbol_1,0); k++)
   {
            SpreadA[k] = iClose(Symbol_1,0,k)*100/iOpen(Symbol_1,0,k+kol_vo_bar)-100;
            SpreadB[k] = iClose(Symbol_2,0,k)*100/iOpen(Symbol_2,0,k+kol_vo_bar)-100;                  
            Spread[k] = SpreadA[k]-SpreadB[k];
   }
   return(0);
}

And here is the code on mql5:

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_plots   3
//--- plot Label1
#property  indicator_label1  "Label1"
#property  indicator_type1   DRAW_SECTION
#property  indicator_color1  clrRed
#property  indicator_style1  STYLE_SOLID
#property  indicator_width1  2
//--- plot Label2
#property  indicator_label2  "Label2"
#property  indicator_type2   DRAW_SECTION
#property  indicator_color2  clrBlue
#property  indicator_style2  STYLE_SOLID
#property  indicator_width2  2

#property  indicator_label3  "Label3"
#property  indicator_type3   DRAW_HISTOGRAM
#property  indicator_color3  clrGray
#property  indicator_style3  STYLE_SOLID
#property  indicator_width3  1

//--- input parameters
input int kol_vo_bar=96;
input string   Symbol_1="GBPJPY";
input string   Symbol_2="EURJPY";
//--- indicator buffers
double         Label1Buffer[];
double         Label2Buffer[];
double         Label3Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,INDICATOR_DATA);
   SetIndexBuffer(1,Label2Buffer,INDICATOR_DATA);
   SetIndexBuffer(2,Label3Buffer,INDICATOR_DATA);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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 k=0; k<Bars(_Symbol,_Period); k++)
   {
            Label1Buffer[k] = iClose(Symbol_1,PERIOD_CURRENT,k)*100/iOpen(Symbol_1,PERIOD_CURRENT,k)-100;
            Label2Buffer[k] = iClose(Symbol_2,PERIOD_CURRENT,k)*100/iOpen(Symbol_2,PERIOD_CURRENT,k)-100;                  
            Label3Buffer[k] = Label1Buffer[k]-Label2Buffer[k];
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
double iClose(string symbol,ENUM_TIMEFRAMES tf,int index)
{
   if(index < 0) return(-1);
   double Arr[];
   if(CopyClose(symbol,tf,index,1,Arr)>0)
        return(Arr[0]);
   else return(-1);
}
double iOpen(string symbol,ENUM_TIMEFRAMES tf,int index)
{
   if(index < 0) return(-1);
   double Arr[];
   if(CopyOpen(symbol,tf,index+kol_vo_bar,1,Arr)>0)
        return(Arr[0]);
   else return(-1);
}

Indicator lines are not displayed correctly in MT5.

What have I done wrong?

Good people, help me, have pity on the poor guy, I'm on the verge of a breakdown, honestly. It's a shame you can't swear in here!

Moderator, don't ban me, first give me a warning if something is wrong.

 

You're recalculating all available bars on every tick, which is highly sub-optimal, and is terribly slow.

 
zlodei:


The indicator lines are not displayed correctly in MT5.

What did I write wrong?

Where is the work with PlotIndexXXX ?

did not allow you to read the documentation and examples?



Moderator, don't ban me, first give me a warning if something is wrong.

Go to the codebase and read it. There are hundreds of examples.
 
sergeev:

Where work with PlotIndexXXX ?

Too lazy to read documentation and examples?


Go to codebase and read it. there are hundreds of examples.

I wonder why this is needed at the beginning of the code:

#property  indicator_label1  "Label1"
#property  indicator_type1   DRAW_SECTION
#property  indicator_color1  clrRed
#property  indicator_style1  STYLE_SOLID
#property  indicator_width1  2

#property  indicator_label2  "Label2"
#property  indicator_type2   DRAW_SECTION
#property  indicator_color2  clrBlue
#property  indicator_style2  STYLE_SOLID
#property  indicator_width2  2

#property  indicator_label3  "Label3"
#property  indicator_type3   DRAW_HISTOGRAM
#property  indicator_color3  clrGray
#property  indicator_style3  STYLE_SOLID
#property  indicator_width3  1

All properties for each line are specified here? Or is it not enough for mql5, now I need to write properties of lines through PlotIndex?

I've read a lot of examples and documentation, I don't understand 80% of them, for example, why should I complicate simple things?

For example in mql4:

   SetIndexStyle(0,DRAW_SECTION,EMPTY,2,Red);
   SetIndexStyle(1,DRAW_SECTION,EMPTY,2,Blue);
   SetIndexStyle(2,DRAW_HISTOGRAM,EMPTY,1,Gray);

In mql5 now I can't even imagine how much specifying line styles can take, 50 lines probably, and the result is 1 and the same.

MQL5 is for PROGRAMMERS, MQL4 is for TRADERS. If you want to check the system, program it with mql4, and if you want the same thing with mt5, ask a programmer to do it, or stop trading and spend time studying mql5.

With the release of MT5, I, as a trader, noticed only one improvement, it is a 64 bit tester with the ability to use all CPU cores.

The sophistication of mql language will not affect the results of manual or automated trading in any way. The complication of the language is important for programmers, yes - we can make nice buttons and panels, integrate with all kinds of strange WinAPI, etc., but it has not affected the results of trading. So why all these difficulties when you can program in mql4, and check it, but there is only 1 BIG minus - there is no x64 terminal and tester with possibility to use all cores. If they would do these 2 things - there would be no price for MT4. But they will not make them on purpose, so that it would not create competition for MT5 and people like me would suffer or pay money.

Anyway thanks for your attention, for the "help". I do not comment, I will not go to the branch anyway, it's just my opinion, not more, I have to go.

 
I am new here. Can you tell me if i trade the rts index futures in mt5? How can i display a single quote chart from 2009 to today?
 
sbr080:
I am new here. Can you tell me if i trade the rts index futures in mt5? How do I print a quote chart from 2009 to today?
You have to ask your broker to give you the sticky chart.
 
barabashkakvn:
Ask your broker to give you a glued chart.
Can I glue it myself?
 
sbr080:
can I glue it together myself?
No. Only a broker. If you do it yourself, you will have to write your own indicator.
 
barabashkakvn:
No. Only a broker. If you do it yourself, you'll have to write your own indicator.
Thank you.
 
Can you advise whether it is possible for an Expert Advisor to display technical indicators on a chart with the parameters it uses? I.e. in the same way as when using visualisation in the strategy tester. I cannot find this information anywhere.
Документация по MQL5: Технические индикаторы
Документация по MQL5: Технические индикаторы
  • www.mql5.com
Технические индикаторы - Документация по MQL5
Reason: