Possible Bug: extern'ed vars in /libraries and /include files

 
I'd like to modularize many of my functions by moving them to /libraries and /include files.

For example, I'd like to move all my Trailing Stop code to libraries/TrailingStop.mq4 and include/TrailingStop.mqh, and declare all relevant input vars in the .mqh file. That way, the using EA only needs to include the header file, and all the inputs will show up on the Inputs tab.

I noticed that if I externalize variables in a .mqh file (like "extern int TrailingStop") and include that header file in my EA, the externalized variable will indeed show up on the Inputs page when the EA is attached to a chart.

Wonderful!

However, these variables don't retain their values. Only externalized variables declared in the ACTUAL EA retain their values.

Can someone inform me how to make this work, or confirm that this is a bug?

Thank you!
Alan
MT 4 build 193
 
Can You expose little sample (2-3 sources) and step by step your actions to illustrate this problem?
 
Sorry for the delayed reply. OK, here's an example of what I'm seeing:

sample EA code (not tested, but it's the basic idea):
extern int TrailingStop = 10;
extern int StopLoss = 20;

#include <MoneyMgmt.mqh>

int start( )
{
  Print( "TrailingStop:" + TrailingStop );
  Print( "StopLoss:" + StopLoss );
  Print( "RiskPercent:" + RiskPercent );
}




MoneyMgmt.mqh (in "include" dir):

#import "MoneyMgmt.mq4"

extern int RiskPercent = 1;

int MoneyManagement( );




MoneyMgmt.mq4 (in "libraries" dir):

#include <MoneyMgmt.mqh>

int MoneyManagement( )
{
  return ( 1 );
}




Using the above code, you'll see 3 variables on the Input page when you add it to a chart: TrailingStop, StopLoss, and RiskPercent. If you modify all 3 values on the Inputs page and run the EA, TrailingStop and StopLoss will retain the values you entered, but RiskPercent will ALWAYS equal 1 (one).

This isn't the case if RiskPercent is defined in the main EA module, only if it's defined in the include file.

You hopefully can see the usefulness of having extern'ed vars in include files: it allows you to not only modularize your code but also the input vars. All you need to do is add one "#include" statement to your main EA and you're all set!

I hope you can get this working. Thanks for your time!

Alan

 
Slawa, have you had a chance to look at this yet?
 
No. I cannot reproduce described bug.

All external variables changes are saved
 
Alan, I tried your example (for my own education) and in my case all values are retained.

Also, why would you have "#include <MoneyMgmt.mqh>" in the library file "MoneyMgmt.mq4"? It seems that you create a circular reference, as "MoneyMgmt.mq4" is imported in "MoneyMgmt.mqh".