Download MetaTrader 5

where am I wrong, so that I don't crash my pc?

To add comments, please log in or register
Carl Schreiber
Moderator
7955
Carl Schreiber  

Hi

I (Win7, 64, mt4, b1090) have an indicator CaVol with about 10 Parameter of which only the first two matters (the rest is for the presentation).

This indicator has 34 puffer. Now I wrote a second indicator CallingCaVol() that calls the first one - but only with the first two parameters - assuming that the others will taken by their default values

( simplified this call):

   int idxStick = MathRand()%10; // => 0..9
   
   double val1 = iCustom(_Symbol,_Period, "CaVol", 20, 1.0,        idxStick + 0,  0 ), // puffer  0.. 9
          val2 = iCustom(_Symbol,_Period, "CaVol", 20, 1.0,        idxStick + 10, 0 ), // buffer 10..19
          val3 = iCustom(_Symbol,_Period, "CaVol", 20, 1.0,        idxStick + 20, 0 ); // buffer 20..29
   //                                     name  para1, para2,      idx-buffer  

As now in OnInit() of CaVol I placed:

   Print(__LINE__," ",WindowExpertName());

I see in the expert log hundreds and hundreds of until the pc runs out of memory:

2017.06.09 12:39:27.357 CaVol EURUSD,H1: 228 CaVol
  1. I expect that the default values are taken by CaVol by such a call - right or wrong? As far as I remember it was that way!
  2. I expect WindowExpertName() to returm the indicator name CallingCaVol that calls CaVol but not CaVol - who is that wrong - me or mt4?
  3. I expect that due to the call of CaVol with the same parameters CaVol is created only ONCE and not each time it is called - why is that different?
whroeder1
17092
whroeder1  

Carl Schreiber:

  1. I expect that the default values are taken by CaVol by such a call - right or wrong? As far as I remember it was that way!
  2. I expect WindowExpertName() to returm the indicator name CallingCaVol that calls CaVol but not CaVol - who is that wrong - me or mt4?
  3. I expect that due to the call of CaVol with the same parameters CaVol is created only ONCE and not each time it is called - why is that different?
  1. [in]  Custom indicator input-parameters, separated by commas.

    The passed parameters and their order must correspond with the declaration order and the type of extern variables of the custom indicator. If the values of input parameters  is not specified, the default values will be used. iCustom - Technical Indicators - MQL4 Reference

    I seem to remember that either you supply no parameters (only defaults) or all of them, which I always do: Detailed explanation of iCustom - MQL4 forum First fix #2, then test all three ways.
  2. If WindowExpertName is returning "CaVol" then OnInit is setting its to that and your iCustom is calling itself recursively, thus using all memory.
  3. CaVol is irrelevant because of #2
Carl Schreiber
Moderator
7955
Carl Schreiber  

Add 2.: CallingCaVol is 'lonesome' running on one chart - nothing else! That's why I don't understand that!

I have another call of OnInit() in OnCalculate() if the timeframe was changed but I placed the line before as well a Print(__LINE__,..) but this never appears!

int OnCalculate(..) {
   ...
   if (ActTF != _Period) {
         Print(__LINE__," ",WindowExpertName(),"  ",ActTF," != ",_Period);
         OnInit(); 
         ReInit = true;
         return(0);
   } 


... ?

Edit: Even after CallingCaVol provides all the parameter calling CaVol it enters the endless loop... :(

Metaquotes said that they are not about to continue developping mt4, but they change things and it is not to the best of the mt4: on y soit qui mal y pense!

Alain Verleyen
Moderator
35125
Alain Verleyen  
Carl Schreiber:

Hi

I (Win7, 64, mt4, b1090) have an indicator CaVol with about 10 Parameter of which only the first two matters (the rest is for the presentation).

This indicator has 34 puffer. Now I wrote a second indicator CallingCaVol() that calls the first one - but only with the first two parameters - assuming that the others will taken by their default values

( simplified this call):

As now in OnInit() of CaVol I placed:

I see in the expert log hundreds and hundreds of until the pc runs out of memory:

  1. I expect that the default values are taken by CaVol by such a call - right or wrong? As far as I remember it was that way!
Right. Though I didn't check with 1090. But normal behavior  is to use default parameters when they are not set explicitly. You can provide 0, 1, or x parameters. Of course you can't "jump" a parameter.


  1. I expect WindowExpertName() to returm the indicator name CallingCaVol that calls CaVol but not CaVol - who is that wrong - me or mt4?
You are wrong ;-)
  1. I expect that due to the call of CaVol with the same parameters CaVol is created only ONCE and not each time it is called - why is that different?

You are right.

Carl Schreiber:

Add 2.: CallingCaVol is 'lonesome' running on one chart - nothing else! That's why I don't understand that!

I have another call of OnInit() in OnCalculate() if the timeframe was changed but I placed the line before as well a Print(__LINE__,..) but this never appears!

... ?

Edit: Even after CallingCaVol provides all the parameter calling CaVol it enters the endless loop... :(

Metaquotes said that they are not about to continue developping mt4, but they change things and it is not to the best of the mt4: on y soit qui mal y pense!

"Honni soit qui mal y pense" ;-)

Could you provide code that compiles to reproduce your issue ?

Alain Verleyen
Moderator
35125
Alain Verleyen  
whroeder1:

  1. If WindowExpertName is returning "CaVol" then OnInit is setting its to that and your iCustom is calling itself recursively, thus using all memory.

I don't understand what you mean ? Why call recursively ? It's just a print.
whroeder1
17092
whroeder1  
Alain Verleyen: I don't understand what you mean ? Why call recursively ? It's just a print.
What I think he has, in the indicator CallingCaVol a IndicatorShortName("CaVol") so when it calls iCustom("CaVol") it is calling another copy of itself. But he refuses to show the code.
Carl Schreiber
Moderator
7955
Carl Schreiber  
Alain Verleyen:
I don't understand what you mean ? Why call recursively ? It's just a print.
It is a recursive call of OnInit() and due to the fact that you can't remove an indicator loaded by iCustom() ....
Carl Schreiber
Moderator
7955
Carl Schreiber  
I am about to code a sample code..
Alain Verleyen
Moderator
35125
Alain Verleyen  
Carl Schreiber:
I am about to code a sample code..
Ok I will test it, as I probably misunderstood.
Carl Schreiber
Moderator
7955
Carl Schreiber  
Alain Verleyen:
Ok I will test it, as I probably misunderstood.
You have to wait a bit, I have to do my weekend shopping now, as I was struggling with this 'feature' the whole morning ...
Alain Verleyen
Moderator
35125
Alain Verleyen  
Carl Schreiber:
You have to wait a bit, I have to do my weekend shopping now, as I was struggling with this 'feature' the whole morning ...
lol...no problem.
123
To add comments, please log in or register