What Custom Indicators CAN'T do ? - page 2

 
Daniel Cioca #:

So your next project is actually learning mql .. :))) 

Yes, that is indeed true. 

As a hobby coder that spends short burst of learning and coding, many things are forgotten and need to be relearned or refreshed.
The continued process of learning and relearning mql will likely continue to be part of each new code project for years to come. 

I do wish I had more time to read and code.
Seems like I get going and make interesting code then life happens and a year or more may go by before I can get back to it. 

  



 
Agent86 #:

Yes, that is indeed true. 

As a hobby coder that spends short burst of learning and coding, many things are forgotten and need to be relearned or refreshed.
The continued process of learning and relearning mql will likely continue to be part of each new code project for years to come. 

I do wish I had more time to read and code.
Seems like I get going and make interesting code then life happens and a year or more may go by before I can get back to it. 

  



You can start here :  https://book.mql4.com/

MQL4 Tutorial
MQL4 Tutorial
  • book.mql4.com
MQL4 Tutorial
 
Agent86:
Hi all, 

I guess what I really need to plan my next project is a generalized list of what custom indicators CAN'T do. vs what EA's CAN'T do. 

Or at least some main feature differences that might guide me in deciding EA vs Indicator. 

Please advise
Thanks

In addition to what has been said, let me express my thoughts.

It is important to understand that one EA works in its own separate thread, while all indicators of one instrument work in one thread, regardless of the number of open windows for one instrument.

A universal approach can be applied to indicators and advisers. What is an indicator? This is the processing of an array of historical data and the formation of their own arrays, which are placed in indicator buffers (including for visualization), which EA has access to. But you can create a universal indicator class that can be used both in the indicator and in EA. Moreover, it is advisable not to use indicator buffers, which are of the double type, but to use your own arrays of structures, which are more convenient to work with and which are more economical in terms of memory consumption. Visualization of the indicator can be done through Canvas. This will allow you to have the same visualization in both the indicator and EA, which is impossible to have when using standard buffer indicators. This approach will have some advantages for EA, as it will be able to optimize and manage the graphical output so as not to overload the processor with graphics at the time of making trade decisions and placing orders. Also, the advantage of this approach will be cross-platform, that is, it will work the same in MT4 and MT5.

I understand that you will have many questions. I guess it makes sense for me to write an article with a specific example.

 
Nikolai Semko #:

In addition to what has been said, let me express my thoughts.

It is important to understand that one EA works in its own separate thread, while all indicators of one instrument work in one thread, regardless of the number of open windows for one instrument.

A universal approach can be applied to indicators and advisers. What is an indicator? This is the processing of an array of historical data and the formation of their own arrays, which are placed in indicator buffers (including for visualization), which EA has access to. But you can create a universal indicator class that can be used both in the indicator and in EA. Moreover, it is advisable not to use indicator buffers, which are of the double type, but to use your own arrays of structures, which are more convenient to work with and which are more economical in terms of memory consumption. Visualization of the indicator can be done through Canvas. This will allow you to have the same visualization in both the indicator and EA, which is impossible to have when using standard buffer indicators. This approach will have some advantages for EA, as it will be able to optimize and manage the graphical output so as not to overload the processor with graphics at the time of making trade decisions and placing orders. Also, the advantage of this approach will be cross-platform, that is, it will work the same in MT4 and MT5.

I understand that you will have many questions. I guess it makes sense for me to write an article with a specific example.

Thanks, 

I think I understand this. 
It's always confused me which direction to start with when testing trade ideas and the slow process due to my inexperience and intermittent times to work on them.
I end up with both indicator and EA and then have to figure out how to combine the 2 things together to work properly somehow. Only to find out that some of the code I wrote isn't exactly compatible with an EA or vise versa. Then the idea evolves and I struggle to combine the 2 or 3 ideas rolled up into one project.  

I'll have some time to do some reading for the next couple months so hopefully I can become more familiar with these things you outlined.
This sounds like exactly what I need to focus on. 
Thanks


 
Nikolai Semko #:

 EA. Moreover, it is advisable not to use indicator buffers, which are of the double type, but to use your own arrays of structures, which are more convenient to work with and which are more economical in terms of memory consumption. Visualization of the indicator can be done through Canvas. 

Hi! Can you please explain that a little deeper?

 
Daniel Cioca #: Hi! Can you please explain that a little deeper?

Indicators cover the entire span of the chart data, and use "double" 8 bytes for each bar, per plot (that is a lot of RAM usage), even if just to have a simple buy/sell arrows plot.

However, sometimes one only needs to store a simple state 'buy/sell/do nothing' which could easily be stored in less than a byte, or maybe one only needs to keep track of say the last 50 bars for a simple SMA and not the entire bar history.

So, in essence, using the indicator buffers can many times be overkill and a waste of resources (both RAM and CPU) for an EA which may not even need to display anything at all to do its job as efficiently as possible.

 
Fernando Carreiro #:

Indicators cover the entire span of the chart data, and use "double" 8 bytes for each bar, per plot (that is a lot of RAM usage), even if just to have a simple buy/sell arrows plot.

However, sometimes one only needs to store a simple state 'buy/sell/do nothing' which could easily be stored in less than a byte, or maybe one only needs to keep track of say the last 50 bars for a simple SMA and not the entire bar history.

So, in essence, using the indicator buffers can many times be overkill and a waste of resources (both RAM and CPU) for an EA which may not even need to display anything at all to do its job as efficiently as possible.

Ok..Thank you for that!


So just to make sure I understood:

instead of that:

double ma= iMA(_Symbol,_Period,MaPeriod,MAShift,MaMethd,MaAppliedPrice,1);

is better to use that:

input int LoockBack=500;
   double MA[];
   
   
   ArrayResize(MA,LoockBack);
  for(int i = LoockBack-1;i>=0;i--)
   {
   MA[i]=iMA(_Symbol,_Period,MaPeriod,MAShift,MaMethd,MaPlliedPrice,i);
   }
   double ma = MA[1];
 
Daniel Cioca #: Ok..Thank you for that! So just to make sure I understood: instead of that: is better to use that:

No! That is still using the iMA() which is an Indicator.

Instead you would need to calculate the Moving Average data itself in the EA with something like the functions in the "MovingAverages.mqh" file but doing it more efficiently if possible, as even the functions in that file are somewhat inefficient.

 
Fernando Carreiro #:

No! That is still using the iMA() which is an Indicator.

Instead you would need to calculate the Moving Average data itself in the EA with something like the functions in the "MovingAverages.mqh" file but doing it more efficiently if possible.

Although I only understand the code parts vaguely, I do understand the need to use less ram especially when using an EA on a VPS that typically has budget cost for lower resources such as 512GB slice or 1GB slice or something like that. 

So to be sure I get this mostly. I NOT be using the indicators in an EAs. This would be the same as creating an iCustom indictor and using a buffer that counts all back all Bars to calculate and draw on the chart which is a waste of resources for something like a Text Label that only needs to show Bar 0 price or something. Or may only need 3 or 4 Bars for a fractal High[0] ?  So avoid if possible. 

I'm not exactly sure how to write such a thing if the indicator itself uses this to calculate but I think I understand the instruction. I guess after some more reading I will get more inside exactly on what this type of code might look like that uses less resources to calculate part of an indicator etc. 

Thanks all. This will be good for my list of notes of where to focus my reading etc. 

However, this does further complicate things for me while learning too. 

 


 
Agent86 #:

Although I only understand the code parts vaguely, I do understand the need to use less ram especially when using an EA on a VPS that typically has budget cost for lower resources such as 512GB slice or 1GB slice or something like that. 

So to be sure I get this mostly. I NOT be using the indicators in an EAs. This would be the same as creating an iCustom indictor and using a buffer that counts all back all Bars to calculate and draw on the chart which is a waste of resources for something like a Text Label that only needs to show Bar 0 price or something. Or may only need 3 or 4 Bars for a fractal High[0] ?  So avoid if possible. 

I'm not exactly sure how to write such a thing if the indicator itself uses this to calculate but I think I understand the instruction. I guess after some more reading I will get more inside exactly on what this type of code might look like that uses less resources to calculate part of an indicator etc. 

Thanks all. This will be good for my list of notes of where to focus my reading etc. 

However, this does further complicate things for me while learning too.

My advice, is to ignore all this, and first focus on doing simple things with MQL and slowly build on your knowledge. Consider this information only once you have been successful at coding your own basic Indicators and basic EAs based on them. Only then will you be able to apply the knowledge mentioned here anyway.

Reason: