Multiple Currency pairs - auto setting magic#

To add comments, please log in or register
Larry
1339
Larry  

I am growing very tired of going to each currency pair chart and setting the magic number each time I compile my code on the test (not talking about tester) I am running. Is there a code snippet out there where I can count all the currency pair charts open with an EA called "bob" (for example) and then assign the magic number to be the last count + 1?

For example, say there are 5 charts open, 3 of them have the Bob EA on them. So when I add the 6th chart and apply "Bob" EA, I want the EA code to recognize that there are 3 current "Bob" EA driven charts so the magic number for the 6th chart will be MagicNumberTotalCount +1.

Joao Rosas
391
Joao Rosas  

int magicForThisChart=0;



int init()

{

magicForThisChart = GlobalVariableGet("MagicNumberTotalCount"); // value for this chart

GlobalVariableSet("MagicNumberTotalCount", magicForThisChart+1); // update the value for the next chart.

}

Larry
1339
Larry  
abstract_mind wrote >>

int magicForThisChart=0;

int init()

{

magicForThisChart = GlobalVariableGet("MagicNumberTotalCount"); // value for this chart

GlobalVariableSet("MagicNumberTotalCount", magicForThisChart+1); // update the value for the next chart.

}

You are awesome!!! Thanks.

Larry
1339
Larry  

Ok, so I modified the code to be like this below, I disabled the "Expert Advisors" button, compiled the EA, then enabled the "Expert Advisors" button. Now 2 of the open trades has a magicnumber that is the same as a new one, but the new one is on a different currency pair now. Any suggestions? My next thought is maybe a global variable name that has the currency pair tied to it, but not sure this will work either.

   magicForThisChart = GlobalVariableGet("MagicNumberTotalCount"); // value for this chart
   if (magicForThisChart == 0)
      {
         magicForThisChart = magicnumber; // the default user entry value
         GlobalVariableSet("MagicNumberTotalCount", magicForThisChart+1); // update the value for the next chart.
      }
   else
      {
         magicForThisChart = GlobalVariableGet("MagicNumberTotalCount"); // value for this chart
         GlobalVariableSet("MagicNumberTotalCount", magicForThisChart+1); // update the value for the next chart.
      }
   
   magicnumber = magicForThisChart;
Joao Rosas
391
Joao Rosas  

Maybe you should put an initial value for the global variable in "terminal->tools->Global Variables".

On the other hand, I offer you this function, which I use for synchronization between EAs. This only works if you use one chart per currency.



int encode(string symbol)
{
int value=0;
for(int i=0;i<StringLen(symbol);i++)
value += i*StringGetChar(symbol,i);
return(value);
}


int start()

{

...

...

magicForThisChart = encode(Symbol())

}

To add comments, please log in or register