Need a little help understanding a few things

 

Hello Community,


Excuse my semi-idiotic questions, but I would like some help with a few questions regarding EA in MQL4 and its working structure, as I am new to this whole thing:

1) Will an Expert Advisor be able to work efficiently on a live account and be executed ON EACH TICK no matter how complex it is? In other words, how much complexity is too much complexity? (Currently writing an EA that has thousands of lines of code and I'm worried it won't be able to be executed properly.)

2) Where should variables be best declared? I do need some of the variables to get filled with new data on each tick, so these are to be declared inside the OnTick function ( those being filled by Ask and Bid  etc..), but as for the other variables that I don't want them to change , should I declare them in "OnInit" or just on top of the code not included in any function? Also, where should "static" variables be declared? 

3) Suppose I declared a static variable in my EA, it should be initialized to zero by default, then inside some condition, I assigned a new value to it: staticVar = currentBid;  

Till when will the program hold this new value? Till the new tick? Till It gets changed manually again in the code? Doesn't the declaration at the top of the program initialize it to zero all over again? ( static double staticVar;) 

4) Can I divide by OrdersTotal() ? I want to change the stop loss value of my orders, when stacked, to be the average of their stop losses, therefore I tried dividing by OrdersTotal(), ( I even declared a variable nbOrders = OrdersTotal() and tried dividing by nbOrders) but the division is not happening and an error is occurring (Error 130 ). Why is it not possible?

Sorry for these simple questions but it seems there's just a small lead I am not comprehending completely. Thank you for the help in advance.


Best Regards.

Reason: