How to get correct result on OnInit() or OnStart() such as function : BarsCalculated() , CopyBuffer()...
Sometimes we want the program to execute only once. So We use OnInit() or OnStart() . But I find that some code cannot be executed.
Such as:
The result is -1.
Even I change it:
the result is "Wrong".
I want to get the correct result. How to do it?
Please don't tell me use OnTick() or OnCalculate()!!! I just want to get correct result only in OnStart() or OnInit().
Thanks!!
The OnStart() function is the Start event handler, which is automatically generated only for running scripts.
The BarsCalculated() returns the number of calculated data for the specified indicator.
The OnStart() function is the Start event handler, which is automatically generated only for running scripts.
The BarsCalculated() returns the number of calculated data for the specified indicator.
I know what your say. I want to execute someting about Indicator just only once. So I try to use it OnStart() or Oninit(). But any attempt will be failed. So I want to kown Is there any good idea with OnStart() or Oninit().
void OnStart() { Print(GetTickCount()); int handle=iMA(_Symbol,_Period,15,0,MODE_SMA,PRICE_CLOSE); while(BarsCalculated(handle)<0) Sleep(500); Print(GetTickCount()); if(BarsCalculated(handle)>0) { Print(BarsCalculated(handle)); for(int i=0;i<100;i++) { if(BarsCalculated(handle)>0) Print(i); else Sleep(500); } } else Print("Wrong"); }
GetTickCount() shows milliseconds since terminal start.
In indicators you can't use Sleep(), but a timeframe change reinitializes it.
GetTickCount() shows milliseconds since terminal start.
In indicators you can't use Sleep(), but a timeframe change reinitializes it.
Thank you very much.
Dont really know why i am having errors with the ode below, please can anyone assist me. i am a newby.
Thanks
{
Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Sometimes we want the program to execute only once. So We use OnInit() or OnStart() . But I find that some code cannot be executed.
Such as:
The result is -1.
Even I change it:
the result is "Wrong".
I want to get the correct result. How to do it?
Please don't tell me use OnTick() or OnCalculate()!!! I just want to get correct result only in OnStart() or OnInit().
Thanks!!