This forum is in read-only mode now. You may discuss your questions on forums of MQL4.community and MQL5.community

Input variables reset to default by compilation


Back to topics list  | 1 2
avatar
120
hdb 2005.06.15 03:03 
Is it the case that all input variables of running expert advisors are reset to the default values when the expert advisor is simply recompiled?

This is currently wreaking havoc as I have 10 windows with different input parameters for the same advisor. It seems that every time i recompile, all the input variables are reset to default and I quicky have to reset them manually... not fun.

thanks,
avatar
80
tonyc2a 2005.06.15 04:18 
Yea it is.

Basically, variables have scope. Variables declared within a given function have scope within that function. IOW, they are destroyed and re-instantiated every time that function is called.

User Inputs, aka extern, variables are declared outside all functions. So they are only destroyed and re-instantiated when the expert is removed from the chart. Unfortunately, when you recompile an EA, it is in effect "removed" and "re-attached" to the chart. So all extern variables are destroyed and re-instantiated, and reset to thier default values.

Since the start() is called on every tick, variables within it are destroyed and re-instantiated at every tick. But variables declared outside all functions are not destroyed and maintain their values - and this is whether they have the extern identifier or not.

Hope that makes some kind of sense.
avatar
4464
Slawa 2005.06.15 11:12 
turn off terminal. recompile expert. run terminal. input variables are left as set before
avatar
120
hdb 2005.06.15 14:23 
tonyc2a, thanks, that does make sense.. I did have to read it twice though! lol

Slawa, thanks for the work-around. However, I think this is just a work around and hope its not a definitive answer. I could not put in a production system (i.e. real money) with this problem.

Can u confirm that it will be fixed at some stage?

Thanks,
avatar
4464
Slawa 2005.06.15 15:38 
there is no bug and will be not fixed. as designed.
avatar
120
hdb 2005.06.15 21:40 
ooch.. well, that may be the end of a nice try for me...

:( :( :(

I never did like the answer 'this is a feature, not a bug'..

avatar
4464
Slawa 2005.06.16 12:52 
there may be different cases. your case is rare. imho
avatar
16
GJim 2005.06.16 13:15 
Is it the case that all input variables of running expert advisors are reset to the default values when the expert advisor is simply recompiled?

This is currently wreaking havoc as I have 10 windows with different input parameters for the same advisor. It seems that every time i recompile, all the input variables are reset to default and I quicky have to reset them manually... not fun.

thanks,


Presuming that your 10 different windows are various pairs and/or time-frames, couldn't you preset the variables, within the program, based on the chart that is in use?

Symbol() will give you the trade pair,
Period() will give you the time-frame for the chart.

So, you could have something like:
If (Symbol() == "EURUSD")
a=4;
If (Symbol() == "GBPUSD")
a=6;
If (Period() == "PERIOD_M5")
b=1;
If (Period() == "PERIOD_M30")
b=2;

G'Jim c):{-
avatar
120
hdb 2005.06.16 14:09 
there may be different cases. your case is rare. imho


well, try suggesting your 'feature' to eSignal, TradeMaven, TradeStation users and see how they react... rofl!
avatar
120
hdb 2005.06.16 14:12 
Yes, GJim, I guess this is possible and will limit some of the potential problems. Thank-you.

However, it is unweildy code to work around what is a bug, or at best, an error in the system specifications.

:(




avatar
4464
Slawa 2005.06.17 11:26 
there may be different cases. your case is rare. imho


well, try suggesting your 'feature' to eSignal, TradeMaven, TradeStation users and see how they react... rofl!

yeah. lets consider 2 cases.
1. some expert working. you need to recompile it but not change its parameters
2. some expert working. you need to recompile it and reset its parameters.
our feature let provide both cases (with workaround)
your suggestion turn off 2-nd case
Back to topics list   | 1 2  
Download MetaTrader 5 (450 Kb, web installer) — a new terminal for financial markets