Forex



Go Back   Forex Trading > Discussion Areas > Metatrader 4






Register
Welcome to Forex-TSD!, one of the largest Forex forums worldwide, where you will be able to find the most complete and reliable Forex information imaginable.

From the list below, select the forum that you want to visit and register to post, as many times you want. It’s absolutely free. Click here for registering on Forex-TSD.

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 03-11-2007, 12:54 AM
Member
 
Join Date: Sep 2006
Posts: 65
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 03-11-2007, 01:13 AM
Member
 
Join Date: Dec 2006
Posts: 67
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 03-11-2007, 01:23 AM
Member
 
Join Date: Sep 2006
Posts: 65
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 03-11-2007, 01: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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 07-04-2008, 01:45 AM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,215
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 12:04 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 07-04-2008, 12:23 PM
Senior Member
 
Join Date: Oct 2005
Posts: 474
Bongo is an unknown quantity at this point
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 12:46 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 07-04-2008, 01:00 PM
Senior Member
 
Join Date: Oct 2005
Posts: 474
Bongo is an unknown quantity at this point
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #8 (permalink)  
Old 07-04-2008, 03:25 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,215
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #9 (permalink)  
Old 07-04-2008, 11:38 PM
matrixebiz's Avatar
Senior Member
 
Join Date: Oct 2006
Posts: 1,215
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!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #10 (permalink)  
Old 07-05-2008, 02:35 AM
Senior Member
 
Join Date: Feb 2007
Posts: 985
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
__________________
FerruFx / www.ervent.net - Professional Coding Services (EAs/Indicators/Alerts)

BBVPS.com - Reliable Windows VPS For MT4 Hosting
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web 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 12:41 PM
Breakout EA Required fxwealth Metatrader 4 5 05-21-2007 03:28 PM
Some help please required Pervaz Suggestions for Trading Systems 2 01-22-2007 04:53 AM
Coding help required ozimacca Indicators - Metatrader 4 2 03-04-2006 12:36 AM


All times are GMT. The time now is 12:37 PM.



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