variable initialize?

 

Hi,

I want to make an EA single instance. ---- only can attach to 1 chart, neither any other symbol, nor same symbol but multi charts. But I can switch timeframe in this one chart.

I managed to write the following code:

datetime timeinit = TimeCurrent();
int init()
  {
   if(!GlobalVariableCheck("buy10_ON"))
   {
       GlobalVariableSet("buy10_ON",timeinit);
       return(0);
   }
  if(GlobalVariableGet("buy10_ON") <> timeinit )     Comment("another instance running, please detach manually.") ;
  return(0);
  }

int deinit()
  {
  if(GlobalVariableGet("buy10_ON") <> timeinit)      return(0);
  GlobalVariableDel("buy10_ON");
  return(0);
  }

int start()
  {  
   if(GlobalVariableGet("buy10_ON") <> timeinit )     
    {
    Comment("another instance running, please detach manually.") ;
    return(0);
    }
.......

But there's error: 'TimeCurrent' - initialization expected .....

So I tried to replace

datetime timeinit = TimeCurrent();

with:

MathSrand(1);

int timeinit = MathRand();

I got same error.

First of all, I want to put this timeinit in init(), but it can not pass data to deinit() or start(), so I put it Head Part. Now what?

Any idea?

Thanks.

 
joshatt:

Hi,

I want to make an EA single instance. ---- only can attach to 1 chart, neither any other symbol, nor same symbol but different timeframe chart. But I can switch timeframe in this one chart.

I managed to write the following code:

But there's error: 'TimeCurrent' - initialization expected .....

You can only initialize with a constant, not the return from a function.

Do this . . .

datetime timeinit;

timeinit = TimeCurrent();
 

Thanks for fast response.

RaptorUK:

You can only initialize with a constant, not the return from a function.

Do this . . .


Thanks for fast response.

This way got error, too: 'timeinit' - expression on global scope not allowed .....

 
joshatt:

Thanks for fast response.


Thanks for fast response.

This way got error, too: 'timeinit' - expression on global scope not allowed .....

Put . . .

timeinit = TimeCurrent();

. . in the init() function.

 

Wonderful !

~Cheers.

Reason: