Questions from Beginners MQL5 MT5 MetaTrader 5 - page 188

 
Vikon:

Hello!

I can't figure out which interval to display a graphical object

on all timeframes.

Thank you.

OBJ_ALL_PERIODS=2097151

Документация по MQL5: Стандартные константы, перечисления и структуры / Константы объектов / Видимость объектов
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы объектов / Видимость объектов
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы объектов / Видимость объектов - Документация по MQL5
 
C-4:
Does anyone know if the compiler has a key to get messages about unused functions and variables, like it is done in MQL4 ?

How is this done in mql4 ?

Asked about not displaying warnings about unused functions, Renat said it wouldn't. In connection with the use of pluggable libraries. It used to be in the old build. Now it isn't. It is very inconvenient to search for those functions in the EA body that are not used. It only talks about unused variables if it finds them in the body of a function, not start() or OnTick()

 
artmedia70:

How is it done in mql4 ?

Asked about not displaying warnings about unused functions, Renat said it wouldn't. Due to the use of plugin libraries. It used to be in the old build. Now it doesn't. It is very inconvenient to search for those functions in the EA body that are not used. It only talks about unused variables if it finds them in the body of a function, not start() or OnTick()

Because in OOP it's not functions, but methods. Each library may have a bunch of classes with many methods, some of which are not used. Additionally classes also refer to other libraries, some of methods of which are also not used. This can result in a huge mess of unused methods.

Judging by the amount of compiled code, the compiler automatically eliminates unused methods. I.e., there is no point in searching for them by yourself, because this work is done by the compiler.

 
Reshetov:

Because in OOP, not functions, but methods. Each library may have a bunch of classes with many methods, some of which are not used. Additionally, classes also refer to other libraries, some of whose methods are also unused. This can result in a huge stack of unused methods.

Judging by the size of the compiled code, the compiler automatically eliminates unused methods. That is, there is no point in looking for them by yourself because the compiler does this job.

This is not the problem. The problem is exactly finding unused methods in your classes. I have more than five hundred methods of my own. The interrelationships are very complex. Runtime code is inevitable. It might be very useful to have a quick look at what is not used anymore.
 
Reshetov:

Because in OOP, it's not functions, but methods. Each library may have a bunch of classes with many methods, some of which are not used. Additionally, classes also refer to other libraries, some of whose methods are also unused. This can result in a huge stack of unused methods.

Judging by the size of the compiled code, the compiler automatically eliminates unused methods. That is, there is no point in looking for them by yourself because the compiler does this job.

Yuri, this is natural. But when you give the source code to a customer, you want to clean it up. And so begins the tortuous process. There are not many templates - several for certain TC classes. I have to clean up functions that are not involved in this case. I would like to have a "magic button" that would point to unused functions and variables only in the EA body.
 

I hope the discussion of the previous question is over. It is difficult to know when the topic is closed and it is appropriate to ask your question. Can you give me a hint? I can't figure out how to fill one 2D array with results ofSt_handle andMA_handle calculations, I can only pass them to one-dimensional array.

/+------------------------------------------------------------------+
//|                                                           11.mq5 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "http://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100
#property indicator_buffers 1
#property indicator_plots   1
//--- plot Label1
#property  indicator_label1  "Label1"
#property  indicator_type1   DRAW_LINE
#property  indicator_color1  clrRed
#property  indicator_style1  STYLE_SOLID
#property  indicator_width1  1
//--- input parameters
input int      Input1=0;
input int      Input2=0;

//--- indicator buffers
double         Label1Buffer[];
double      MA[10000][400];  
int         St_handle; 
int         MA_handle; 
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Label1Buffer,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[])
  {
//---
   int Kp     =51; // с Kp начанается К% на Kp_end заканчивается
   int Kp_end =400;// с Kp начанается К% на Kp_end заканчивается
   int MAp    =2;  // с MAp начанается D% на MAp_end заканчивается
   int MAp_end=31// с MAp начанается D% на MA_end заканчивается
   ENUM_STO_PRICE price_field=1; // цена расчета стохастика 0 Low/High    1 Close/Close


   St_handle=iStochastic(NULL,0,Kp,1,1,MODE_EMA,price_field);  
  
   for(MAp=2;MAp<MAp_end;MAp++)
   {
    MA_handle=iMA(NULL,0,MAp,0,MODE_EMA,St_handle);
   }
    
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
C-4:
This is not the problem. The problem is exactly finding unused methods in your classes.

What do you mean: unused methods in your classes? This is not the practice in OOP. A normal OOP programmer, in contrast to algorithmic programming, creates classes with all the necessary fields and methods, as they say, for all occasions, because the same class may be later used in other applications or become a part of class library. Not to mention the fact that even within one project it is better to create full classes, not stripped-down, so that you don't have to search through the source code and add the required fields and methods later.

In OOP any economy, which many people get used to in algorithmic programming, may turn out to be detrimental later. Everything what is not used must be excluded from the code by the compiler and not by the programmer.

Of course, OOP results in a larger source code compared to algorithmic programming. But this is not a disadvantage, but an advantage, because much of the "extra" code in this project can be reused in other projects.

C-4:


I have over five hundred methods of my own. The interrelationships are very complex. Rudimentary code is unavoidable. It is very useful to quickly see what is not used anymore.

You shouldn't try to make a conundrum, i.e. to cram everything into one class. You need to create class libraries, i.e. break down the functionality into separate classes and don't forget to include comments on this stuff and then everything will sort itself out. Initially, when I started learning Java after Pascal, I too tried to do everything in one piece, i.e. instead of using OOP, I created one class with everything I needed for a certain task, just like in algorithmic programming. The result was a non-universal mess that was impossible to apply anywhere later, not to mention that it was hard to understand such code.
 
Andrei-1:

Can you give me a hint? I can't figure out how to fill one two-dimensional array withSt_handle andMA_handle calculation results, I can only pass them to one-dimensional array.

What is the point? I.e. why make a hump instead of using Occam's razor? I.e. what's the advantage of a two-dimensional array over two one-dimensional arrays? After all, you first need to shove something from two one-dimensional ones created by default indicators into a two-dimensional one, and then take something out of there. You are doing unnecessary work and trying to drag others into it.

If there was a problem with one-dimensional arrays, then it would be worth the trouble.

 
After poking around the forum I came across how much memory this will take, a lot! Decided to fill a one-dimensional array, look for a signal in it, overwrite and look for a signal again. still want 10K cycles. Like this. One or two searches per hour is enough for me.
St_handle=iStochastic(NULL,0,Kp,1,1,MODE_EMA,price_field); // создание хэндла стохастика 
  
   for(MAp=1;MAp<MAp_end;MAp++) //перебор сглаживаний 
   {
    MA_handle=iMA(NULL,0,MAp,0,MODE_EMA,St_handle); // создание хэндла сглаженного стохастика
    CopyBuffer(MA_handle,0,0,400,MA); // заполнение одномерного массива значениями стохастика
    if(MA[1]>6) Alert(MA[1]); // начинается поиск сигнала
    
   }
 

Sorry if this is off topic ...

help who can ...

in delphi 7 dll procedure...

procedure test1(var data: array of Double); stdcall;
begin
ShowMessage('Entered ');

end;

in mt4 :

#import "gayss.dll"
void test1( double &data[] );
#import

ArrayResize(data, 6);
data[0]= 2;
data[1]= 4;
data[2]= 8;
data[3]= 16;
data[4]= 21;

data[5]= 3;

test1(data);

and an error pops up... 2014.02.06 17:39:04.241 stack damaged, check DLL function call in 'SOG_2014.mq4' (80,7)

Who knows how to do it right...