Please help with an indicator!

 

Hi! I want to make an indie that is not going to draw anything, it will just take another indicator (by iCustom function) like MACD or a similar oscillator indicator, and give Alert and Sound alarm when it crosses a certain important level.

Below is the code. I can't really code from scratch, could some kind soul please look what needs to be added (or removed) to make this code work? it's a small one

extern string Name = "IndName";

extern double lvl= 0; //level to be crossed for signal

extern int BuffNum = 0; //indicator buffer number to cross the level

double Val[];

int init() // have no clue if this part is needed at all?

{

return(0);

}

int start()

{

int limit;

int counted_bars=IndicatorCounted();

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(int i=0; i<limit; i++)

Val = iCustom(NULL,0,"Name",BuffNum,0) ; //"Name" or Name?

if ( (Val > lvl && Val< lvl) || (Val lvl) )

{

Alert("Watch it!", Symbol());

PlaySound ("Alert.wav ");

}

}

I'm told by a programmer that in the code, "array has no size and it must be forced to have size", and I have no clue what it means

Appreciate any help.

 
SVGuss:
Hi! I want to make an indie that is not going to draw anything, it will just take another indicator (by iCustom function) like MACD or a similar oscillator indicator, and give Alert and Sound alarm when it crosses a certain important level.

Below is the code. I can't really code from scratch, could some kind soul please look what needs to be added (or removed) to make this code work? it's a small one

extern string Name = "IndName";

extern double lvl= 0; //level to be crossed for signal

extern int BuffNum = 0; //indicator buffer number to cross the level

double Val[];

int init() // have no clue if this part is needed at all?

{

return(0);

}

int start()

{

int limit;

int counted_bars=IndicatorCounted();

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(int i=0; i<limit; i++)

Val = iCustom(NULL,0,"Name",BuffNum,0) ; //"Name" or Name?

if ( (Val > lvl && Val< lvl) || (Val lvl) )

{

Alert("Watch it!", Symbol());

PlaySound ("Alert.wav ");

}

}

I'm told by a programmer that in the code, "array has no size and it must be forced to have size", and I have no clue what it means Appreciate any help.

SVGuss, you can take any indicator and change the color to none and if it's a separate window indicator squish it down real small to take up very little chart space, and if the indicator has alerts they should work just the same.

 

Well... "if the indicator has alerts " is a big IF But what if it's a custom indicator without any alerts? Rather than modyfying each indicator adding an alert inside it's code, you could use the one I suggest and all you have to do is just to specify its name. That seems much easier and much more universal.

 
SVGuss:
Well... "if the indicator has alerts " is a big IF But what if it's a custom indicator without any alerts? Rather than modyfying each indicator adding an alert inside it's code, you could use the one I suggest and all you have to do is just to specify its name. That seems much easier and much more universal.

SVGuss, I agree with you it's a very good idea, especially for an ex4 file, problem is there are so many possible combinations of conditions for the indicator to alert, which IMHO would make it hard to make a universal one.

 

Hm... I don't understand what you mean. There's only one condition - when, say, 0 for MACD or 50 for Stochastic is crossed. There are many custom oscillators like MACD or Stochastic, and for them I think it would be quite useful. Actually, if you also want levels 20 and 80 for Stochastic, the same indicator would do, just throw it on the chart with different parameters... These are all the conditions I can think of.

 
SVGuss:
Hm... I don't understand what you mean. There's only one condition - when, say, 0 for MACD or 50 for Stochastic is crossed. There are many custom oscillators like MACD or Stochastic, and for them I think it would be quite useful. Actually, if you also want levels 20 and 80 for Stochastic, the same indicator would do, just throw it on the chart with different parameters... These are all the conditions I can think of.

SVGuss

You did not "tell" to metatrader that it is an indicator

Use one of the following :

#property indicator_main_window

#property indicator_separate_window

and it should start working

______________________

The problem now is that metatrader "thinks" that it is either EA or a script and it refuses to start it as indicator

 

Thanks, mladen!

I inserted #property indicator_chart_window, main_window won't compile.

I'll test next week if it works. Thanks again.

 
SVGuss:
Thanks, mladen!

I inserted #property indicator_chart_window, main_window won't compile.

I'll test next week if it works. Thanks again.

It compiles on my metaeditor

Like this :

#property indicator_chart_window

extern string Name = "IndName";

extern double lvl= 0; //level to be crossed for signal

extern int BuffNum = 0; //indicator buffer number to cross the level

double Val[];

int init() // have no clue if this part is needed at all? {

return(0);

}

int start()

{

int limit;

int counted_bars=IndicatorCounted();

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(int i=0; i<limit; i++)

Val = iCustom(NULL,0,"Name",BuffNum,0) ; //"Name" or Name?

if ( (Val > lvl && Val< lvl) || (Val lvl) )

{

Alert("Watch it!", Symbol());

PlaySound ("Alert.wav ");

}

}
 

Yes, chart_window compiles, not main_window

in the line Val = iCustom(NULL,0,"Name",BuffNum,0) - does Name need quotes though?

 
SVGuss:
Yes, chart_window compiles, not main_window in the line Val = iCustom(NULL,0,"Name",BuffNum,0) - does Name need quotes though?

They way you written the indicator it does not need the quotes

Reason: