First EA : How to confirm tick is coming in

 

I wrote the first simplest EA as below. When I attach it to the chart window, I see the alert for init and I see the alert of deinit when I remove it. But I never get any alerts from the start function. What am I doing wrong?

int Count=0;

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

//| expert initialization function |

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

int init()

{

Alert ("Function init() triggered at start");

return;

}

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

//| expert deinitialization function |

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

int start()

{

Alert("In the start");

double Price= Bid;

Count=My_Function();

Alert("New tick", Count," Price=",Price);

return;

}

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

//| expert start function |

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

int deinit()

{

Alert("Function deinit() triggered at exit");

return;

}

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


int My_Function()

{

Count++;

}

 
forexlead:

I wrote the first simplest EA as below. When I attach it to the chart window, I see the alert for init and I see the alert of deinit when I remove it. But I never get any alerts from the start function. What am I doing wrong?

...
Please edit your post, you have to use the SRC button when you post code. Thanks.
 

Count=My_Function();

the function does not return a value but increases Count.

change to void or add return value.

this is not an answer for the question on missing alert.

 

Were you by chance testing it when there were no new ticks coming in?

Ie. market closed or disconnected to the internet?

 

forexlead:

What am I doing wrong?

As szgy74 said, My_Function() does not return a value, so making Count equal to that function makes Count null. In effect, you are adding one to Count with MyFunction(), then nulling that out. You should skip assigning the function value to Count and simply call the function. You are still changing the value of Count with My_Function(), and since it is a global variable, that value is accessed in the start function as well.

double Price = Bid;
My_Function();
Alert("...");

Or, if you want to keep the assignment of the function return value to Count, you need to return Count++.

int My_Function()
   {
    Count++;
    return(Count);
   }

Obviously, the first solution is more efficient than the second, and doing away with the function altogether would be most efficient, but you are practicing your use of functions and variables.

And, as szgy74 said, this still doesn't solve your Alert problem. Check your journal, not just your expert log. That might tell you something.

This might not fix it, but when using Alert() and Print(), I don't use comma-separated parameters; I concatenate the values into a single string. It is a matter of style, I suppose.

Alert("New tick: " + Count + ". Price = " + Price);
Reason: