| New signals service! | |
|
|||||||
| Register in Forex TSD! | |
|
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time). Click here to register and get more information |
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Automatic Magic Function Required
I am looking for a simple function that will create an automatic Magic Number based on the symbol type.
Does anyone have something like this? I thought this would be easier than allocating a number to each symbol type. I need this for an EA I am writing which will attach to almost all charts at one time. I need a different magic number for each symbol without having to manually change it on each chart. Thanks. Steve |
|
|||
|
The following code combines the symbol, expert name & time frame for a Magic Number:
int MagicNumberFromExpertName(string expert_name) { int magic_number = 0; //We use symbol here as an expert has to be attached to a chart for(int i=0; i < 5; i++) { magic_number = magic_number * 3 + StringGetChar(Symbol(), i); } for(i = 0; i < StringLen(expert_name); i++) { magic_number = magic_number * 3 + StringGetChar(expert_name, i); } magic_number = magic_number * 3 + Period(); return (magic_number); } |
|
|||
|
here is another version
string s="GBPUSD", magicStr = ""; int len = StringLen(s), tmp; for(int i=0; i<len; i++){ tmp = StringGetChar(s, i); magicStr = magicStr+(tmp-64); } int magic = StrToInteger(magicStr); 64 was subtracted under assumption that symbol is ascii string Without -64 the resulting # will not fit into int type resulting in negative #, i dont know if thats ok and if number is unique. I dont know if subtracting 64 for other pair other than g/u gives small number. Anyway this was intended for you to think and try writing the function yourself. |
|
|||
|
Magic Number Base On Symbol And Time Frame
MAGIC NUMBER BASE ON SYMBOL AND TIME FRAME FUNCTION
int init() { MagicNumber = subGenerateMagicNumber(MagicNumber, Symbol(), Period()); } ------- ------- int subGenerateMagicNumber(int MagicNumber, string symbol, int timeFrame) { int isymbol = 0; if (symbol == "EURUSD") isymbol = 1; else if (symbol == "GBPUSD") isymbol = 2; else if (symbol == "USDJPY") isymbol = 3; else if (symbol == "USDCHF") isymbol = 4; else if (symbol == "AUDUSD") isymbol = 5; else if (symbol == "USDCAD") isymbol = 6; else if (symbol == "EURGBP") isymbol = 7; else if (symbol == "EURJPY") isymbol = 8; else if (symbol == "EURCHF") isymbol = 9; else if (symbol == "EURAUD") isymbol = 10; else if (symbol == "EURCAD") isymbol = 11; else if (symbol == "GBPUSD") isymbol = 12; else if (symbol == "GBPJPY") isymbol = 13; else if (symbol == "GBPCHF") isymbol = 14; else if (symbol == "GBPAUD") isymbol = 15; else if (symbol == "GBPCAD") isymbol = 16; else isymbol = 17; if(isymbol<10) MagicNumber = MagicNumber * 10; return (StrToInteger(StringConcatenate(MagicNumber, isymbol, timeFrame))); } Last edited by Bongo; 07-04-2008 at 11:46 AM. |
|
|||
|
Or this initialization function:
int MagicNumber; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { if (Symbol() == "AUDCADm" || Symbol() == "AUDCAD") { MagicNumber = 427101; } if (Symbol() == "AUDJPYm" || Symbol() == "AUDJPY") { MagicNumber = 427102; } if (Symbol() == "AUDNZDm" || Symbol() == "AUDNZD") { MagicNumber = 427103; } if (Symbol() == "AUDUSDm" || Symbol() == "AUDUSD") { MagicNumber = 427104; } if (Symbol() == "CHFJPYm" || Symbol() == "CHFJPY") { MagicNumber = 427105; } if (Symbol() == "EURAUDm" || Symbol() == "EURAUD") { MagicNumber = 427106; } if (Symbol() == "EURCADm" || Symbol() == "EURCAD") { MagicNumber = 427107; } if (Symbol() == "EURCHFm" || Symbol() == "EURCHF") { MagicNumber = 427108; } if (Symbol() == "EURGBPm" || Symbol() == "EURGBP") { MagicNumber = 427109; } if (Symbol() == "EURJPYm" || Symbol() == "EURJPY") { MagicNumber = 427110; } if (Symbol() == "EURUSDm" || Symbol() == "EURUSD") { MagicNumber = 427111; } if (Symbol() == "GBPCHFm" || Symbol() == "GBPCHF") { MagicNumber = 427112; } if (Symbol() == "GBPJPYm" || Symbol() == "GBPJPY") { MagicNumber = 427113; } if (Symbol() == "GBPUSDm" || Symbol() == "GBPUSD") { MagicNumber = 427114; } if (Symbol() == "NZDJPYm" || Symbol() == "NZDJPY") { MagicNumber = 427115; } if (Symbol() == "NZDUSDm" || Symbol() == "NZDUSD") { MagicNumber = 427116; } if (Symbol() == "USDCHFm" || Symbol() == "USDCHF") { MagicNumber = 427117; } if (Symbol() == "USDJPYm" || Symbol() == "USDJPY") { MagicNumber = 427118; } if (Symbol() == "USDCADm" || Symbol() == "USDCAD") { MagicNumber = 427119; } if (MagicNumber == 0) { MagicNumber = 427199; } pair = Symbol(); return(0); } |
|
|||
|
Quote:
This MagicNumber copy and past is a part of a coding I modify long time ago here in this forum. (The number tell me the exact EA where it come from !!!) FerruFx
__________________
THE HEART of FOREX & THE PROBABILITY METER - Trade with 100% confidence and ... Stress Less!!! Coding services: Experts Advisors, indicators, alerts, etc ... more info by PM NEW: video presentation of the Probability Meter ... 24hrs action on the website |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Help required from FX Virgin x | Kirsty_FX | TSD Expert Advisors | 12 | 05-31-2007 11:41 AM |
| Breakout EA Required | fxwealth | Metatrader 4 | 5 | 05-21-2007 02:28 PM |
| Some help please required | Pervaz | Suggestions for Trading Systems | 2 | 01-22-2007 03:53 AM |
| Coding help required | ozimacca | Indicators - Metatrader 4 | 2 | 03-03-2006 11:36 PM |