There is no need to NormalizeDouble on the Bid.
Also be careful with the scope of your variables. Only static variables or variables with global scope will hold their value between calls. Local variables will not.
It would be a lot easier to use OnTimer().
int OnInit()
{
EventSetTimer(1); // set the timer for 1 second
return(INIT_SUCCEEDED);
}
void OnTimer()
{
price=Bid;
Print("Updated");
}
As you're using the predefined variable Bid, I'm surmising this is MQL4? In which case I'll move to the MQL4 section.
There is no need to NormalizeDouble on the Bid.
Also be careful with the scope of your variables. Only static variables or variables with global scope will hold their value between calls. Local variables will not.
It would be a lot easier to use OnTimer().
int OnInit()
{
EventSetTimer(1); // set the timer for 1 second
return(INIT_SUCCEEDED);
}
void OnTimer()
{
price=Bid;
Print("Updated");
}
As you're using the predefined variable Bid, I'm surmising this is MQL4? In which case I'll move to the MQL4 section.
Yes OnTimer() is easier, only if it worked on my build 1045 but it does not. Tested like below
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
EventSetTimer(60);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
Print("A minute passed");
}
My variables are on Global scope.
Yes OnTimer() is easier, only if it worked on my build 1045 but it does not. Tested like below
Are you testing it through strategy tester?
OnTimer() doesn't work in the strategy tester.
Add your EA to a live chart (it doesn't matter that the markets are closed - you don't need a tick)
honest_knave: OnTimer() doesn't work in the strategy tester.
|
In backtest
OnTimer() not performs (M. Ali) - MQL4 forum Chart Event For MT4 Backtester (Migel) - MQL4 forum |
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
int TimeBar;
//Fill price with Bid and record time
if (price==0)
{
if(price=NormalizeDouble(Bid,Digits)) TimeBar=GetTickCount();
}
//Now if 1 second pass, update price value with current Bid
if (price!=0)
{
if (TimeBar<GetTickCount()-time)
{
if(price=NormalizeDouble(Bid,Digits)) TimeBarB=GetTickCount();
Print("Updated");
}
}