MarketInfo() - bug

 

Hi,

I think, I just found a bug.

To re-produce just install and insert as Custom-indicator, end and re-start MT4 - you'll find the window empty.

Now just set faulty to false and feel better.

I used this for my indicator in a separate_window

//+------------------------------------------------------------------+
//|                                                      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 = -1;

//+------------------------------------------------------------------+
//| 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()
  {
   bool faulty = true; // change to check true : false
   if ( faulty ) 
     // with this the indicator is NOT drawn, values are NOT shown at MT4-Re-start,
     // onla after 1) re-compilation, 2) re-est 3) change of periodicity (eg. M5->M15)
     if (ValuePoints<0) ValuePoints   = MarketInfo(Symbol(),MODE_TICKVALUE)/Point;
   else
     // herewith the indicator behaves normal,
     // and is drawn, values are shown right after re-start:
     if (ValuePoints<0) ValuePoints   = 1/Points;

   for(i = 0; i<Bars; i++) {
      ExtMapBuffer1[i] = MathSqrt(ValuePoints *
               ( High[i] - Low[i] ));
   }
   return(0);
  }


//+------------------------------------------------------------------+

does anybody has a workaround, as I would need the MarketInfo()-function in this separate window

 

Your code doesn't compile.

 
phy:

Your code doesn't compile.

sorry, now it does.

I had a { to many..

 

Post it, unless it suddenly "started working"

 
phy:

Post it, unless it suddenly "started working"

here it is:

//+------------------------------------------------------------------+
//|                                                      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 = -1;

//+------------------------------------------------------------------+
//| 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()
  {
   bool faulty = true; // change to check true : false
   if ( faulty ) 
     // with this the indicator is NOT drawn, values are NOT shown at MT4-Re-start,
     // onla after 1) re-compilation, 2) re-est 3) change of periodicity (eg. M5->M15)
     if (ValuePoints<0) {
         ValuePoints   = MarketInfo(Symbol(),MODE_TICKVALUE)/Point;
         newErr("vP", 0,0,0,0, ValuePoints);
     }         
   else
     // herewith the indicator behaves normal,
     // and is drawn, values are shown right after re-start:
     if (ValuePoints<0) ValuePoints   = 1/Point;

//Alert("valPoint   vP:",ValuePoints);

   for(int i = 0; i<Bars; i++) {
      ExtMapBuffer1[i] = MathSqrt(ValuePoints *
               ( High[i] - Low[i] ));
   }
   return(0);
  }

int newErr(string wo, int l, int b, int c, int i, double v) {
   int z=0,err = GetLastError();
   if ( err == 0 ) return(0);
   Alert(wo, "  limit="+l+"  bars="+b+"  count=",c,"  int:",i,"  val:",v,"  err:",ErrorDescription(err));
   return(v/z);
}
 

and here is a work-around:


...
     if (ValuePoints<=0) {
         ValuePoints   = MarketInfo(Symbol(),MODE_TICKVALUE)/Point;
         if (ValuePoints<=0) return(-1);
     }         
...

MarketInfo() return just 0 at re-start of MT4 and with this the chart is not drawn right after re-start.

BUT herewith the chart is drawn and the values are set in the data-window - as other indicators - but a bit later.

calli


PS: couldn't they write this in the Description of this function. Lost a lot of time, very annoying!

 
So, what's the problem?
 
phy:
So, what's the problem?

What is the probelm?

Come on.

I personally lost a lot of time searching a mistake in my code.

Second I generally do not act on the assumption that normal functions sometimes work properly sometimes not, depending on the time they are used.

Third I would expect that in such a case at least an error is thrown - nothing.

Fourth this function first for example could wait until a connection is established, if it needs this, and throws after some time the error if failed.


How should I know those few functions that behave differently?

As I said the description does not tell you anything.


To me this is a problem and a quite annoying one too!

Carl

 

Yes, what's the problem?

I changed color, width, added comment

Comment("\n\n\n ValuePoints = MarketInfo(Symbol(),MODE_TICKVALUE)/Point; = ", MarketInfo(Symbol(),MODE_TICKVALUE)/Point);

 

Suggestion:

.

If you are having problems with restarting, don't do ctitical calculations "one time" on that first tick, restart emits a ton of bogus ticks as chart bars are updated.

So move your

.

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

for(int i = Bars-1; i >= 0; i--) {
.

into the main loop somewhere, maybe as shown.

.

Sometimes I do this (below) to not move ahead until things are ready to go:

int start (){

if(Time[0] != TimeCurrent()) return(0);

 
phy:

Suggestion:

.

If you are having problems with restarting, don't do ctitical calculations "one time" on that first tick, restart emits a ton of bogus ticks as chart bars are updated.

So move your

.

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

for(int i = Bars-1; i >= 0; i--) {
.

into the main loop somewhere, maybe as shown.

.

Sometimes I do this (below) to not move ahead until things are ready to go:

int start (){

if(Time[0] != TimeCurrent()) return(0);

phy,


my problem is that after a mt4-restart my indicator never was drawn or calculated correctly unless I re-compile, re-set or change to another periodicity and I did not understand why.

So I thought it was my fault and was searching, trying, searching, ...

I did move

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

from ini() into my main loop - no change.

Even this

int start (){

if(Time[0] != TimeCurrent()) return(0);

won't help.

I initially set ValuePoints -1 (double Va.. = -1) as MarketInfo(Symbol(),MODE_TICKVALUE)/Point;

will always be positive - so easy to check:

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

One of my aspects in programming is to avoid unnecessary 'cpu-time'.

ValuePoints has to be set only once, so why checking this every tick?


From where could I know that sometimes MarketInfo(Symbol(),MODE_TICKVALUE) returns 0 without any hint of an error?

From where could I know that this function does not work within ini() without any errors thown??

Have a nice weekend,

Carl

Reason: