Programming help - turn indication into function

toyogo00

Newbie
Messages
5
Likes
0
Hi,

I've writen an indicator with (init(), start() etc coding done). I would like to turn this indicator into a callable function by other module. How to do so?

The problem I have is few global variables are used in both init() and start(). If I change it as below:

int gval=8;

int init()
{
SetIndexDrawBegin(0,gval);
SetIndexDrawBegin(1,gval);

}

int start()
{
if (gval >= 40) gval = gval - 3; else gval = gval + 5; .....
}

So if I want that to be a function then I will change the start() as :

int start()
{
myfunc(20);
}

int myfunc(int gval)
{
if (gval >= 40) gval = gval - 3; else gval = gval + 5; .....
}

How to pass the parameter to init() ?


Regards,
Toyogo
 
Look,

if you wrote an indicator, there is only one way how to use it in other module, for example in expert advisor or another indicator.

You need to call iCustom() function with your indicator name and parameters...

example:
Code:
double sig_1 = iCustom(NULL, 0, "sig_SAR", step, max, 0, 0);

You can't pass parameter to init function because its built in function and it doesn't take any parameters. Insted of this you exporting your indicator parameters by using extern keyword before the parameter name.

example:
Code:
extern double step = 0.02;
extern double max = 0.2;

then you can use them in the other module as I show you on iCustom example.

You might want to visit my site about MQL programming, I'm gonna write some beginner tutorials when I have free time.

Cheers,
Kriss.
 
Top