Use GlobalVariableGet() in an indicator - page 2

 

It's impossible. You can't put two metatraders in the one directory and each MT use its own directory for Global Variable. You have to use the file and winapi functions.

 
Roger09:
It's impossible. You can't put two metatraders in the one directory and each MT use its own directory for Global Variable. You have to use the file and winapi functions.

Thank you for the response. I was afraid of that. Do you have any examples on how to use the winapi?

 

hi guys, anyone know how we can use global variable to keep stop alerting when change between timeframes. or show me a sample indicator that use it...

in regular mode, we stop repeating alerts by a datetime like:

TimeStamp != iTime(Symbol(),0,0)

but this not work in this case and each time you change timeframe it will alert again.

thanks

 
Alireza Yadegar:

hi guys, anyone know how we can use global variable to keep stop alerting when change between timeframes. or show me a sample indicator that use it...

in regular mode, we stop repeating alerts by a datetime like:

but this not work in this case and each time you change timeframe it will alert again.

thanks

This is one possibility (you can call IsNewBar() any number of time, but only call TickEnded() once at the end of OnTick()):

string gvLastTime;

int OnInit()
  {
   gvLastTime = "BarTime_"+EnumToString(_Period);
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
  }

void OnTick()
  {
   if (IsNewBar())
      Print ("Hello World");
   TickEnded();
  }

bool IsNewBar()
{
   datetime lastTime = (datetime)GlobalVariableGet(gvLastTime);
   datetime currTime = iTime(_Symbol,_Period,0);
   if (lastTime!=0 && lastTime<currTime)
      return (true);
   return (false);
}

void TickEnded()
{
   GlobalVariableSet(gvLastTime,iTime(_Symbol,_Period,0));
}
Documentation on MQL5: Timeseries and Indicators Access / Bars
Documentation on MQL5: Timeseries and Indicators Access / Bars
  • www.mql5.com
If the start_time and stop_time parameters are defined, the function returns the number of bars in the specified time interval, otherwise it returns the total number of bars. If data for the timeseries with specified parameters are not formed in the terminal by the time of the Bars() function call, or data of the timeseries are not synchronized...
 
Seng Joo Thio:

This is one possibility (you can call IsNewBar() any number of time, but only call TickEnded() once at the end of OnTick()):

wow, its worked. almost all last previous 24 hours i was busy with this problem!, thanks man.