Yes, it's possible, but how can you use it later?
michaelB:
Does anyone see a problem using the following code to build a unique magic number ??
[I cannot use symbol or timeframe in the magic number]
int magic = TimeCurrent();
- Each time you refresh the charts the EA goes through a deInit/init cycle and you'll forget the previous magic number and loose all trades.
- Why not. Just use mn = base+tf. Always filter by symbol.
extern int Magic.Number.Base = 20110202; int magic.number; // Export to ModifyStops string TF.text; // Export to Decide int init(){ /*++++ Adjust for the current chart timeframe */{ static int TFperiod[] = { PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1, PERIOD_MN1 }; static string TFtext[] = { "M1", "M5", "M15", "M30", "H1", "H4", "D1", "W1", "MN1" }; for(int iTF=0; TFperiod[iTF] < Period(); iTF++){} TF.text = TFtext[iTF]; magic.number = Magic.Number.Base + iTF; } : for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. ){
Roger:
Yes, it's possible, but how can you use it later?
Yes, it's possible, but how can you use it later?
Actually the statement should look like this-
static int magic = TimeCurrent();
Once set, the number should be available [and constant] as long as the EA is running.
michaelB:
That will not compile. You can only initialize a static with a constant. You could do
Actually the statement should look like this-
static int magic = TimeCurrent();
Once set, the number should be available [and constant] as long as the EA is running.
static int magic = 0; if (magic == 0) magic = TimeCurrent();
But on any restart (chart closed/reopened) terminal restart, OS reboot etc. All currently opened trades will be abandoned.
[I cannot use symbol or timeframe in the magic number]
WHRoeder:
That will not compile. You can only initialize a static with a constant.
I think that is the least of his issues . . .
That will not compile. You can only initialize a static with a constant.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Does anyone see a problem using the following code to build a unique magic number ??
[I cannot use symbol or timeframe in the magic number]
int magic = TimeCurrent();