Beginner programmer help please

 

I'm teaching myself to program using the MQL4 book on this site.

I'm stuck on the following:

I have coded the very simple stochastics cross alert program from the book. See code below. I'm not sure if I should compile the program as a script or an EA? I have tried both, compiled this code as script and EA and attached to a chart but I'm not getting any alerts. Any help will be appreciated.

int start()
{
double M_0, M_1,
S_0, S_1;

M_0 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0);
M_1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,1);
S_1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,0);
S_1 = iStochastic(NULL,0,5,3,3,MODE_SMA,0,MODE_MAIN,1);

if (M_1 < S_1 && M_0 >= S_0)
Alert ("Crossing upwards. BUY");

if (M_1 > S_1 && M_0 <= S_0)
Alert ("Crossing downwards. SELL");

if (M_1 > S_1 && M_0 > S_0)
Alert ("Continue holding long position");

if (M_1 < S_1 && M_0 < S_0)
Alert ("Continue holding short position");

return(0);
}

 

What value is S_0 ? Is that same as S_1 ? (look at your code again. S_1 is used twice)


It looks like M_0 and S_0 are exactly the same. Both read,5,3,3,MODE_SMA,0,MODE_MAIN,0);

M_1 and S_1 are also the same, so cross can never happen.


Scripts happen once and then stop. Experts are continuous. Best to use Alert in either expert or indicator.

 
JPS:

What value is S_0 ? Is that same as S_1 ?


It looks like M_0 and S_0 are exactly the same. Both read,5,3,3,MODE_SMA,0,MODE_MAIN,0);

M_1 and S_1 are also the same, so cross can never happen.


Scripts happen once and the stop. Experts are continuous. Best to use Alert in either expert or indicator.


Thanks so much