Need some help to sort out an error

User avatar
s01
Trader
Posts: 26
Joined: Mon Jul 30, 2012 3:22 pm
Location: Midwest, USA

Need some help to sort out an error

Post by s01 »

Hi again,

I just cannot wrap my head around this seemingly insignificant error, but try as I may, I cannot get rid of it. Might help if some new eyes looked at it and, then I could bang my head on the desk for not seeing it.

I have the 2 lines marked with the error, but its a : invalid integer number as parameter 2 for SetIndexDrawBegin function ....

Thank's agin in advance for any help in this.

Steve / s01

Code: Select all

//+------------------------------------------------------------------+
//|                                                ZeroLagStochs.mq4 |
//+------------------------------------------------------------------+
//|                                                   PriceVSwma.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "perky_z@yahoo.com"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 Lime

#property indicator_width1 1    // added these 2 lines // s01
#property indicator_width2 2



//---- input parameters


double stok1=0,stok2=0,stok3=0,stok4=0,stok5=0,mov=0,stoksmoothed=0,smoothing=15;
int shift=0, MAType=1, cnt=0,  prevbars=0,loopbegin=0;

bool first=true;
//---- buffers
double TrendBuffer[];
double LoBuffer[];
double HiBuffer[];
double PlusSdiBuffer[];
double MinusSdiBuffer[];
double TempBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 3 additional buffers are used for counting.
   IndicatorBuffers(3);
   
//---- indicator buffers
   SetIndexBuffer(0,TrendBuffer);
   SetIndexBuffer(1,LoBuffer);
   
    SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,White);
    SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2,Lime);
    IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
    
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("ZeroLagStocs");
   
   SetIndexDrawBegin(0,TrendBuffer); // invalid integer number as 
      // ------------------------ parameter 2 for setindexdrawbegin function
   SetIndexDrawBegin(1,LoBuffer);    // both lines are giving the error
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Average Directional Movement Index                               |
//+------------------------------------------------------------------+
int start()
  {
  // initial checkings
// check for additional bars loading or total reloading
if (Bars < prevbars )  first = true;
if (Bars-prevbars>1) first = true;
prevbars = Bars;
if (first) 
{
	// loopbegin prevent couning of counted bars exclude current
	loopbegin = Bars-1;
	if (loopbegin < 0) return(0);      // not enough bars for counting
	
	
	first = False;
   }
  
 
  loopbegin = loopbegin+1; 
 // Comment( loopbegin);            // current bar is to be recounted too
  for (shift = loopbegin; shift>= 0 ;shift--)
	{

stok1 = (iStochastic(NULL,0,8,3,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.05;
stok2 = (iStochastic(NULL,0,89,21,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.43;
stok3 = (iStochastic(NULL,0,55,13,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.26;
stok4 = (iStochastic(NULL,0,34,8,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.16;
stok5 = (iStochastic(NULL,0,21,5,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.10;
mov   = stok1+stok2+stok3+stok4+stok5;
stoksmoothed = mov/smoothing + LoBuffer[shift+1]*(smoothing-1)/smoothing;

	TrendBuffer[shift]=mov;
	LoBuffer[shift]=	stoksmoothed;
	
	loopbegin = loopbegin-1;     
	}}
	return(0);
	    // prevent to previous bars recounting
There are no bad traders, just bad systems, or rules.
A Quote that I stold from someone else:
Better to wish you were in a trade than wish you were out of a trade
User avatar
NeoTrader
Trader
Posts: 436
Joined: Wed Apr 04, 2012 2:52 pm
Location: small Village at Lake Chiemsee, Bavaria, Germany

Re: Need some help to sort out an error

Post by NeoTrader »

hi s01,
s01 wrote:I just cannot wrap my head around this seemingly insignificant error, but try as I may, I cannot get rid of it. Might help if some new eyes looked at it and, then I could bang my head on the desk for not seeing it.

I have the 2 lines marked with the error, but its a : invalid integer number as parameter 2 for SetIndexDrawBegin function ....

double TrendBuffer[];
double LoBuffer[];

SetIndexDrawBegin(0,TrendBuffer); // invalid integer number as

// ------------------------ parameter 2 for setindexdrawbegin function
SetIndexDrawBegin(1,LoBuffer); // both lines are giving the error
Just took a quick look at your code,

SetIndexDrawBegin needs that both parameters are integer... you defined TrendBuffer and LoBuffer as double.
If it is possible try to set them as int and look what happens. You can also look in the mql documentation for type casting to see how mql casts the different types.

If the type change does not work try the following (or vice versa):
Since mql has not a conversion function for DoubleToInteger the only alternative is to write it yourself (eg.

Code: Select all

int DoubleToInt(double dbl){return(StrToInteger(DoubleToStr(dbl,0)));} 
use it this way

Code: Select all

SetIndexDrawBegin(0,DoubleToInt(TrendBuffer));
SetIndexDrawBegin(1,DoubleToInt(LoBuffer));
And as I see you call the SetIndexDrawBegin in the init() where the buffers ( and the arrays) are still empty...this could also be the problem.

hope that one of this will help you to find a solution.

happy weekend,

NeoTrader

-
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Need some help to sort out an error

Post by gaheitman »

s01 wrote:Hi again,

I just cannot wrap my head around this seemingly insignificant error, but try as I may, I cannot get rid of it. Might help if some new eyes looked at it and, then I could bang my head on the desk for not seeing it.

I have the 2 lines marked with the error, but its a : invalid integer number as parameter 2 for SetIndexDrawBegin function ....

Thank's agin in advance for any help in this.

Steve / s01

Code: Select all

//+------------------------------------------------------------------+
//|                                                ZeroLagStochs.mq4 |
//+------------------------------------------------------------------+
//|                                                   PriceVSwma.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "perky_z@yahoo.com"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 Lime

#property indicator_width1 1    // added these 2 lines // s01
#property indicator_width2 2



//---- input parameters


double stok1=0,stok2=0,stok3=0,stok4=0,stok5=0,mov=0,stoksmoothed=0,smoothing=15;
int shift=0, MAType=1, cnt=0,  prevbars=0,loopbegin=0;

bool first=true;
//---- buffers
double TrendBuffer[];
double LoBuffer[];
double HiBuffer[];
double PlusSdiBuffer[];
double MinusSdiBuffer[];
double TempBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- 3 additional buffers are used for counting.
   IndicatorBuffers(3);
   
//---- indicator buffers
   SetIndexBuffer(0,TrendBuffer);
   SetIndexBuffer(1,LoBuffer);
   
    SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,White);
    SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2,Lime);
    IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
    
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("ZeroLagStocs");
   
   SetIndexDrawBegin(0,TrendBuffer); // invalid integer number as 
      // ------------------------ parameter 2 for setindexdrawbegin function
   SetIndexDrawBegin(1,LoBuffer);    // both lines are giving the error
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Average Directional Movement Index                               |
//+------------------------------------------------------------------+
int start()
  {
  // initial checkings
// check for additional bars loading or total reloading
if (Bars < prevbars )  first = true;
if (Bars-prevbars>1) first = true;
prevbars = Bars;
if (first) 
{
	// loopbegin prevent couning of counted bars exclude current
	loopbegin = Bars-1;
	if (loopbegin < 0) return(0);      // not enough bars for counting
	
	
	first = False;
   }
  
 
  loopbegin = loopbegin+1; 
 // Comment( loopbegin);            // current bar is to be recounted too
  for (shift = loopbegin; shift>= 0 ;shift--)
	{

stok1 = (iStochastic(NULL,0,8,3,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.05;
stok2 = (iStochastic(NULL,0,89,21,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.43;
stok3 = (iStochastic(NULL,0,55,13,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.26;
stok4 = (iStochastic(NULL,0,34,8,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.16;
stok5 = (iStochastic(NULL,0,21,5,3,MODE_SMA,NULL,MODE_MAIN,shift))*0.10;
mov   = stok1+stok2+stok3+stok4+stok5;
stoksmoothed = mov/smoothing + LoBuffer[shift+1]*(smoothing-1)/smoothing;

	TrendBuffer[shift]=mov;
	LoBuffer[shift]=	stoksmoothed;
	
	loopbegin = loopbegin-1;     
	}}
	return(0);
	    // prevent to previous bars recounting
SetIndexDrawBegin() expects a regular ol' number as the second parameter. You are passing an array. Take a look at the example in the help -- well, it's not a great example. Generally the function is used to keep the indicator from drawing until it has enough data (left to right) to show correct information. So, if you need at least 100 candles before you can calculate your value, you would use 100 as the second parameter.

I usually leave these calls out entirely unless I need them to prevent a divide by zero error.

George
garyfritz

Re: Need some help to sort out an error

Post by garyfritz »

NeoTrader wrote:Since mql has not a conversion function for DoubleToInteger the only alternative is to write it yourself (eg.

Code: Select all

int DoubleToInt(double dbl){return(StrToInteger(DoubleToStr(dbl,0)));} 
That seems pretty convoluted. Why not just return(MathRound(dbl)); ? (Or MathFloor(), depending on what you want.) I'm pretty sure MQL will properly convert the double MathRound() return value to Integer, since the DoubleToInt return value is integer. If not, you could just assign MathRound(dbl) to an int and then return that.
User avatar
s01
Trader
Posts: 26
Joined: Mon Jul 30, 2012 3:22 pm
Location: Midwest, USA

Re: Need some help to sort out an error

Post by s01 »

LOL, Guys,

Now totaly confused ...

I understand from the Empty4 documentation that the begin wants a number, but then in the sample it has text.... Copy/Paste from the Empty4 website

void SetIndexDrawBegin(int index, int begin)
Sets the bar number (from the data beginning) from which the drawing of the given indicator line must start. The indicators are drawn from left to right. The indicator array values that are to the left of the given bar will not be shown in the chart or in the DataWindow. 0 will be set as default, and all data will be drawn.

Parameters:
index - Line index. Must lie between 0 and 7.
begin - First drawing bar position number.

Sample:

int init()
{
//---- 2 additional buffers are used for counting.
IndicatorBuffers(3);
//---- drawing settings
SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
SetIndexDrawBegin(0,SignalSMA);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 3 indicator buffers mapping
SetIndexBuffer(0,ind_buffer1);
SetIndexBuffer(1,ind_buffer2);
SetIndexBuffer(2,ind_buffer3);
//---- name for DataWindow and indicator subwindow label
IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//---- initialization done
return(0);
}

So .. remember a coder I am not, just a regular guy tryin to figure this Empty4 out. I did not write this code, its an indicator I have had for a long time. But that error always bugged me. So just trin to fix someone elses mess. The indicator as it is now works, just has that constant error message.

So I want a number there? Or not?
Very confusing in the documentation.
If I place a number there,min number of bars counted or some such,
then how do I recall to get the line drawn again?
There are no bad traders, just bad systems, or rules.
A Quote that I stold from someone else:
Better to wish you were in a trade than wish you were out of a trade
garyfritz

Re: Need some help to sort out an error

Post by garyfritz »

George is right. You passed an array (your buffers, TrendBuffer and LoBuffer) as the second parameter. The Empty4 doc says the second parameter is supposed to be "First drawing bar position number." So it wants the bar number you want to start drawing from, not an entire buffer.

So if you called SetIndexDrawBegin(0, 23), that tells Empty4 to skip the oldest (left-most) 22 bars and start drawing buffer 0 on bar 23. (Note that this "count from the left" definition is the OPPOSITE of the normal Empty4 convention, where bar 0 is the NEWEST bar on the right of the chart.)

I'm not sure why this indicator needs that. Maybe there's some initialization period where the indicator calculation returns wonky values, and it wants you to not start plotting until the values stabilize. I suspect you could just delete that line and it would probably work fine.
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Need some help to sort out an error

Post by gaheitman »

s01 wrote:LOL, Guys,

Now totaly confused ...

I understand from the Empty4 documentation that the begin wants a number, but then in the sample it has text.... Copy/Paste from the Empty4 website

So I want a number there? Or not?
Very confusing in the documentation.
If I place a number there,min number of bars counted or some such,
then how do I recall to get the line drawn again?
Like many of the examples in the documentation, it isn't really helpful. I suspect the real code that they took the example from has this at the top (along with other externs):

Code: Select all

extern int SignalSMA=9; //length of Signal moving average
George
User avatar
NeoTrader
Trader
Posts: 436
Joined: Wed Apr 04, 2012 2:52 pm
Location: small Village at Lake Chiemsee, Bavaria, Germany

Re: Need some help to sort out an error

Post by NeoTrader »

hi gary,
garyfritz wrote:
NeoTrader wrote:Since mql has not a conversion function for DoubleToInteger the only alternative is to write it yourself (eg.

Code: Select all

int DoubleToInt(double dbl){return(StrToInteger(DoubleToStr(dbl,0)));} 
That seems pretty convoluted. Why not just return(MathRound(dbl)); ? (Or MathFloor(), depending on what you want.) I'm pretty sure MQL will properly convert the double MathRound() return value to Integer, since the DoubleToInt return value is integer. If not, you could just assign MathRound(dbl) to an int and then return that.
you're right...you could also use the math functions...but they still produce doubles...and maybe mql converts them to int (I'm not that sure what mql does at some times).
In my solution ( as convoluted as it seems) I'm sure I have an int at the end.

By the way...I also think that George is on the right track. As I said also in the first post, both values must be integer. I didn't look to close in the code and it was late...so I didn't realize that he uses the array instead of a value out of the array.

It also makes much more sense to use a period value for this parameter.

happy weekend,

NeoTrader

-
User avatar
s01
Trader
Posts: 26
Joined: Mon Jul 30, 2012 3:22 pm
Location: Midwest, USA

Re: Need some help to sort out an error

Post by s01 »

Well consesus was right,

Code: Select all

//   SetIndexDrawBegin(0,TrendBuffer); // error gone
//   SetIndexDrawBegin(1,LoBuffer);    // 
Don't see a reason for those 2 lines, seems to have worked.
Will watch for the divide by zero error mentioned earlier, when we start to get some data flowing.

Thanks again Guy's,

Steve / s01

The next one won't be so easy.
I have a few more things to try before I post it up.

s01
There are no bad traders, just bad systems, or rules.
A Quote that I stold from someone else:
Better to wish you were in a trade than wish you were out of a trade
garyfritz

Re: Need some help to sort out an error

Post by garyfritz »

Good, glad that worked out.
NeoTrader wrote:you're right...you could also use the math functions...but they still produce doubles...and maybe mql converts them to int (I'm not that sure what mql does at some times).
In my solution ( as convoluted as it seems) I'm sure I have an int at the end.
The whole DoubleToInt() function should be unnecessary. Any competent and properly-implemented language should automatically convert the double to an int in any double-to-int assignment, including implicit conversions e.g. for passing a double for an int parameter to a function. If it doesn't do the conversion, it should flag a type mismatch error. If MQL doesn't do either of those, it's a horrific bug in the language implementation.

And we know there aren't any bugs in Empty4...
Post Reply

Return to “Indicators”