Download MetaTrader 5
To add comments, please log in or register
They are already making profit from their signals. Publish your signal and join them!
Carl Schreiber
6373
Carl Schreiber 2008.12.08 14:03 

hi,

my indicator compiles with no errors and is drawn corrretly.

But when I now close and restart MT4 the indicator window is empty all buffers are zero,

even after new quotes nothing can be seen, nothing is changed.

Only if I again compile my indicator (anything changed of course) everything is fine again?

Where is my fault?

Thanks carl

blogzr3
492
blogzr3 2008.12.08 14:28  

Sounds like it could be something to do with the IndicatorCounted() and Bars and how you compute the max in the for-loop.


A quick test to see if this is the case would be to hard-code the max, i.e change the max variable to a literal number and see if this fixes the problem.

Carl Schreiber
6373
Carl Schreiber 2008.12.08 16:37  
blogzr3:

Sounds like it could be something to do with the IndicatorCounted() and Bars and how you compute the max in the for-loop.


A quick test to see if this is the case would be to hard-code the max, i.e change the max variable to a literal number and see if this fixes the problem.

ahh, thanks, found it - and haven't got a solution :(

This piece of code:
...

   int counted_bars=IndicatorCounted();
    if(counted_bars < 0) {
       Alert(Symbol(),"  bars="+Bars+"  count="+counted_bars,"  err:",ErrorDescription(GetLastError()));
       return(-1); 
   }

//---- last counted bar will be recounted
   limit = Bars - counted_bars + SlowSMA - 1; 
   if ( limit > Bars ) limit = Bars;
   if (limit<0) {
      Alert("uups limit="+limit+"  bars="+Bars+"  count="+counted_bars,"  err:",ErrorDescription(GetLastError()));
      return(-1);
   } //else Print("uups limit="+limit+"   limit="+limit+"  bars="+Bars+"  count="+counted_bars);

Alert("uups limit="+limit+"  bars="+Bars+"  count="+counted_bars);
...

produces after compilation:

2008.12.08 14:47:49 myIndi EURUSD,M15: Alert: uups limit=19193 bars=19193 count=0

so all bars are re-calculated and counted-bars are zero.


But a restart of MTT4 produces:

2008.12.08 14:48:03 myIndi EURUSD,M15: Alert: uups limit=18 bars=19193 count=19192

so only the last 20 are calculated (and nothing is correct :(


On the otherhand obviously the values of others indicators before the shutdown of MT4 are kept but not the one of mine??

Anyone with a hint?


OR - is there a way to make the indicator know that it should re-calc my indicator at restart of MT4 => IndicatorCounted() returns zer0 (but only in my indicator)?

Can there something set e.g. by deinit() that IndicatorCounted() gives 0 hereafter?


Thanks in advance,

Carl


PS:

I tried to define a reCalc-Variable:


..
int reCalc = 1;
..
int deinit() {
   int reCalc = 1;
...
}
int init() {
   int reCalc = 1;
..
}

int start() {
...
   if ( limit > Bars || reCalc == 1) { limit = Bars; reCalc = 0; }
...
}

does not help :(

I do get:

2008.12.08 15:53:46 sstHMA EURUSD,M15: Alert: uups limit=20 bars=19197 count=19196


EDven another try to re-calc the indicator and have it re-drawn by that failed.
I tried:

   if ( dBO[Bars-(2*lengthSMA)] == 0 || dBO[Bars-(2*lengthSMA)] == EMPTY_VALUE ) {
      if (Symbol()=="EURUSD") Alert("uups limit="+limit+"  bars="+Bars+"  count="+counted_bars,"  dBO:",dBO[Bars-(2*lengthSMA)]," [",Bars-(2*lengthSMA),"]");
      limit = Bars;
   } else 
      if (Symbol()=="EURUSD") Alert("norm limit="+limit+"  bars="+Bars+"  count="+counted_bars,"  dBO:",dBO[Bars-(2*lengthSMA)]," [",Bars-(2*lengthSMA),"]");

the Buffer dBO has the difference of Bollinger-UP - Bollinger-DN, which is rather seldom zero!

But even with this I get

2008.12.08 16:53:19 myIndi EURUSD,M15: Alert: uups limit=19201 bars=19201 count=0 dBO:0 [19165]

so it seemed to be re-calc as of the beginning,

but nothing has changed: nothing is drawn and the data-window shows only zeros too.

:((

blogzr3
492
blogzr3 2008.12.09 06:19  

If dBO is your display buffer, you should simply loop through it with 0,1,2,3...etc using a for-loop to see what's in it. If it's empty, then whatever code you used to populate it is at fault, so you need to backtrack to that part.


Note that there are numerous reasons why an indicator is not drawn, including incorrect settings earlier on in the variable/property declaration sections and also the various SetIndex... settings in the init section. There are also a number of places where MQL4 code behaves differently from other programming languages, so knowing other languages before starting on MQL4 is actually a disadvantage in a way. Which you can only find out by experimenting, starting with the sample code provided.

Carl Schreiber
6373
Carl Schreiber 2008.12.09 14:08  
blogzr3:

If dBO is your display buffer, you should simply loop through it with 0,1,2,3...etc using a for-loop to see what's in it. If it's empty, then whatever code you used to populate it is at fault, so you need to backtrack to that part.


Note that there are numerous reasons why an indicator is not drawn, including incorrect settings earlier on in the variable/property declaration sections and also the various SetIndex... settings in the init section. There are also a number of places where MQL4 code behaves differently from other programming languages, so knowing other languages before starting on MQL4 is actually a disadvantage in a way. Which you can only find out by experimenting, starting with the sample code provided.



I have _NO_ idea what to do, how to program my indicator that it is drawn as off the start of MT4 and not only after re-compiling it???


Now I infiltratet any loop of my indicator with this error-calls:

// newErr("where", limit,Bars,counted_bars, i, value);
int newErr(string w, int l, int b, int c, int i, double v) {
   int x=1,y=0,err = GetLastError();
   if ( err == 0 ) return(0);
   Alert(w,"  limit=",l,"  bars=",b,"  count=",c,"  idx:",i,"  val:",v,"  err:",ErrorDescription(err));
   return(x/y); // to stop the indicator.
}

and now neither after re-start of MT4 nor after re-compiling any error is shown,

but still every buffer is set to zero form the beginning of the chart window until the most recent bar until re-compilation?


Isn't here anybody who has had a simuilar problem and has a way to find my bug?

Thanks Carl

Carl Schreiber
6373
Carl Schreiber 2008.12.10 14:23  
gooly:

I have _NO_ idea what to do, how to program my indicator that it is drawn as off the start of MT4 and not only after re-compiling it???


Now I infiltratet any loop of my indicator with this error-calls:

and now neither after re-start of MT4 nor after re-compiling any error is shown,

but still every buffer is set to zero form the beginning of the chart window until the most recent bar until re-compilation?


Isn't here anybody who has had a simuilar problem and has a way to find my bug?

Thanks Carl






Still don't know what to do. Every try since three days was fruitless.

I opend a new chart window with only this indicator - no change.

I eliminated allmost everything but one little line - no change.

I even wrote a new indicator which has only one little line - no change.

After restart of MT4 these indicators were not dranw in its wondows and they sends no values to their data-window???


Only if I either

- re-compile (of course no errors see above) or

- reset this indicator or

- just switch the Periodicity - then everything is ok?


Do I have to delete a specific MT4 config-file?

Anybody from the program team that can send me a little (christmas-) light??

Carl

Ray
2650
Ray 2008.12.10 17:03  
show your code.
Carl Schreiber
6373
Carl Schreiber 2008.12.11 16:23  
//+------------------------------------------------------------------+
//|                                                      noStart.mq4 |
//|                                                              cas |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "cas"
#property link      ""
#include <stderror.mqh>
#include <stdlib.mqh>


#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 20
#property indicator_buffers 1
#property indicator_color1 MediumBlue

#property  indicator_width1  1



//---- input parameters
extern int lengthSMA = 18;
extern double limKRU = 2.5;
extern double limSTG = 10.0;


//---- buffers
double ExtMapBuffer1[];

//--- my global Vars

double   ValuePoints;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
    SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMapBuffer1);
   
SetIndexDrawBegin(0,lengthSMA);

//----
   ValuePoints   = MarketInfo(Symbol(),MODE_TICKVALUE)/Point;



   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    i, counted_bars=IndicatorCounted();
   int limit = Bars - counted_bars;

//----
   
   for(i = 0; i<limit; i++) {
      ExtMapBuffer1[i] = MathSqrt(ValuePoints *
               ( iBands(NULL,0,lengthSMA,2,0,PRICE_CLOSE,MODE_UPPER,i) -
                 iBands(NULL,0,lengthSMA,2,0,PRICE_CLOSE,MODE_LOWER,i)))/3;
newErr("dBO [i]",limit,Bars,counted_bars,i,ExtMapBuffer1[i]);

   }

   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+


// usage:  newErr(limit,Bars,counted_bars, dBO[Bars-(2*lengthSMA)]);
int newErr(string where, int l, int b, int c, int i, double v) {
   int x=1,y=0,err = GetLastError();
   if ( err == 0 ) return(0);
   Alert(where, "  limit="+l+"  bars="+b+"  count=",c,"  int:",i,"  val:",v,"  err:",ErrorDescription(err));
   return(x/y); // to stop
}

ok,

here it is - one of them..

Do you can see what and where is the problem?
-- I don't --


In the Journal-Tab I read:


2008.12.11 15:10:35 '...': login (4.00, #..)

2008.12.11 15:10:33 Custom indicator noStart XAUUSD,H1: loaded successfully

in the Experts-Tab I read:

2008.12.11 15:10:33 noStart XAUUSD,H1: initialized

2008.12.11 15:10:33 noStart XAUUSD,H1: loaded successfully


no errors by newErr() found.


The indicator window is just empty,

the data-window shows all values are 0 no change even after new ticks.


Everything is different after (s.a.) recompiling, ...


Very, very frustrating!

Carl

Ray
2650
Ray 2008.12.11 22:09  

For test:

replace for i < limit with i < Bars

Get rid of SetIndexDrawBegin

Set ExtMapBuffer1 = Close[i];

Remove the indicator from the chart, and re-add.

Take ValuePoints out of init. It doesn't belong there.

See where you get some output from the substitutions and go from there.

Carl Schreiber
6373
Carl Schreiber 2008.12.11 23:01  
phy:

For test:

replace for i < limit with i < Bars

Get rid of SetIndexDrawBegin

Set ExtMapBuffer1 = Close[i];

Remove the indicator from the chart, and re-add.

Take ValuePoints out of init. It doesn't belong there.

See where you get some output from the substitutions and go from there.

No change !!! ???

1.) replace for i < limit with i < Bars

done - no change


2.) Get rid of SetIndexDrawBegin

done - no change


3.) Remove the indicator from the chart, and re-add.

done - no change


4.) Take ValuePoints out of init. It doesn't belong there.

done replacing into start() this way:

// global definition:

double ValuePoints = -1;

int start()
  {
   if (ValuePoints<0) ValuePoints   = MarketInfo(Symbol(),MODE_TICKVALUE)/Point;
   for(i = 0; i<Bars; i++) {
      ExtMapBuffer1[i] = MathSqrt(ValuePoints *
               ( High[i] - Low[i] ))/3;
             newErr("dBO [i]",limit,Bars,counted_bars,i,ExtMapBuffer1[i]);

   }
   return(0);
  }

Can't go from there :(( no change, no drawing after re-start no idea where is the bug - in my program, I doubt.

I even added another indicator (hma) this one is drawn - mine not.

I start thinking to take it personally ;)


Now I found it and it is very annoying bug!!

As soon as I replace

if (ValuePoints<0) ValuePoints   = MarketInfo(Symbol(),MODE_TICKVALUE)/Point;

by

if (ValuePoints<0) ValuePoints   = 1/Point;

the chart is drawn at re-start of MT4.


So the function

MarketInfo(Symbol(),MODE_TICKVALUE)

is faulty.

At least this standard function only partly works in a seperate window - who would think of that?


Where the hell was the Link for the bug-messages, do you know phy?

Thanks for encouraging me to go on testing.

calli

Ray
2650
Ray 2008.12.11 23:28  

Where the hell was the Link for the bug-messages

type an error number into the editor's navigator search box and press the "enter" key deterministically.

/ /12
To add comments, please log in or register