Magic number help please - page 2

 

> would giving a different number in #define MAGICMACD 999998 to each EA solve the problem

Yes

But is much better to have MagicNumber as an extern - gives you the option of changing it, e.g. you want to run two copies of the EA with different settings

So you have

extern int MagicNumber = 999998;

and then the function call becomes

total=ActiveTradesForMagicNumber(Symbol(), MagicNumber);

and the order changes to

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,"macd sample",MagicNumber,0,Green);

FWIW

-BB-

 

If anyone would like to take the time, could you look at the "simple macd" in MT and edit and create a magic nimber there then post it here for me to copy it, thanks to anyone willing to take the time,

Robbo

 

Hello robbo, maybe attached will be of use.

.

I 'found' a file which I presume is the one you are after. I found in: C:\Program Files\...\experts\samples\MACD Sample.mq4

.

Save in ...\experts folder

Open with editor

Compile

Open terminal - if open and not see the expert listed, close terminal and restart. This should be remedy...

Drag expert to chart

Inputs window will appear. You will see your magic number at top with associated comment string.

.

The added source code has been annotated with a key string, as has the original source code, which has also been commented out.

.

hth

Files:
 

fbj

Thanks for the post - and nearly there

To finish, the line

total=OrdersTotal()

will need total generated by something like

int ActiveTradesForMagicNumber(string SymbolToCheck, int MagicNumberToCheck) **// all code from here on down
{
int icnt, itotal, retval;

retval=0;
itotal=OrdersTotal();

for(icnt=0;icnt<itotal;icnt++)
{
OrderSelect(icnt, SELECT_BY_POS, MODE_TRADES);
// check for opened position, symbol & MagicNumber
if(OrderType()<=OP_SELL && OrderSymbol()==SymbolToCheck && OrderMagicNumber()==MagicNumberToCheck) 
{

retval++;

//Print("Orders opened : ",retval);

}
}

return(retval);

FWIW

-BB-

 

LOL... yes, I posted on page.1 but today I did not reread!!!

Just wen snooping on HD and found a file and did quick shove in of extern.

Now, after post I see page.1 has some rather relevant 'added' code... what a laugh!

Oh well, my intentions were there but just not get the whole story - ummm, as per usual :o)

 

Hi FBJ, it makes thing alot simpler seeing what you have done, thanks, however, Barrowboy had posted in the archive about magic numbers and i did copy it, he has given me a different version to try and this is similar only the text highlighted is not present, only " extern int MagicNumber", so i will try this and comment on what results i have.

Thank you for taking the time though, it is appreciated, Robbo


EDIT

In short though, if i assign this EA to 4 different charts with 4 different currencies, when the criteria is met, a position will open on each one, even if there is a position open on a different currency


E_THIS_TO_ANY_VALUE_IN_THE = "RANGE 1...2147483647";
extern int eiMagicNumber = 12345678;
extern string __ORIGINAL_INPUTS__ = "__ARE BELOW THIS LINE__";
//--fbj/https://forum.mql4.com/24176/page2
extern double TakeProfit = 50;
extern double Lots = 0.1;
extern double TrailingStop = 30;
extern double MACDOpenLevel=3;
extern double MACDCloseLevel=2;
extern double MATrendPeriod=26;extern string CHANG

 
robbo wrote >>

Hi FBJ, it makes thing alot simpler seeing what you have done, thanks, however, Barrowboy had posted in the archive about magic numbers and i did copy it, he has given me a different version to try and this is similar only the text highlighted is not present, only " extern int MagicNumber", so i will try this and comment on what results i have.

Thank you for taking the time though, it is appreciated, Robbo

E_THIS_TO_ANY_VALUE_IN_THE = "RANGE 1...2147483647";
extern int eiMagicNumber = 12345678;
extern string __ORIGINAL_INPUTS__ = "__ARE BELOW THIS LINE__";
//--fbj/https://forum.mql4.com/24176/page2
extern double TakeProfit = 50;
extern double Lots = 0.1;
extern double TrailingStop = 30;
extern double MACDOpenLevel=3;
extern double MACDCloseLevel=2;
extern double MATrendPeriod=26;extern string CHANG

no probs. As you'll have read above, BB politely told me the full state of affairs. I just did not get right source or complete job requirement - hahaa, pays to read total thread - which I did not.

Have fun.

 
Hi BB and FBJ, I,m just waiting to see if what i have done is going to work, but in the mean time, could you explain the difference between FBJ,s code and BB,s code and how would they work differently or would they work the same but different coding ? just an offshoot of the main topic and a bit of education, Robbo
Reason: