Forex
Google
New signals service!

Go Back   Forex Trading > Discussion Areas > Metatrader 4


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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-10-2007, 11:54 PM
Member
 
Join Date: Sep 2006
Posts: 56
sbwent is on a distinguished road
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-11-2007, 12:13 AM
Member
 
Join Date: Dec 2006
Posts: 73
testern is on a distinguished road
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);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-11-2007, 12:23 AM
Member
 
Join Date: Sep 2006
Posts: 56
sbwent is on a distinguished road
Thanks

Thank you, Much appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-11-2007, 12:35 AM
Member
 
Join Date: Dec 2005
Posts: 68
asmdev is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-04-2008, 12:45 AM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,159
matrixebiz is on a distinguished road
Auto MagicNumber

Quote:
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);
}
I get allot of errors when I add this to my code. Can you be more clear.
I added this;
extern string expert_name = "EA Name"
Moved this up to top with the other extern variables;
int magic_number = 0;
And deleted this;
int MagicNumberFromExpertName(string expert_name)


I'll try this
Thank you

Last edited by matrixebiz; 07-04-2008 at 11:04 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-04-2008, 11:23 AM
Senior Member
 
Join Date: Oct 2005
Posts: 302
Bongo is on a distinguished road
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-04-2008, 12:00 PM
Senior Member
 
Join Date: Oct 2005
Posts: 302
Bongo is on a distinguished road
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);
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-04-2008, 02:25 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,159
matrixebiz is on a distinguished road
Thank you for the info
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-04-2008, 10:38 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,159
matrixebiz is on a distinguished road
Not sure what this is doing - pair = Symbol(); wouldn't compile so I removed it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 07-05-2008, 01:35 AM
Senior Member
 
Join Date: Feb 2007
Posts: 875
FerruFx is on a distinguished road
Quote:
Originally Posted by matrixebiz View Post
Not sure what this is doing - pair = Symbol(); wouldn't compile so I removed it.
Yes you can remove it. This line is for other stuff in the rest of the code where the example was taken.

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

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


All times are GMT. The time now is 01:41 PM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.