Questions from Beginners MQL5 MT5 MetaTrader 5 - page 869

 
Sergey Savinkin:

It works. ))

And what a clever forum engine... You provided the link yourself where there are full instructions on how to paste the code.

 
Alexey Viktorov:

And really... why strive to be better...

Count how much extra code is written in these functions and how much code you write by calling these self-written functions.

I strive to be better at trading, and I need coding to move towards that goal.

If the difference will be 0.1 second at the end of the year, is there any point in bothering?

Can you show me how to make this code without functions and speed it up?

 
Aleksey Vyazmikin:

I am striving to be better at trading, and I need coding to move towards that goal.

If the difference will be 0.1 second at the end of the year, is there any point in bothering?

Can you show me how to make this code without functions and speed it up?

That's how you have it all written. Only it's all wrapped under mql4. Can't you do without such a wrapper?

And this is

Forum on trading, automated trading systems and strategy testing

FAQ from Beginners MQL5 MT5 MetaTrader 5

Aleksey Vyazmikin, 2018.05.24 12:30

All collected by bits and pieces, but the main body of similar functions I took originally from here, really don't know what's left of it.

ENUM_TIMEFRAMES TFMigrate(int tf)
  {
   switch(tf)
     {
      case 0: return(PERIOD_CURRENT);
      case 1: return(PERIOD_M1);
      case 5: return(PERIOD_M5);
      case 15: return(PERIOD_M15);
      case 30: return(PERIOD_M30);
      case 60: return(PERIOD_H1);
      case 240: return(PERIOD_H4);
      case 1440: return(PERIOD_D1);
      case 10080: return(PERIOD_W1);
      case 43200: return(PERIOD_MN1);

      case 2: return(PERIOD_M2);
      case 3: return(PERIOD_M3);
      case 4: return(PERIOD_M4);
      case 6: return(PERIOD_M6);
      case 10: return(PERIOD_M10);
      case 12: return(PERIOD_M12);
      case 16385: return(PERIOD_H1);
      case 16386: return(PERIOD_H2);
      case 16387: return(PERIOD_H3);
      case 16388: return(PERIOD_H4);
      case 16390: return(PERIOD_H6);
      case 16392: return(PERIOD_H8);
      case 16396: return(PERIOD_H12);
      case 16408: return(PERIOD_D1);
      case 32769: return(PERIOD_W1);
      case 49153: return(PERIOD_MN1);
      default: return(PERIOD_CURRENT);
     }
  }

It's just quiet awful.... What's this all about???

It's not really a course. Sorry, no more criticism.

 
Alexey Viktorov:

That's how you have it all written. Only it's all wrapped in mql4. Can't you do without such a wrapper?

And this...


is just plain awful... What's this all about?

And in general it's not the courses here. Sorry, no more criticism.

Well, since there's no desire to show how to do it better for beginners...

I don't see the horror, in MT4 the time period is often designated by digits divisible by minutes, which is not logical to do in MT5, but it allows easier porting of code.

 
Aleksey Vyazmikin:

Well, since there's no desire to show the best way for beginners...

I don't see the horror, in MT4 the time period is often denoted by numbers divisible by minutes, which is not logical to do already in MT5, but makes it easier to port the code.

Why would you translate it into number of minutes and then put it back?

Is 16408 more understandable than PERIOD_D1 or 49153 more understandable than PERIOD_MN1?

Периоды графиков - Константы графиков - Стандартные константы, перечисления и структуры - Справочник MQL4
Периоды графиков - Константы графиков - Стандартные константы, перечисления и структуры - Справочник MQL4
  • docs.mql4.com
Все предопределенные периоды графиков имеют уникальные идентификаторы. Идентификатор PERIOD_CURRENT означает текущий период графика, на котором запущена mql4-программа. Перечисление ENUM_TIMEFRAMES содержит значения стандартных таймфреймов, онлайновые графики финансовых...
 

Hello, in the EA I want to know the current value of ATR from the high period of the chart. An integer value.

#include <Trade\SymbolInfo.mqh> 
CSymbolInfo    m_symbol;
//===
input int             ATRper=7;         //ATR Period
input ENUM_TIMEFRAMES ATRtimeframe=PERIOD_CURRENT;//«Time_Frame_ ATR»
int            handle_iCustom;
double atr_tp;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   if(!m_symbol.Name(Symbol())) // sets symbol name
      return(INIT_FAILED);
   handle_iCustom=iATR(m_symbol.Name(),ATRtimeframe,ATRper);
//--- if the handle is not created 
   if(handle_iCustom==INVALID_HANDLE)
     {
      //--- tell about the failure and output the error code 
      PrintFormat("Failed to create handle of the iCustom indicator for the symbol %s/%s, error code %d",
                  m_symbol.Name(),
                  EnumToString(Period()),
                  GetLastError());
      //--- the indicator is stopped early 
      return(INIT_FAILED);
     }
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   int Bar_=0;
   atr_tp= iCustomGet(handle_iCustom  ,0,Bar_);
   atr_tp=NormalizeDouble(atr_tp,Digits())/_Point;
   atr_tp=(int)atr_tp;
   Comment("atr_",atr_tp);
  }
//+------------------------------------------------------------------+
double iCustomGet(int handle,const int buffer,const int index)
  {
   double Custom[1];
//--- reset error code 
   ResetLastError();
//--- fill a part of the iCustom array with values from the indicator buffer that has 0 index 
   if(CopyBuffer(handle,buffer,index,1,Custom)<0)
     {
      //--- if the copying fails, tell the error code 
      PrintFormat("Failed to copy data from the iCustom indicator, error code %d",GetLastError());
      //--- quit with zero result - it means that the indicator is considered as not calculated 
      return(0.0);
     }
   return(Custom[0]);
  }
///

Where is the error?

 
lil_lil:

Hello, in the EA I want to know the current value of ATR from the high period of the chart. An integer value.

Where is the error?

What does it say? What is it saying?

 
Sergey Savinkin:

What does it say? What's he swearing about?

It's not, it's lying. The indicator on the high shows "8", but the advisor says "6" in the commentary

 
lil_lil:

It doesn't swear, it lies. The indicator on the high shows "8", but in the comment the EA says "6".

I have run your EA on a period of 5 minutes, period ATR 14, time frame ATR - 1 hour. Everything is showing evenly, both in the comments and on the chart.

 
lil_lil:

It's lying on my current one too, with ATRtimeframe=PERIOD_CURRENT


I don't think it's about the code at all. Here's my PERIOD_CURRENT


Reason: