At the first look I see one problem: for different symbols the new candle appears at different times depending on the last tick.
If your chart is e.g. EURUSD with many ticks and another symbol e.g. NZDUSD the last tick of this symbol might still have a time stamp for the previous candle!
How do you deal with this?
To check the new bar why don't you just do:
static datetime tmeBar = 0; bool newBar = false; if ( tmeBar != iTime(_Symbol,_Period,0) ) { tmeBar = iTime(_Symbol,_Period,0); newBar = true; }
Maybe helps you.
int prevbars[]; string symbols[]; ////////////////////////////////////////////////////////////// int OnInit() { ////// int symbols_tot=SymbolsTotal(true); ArrayResize(symbols,symbols_tot); ArrayResize(prevbars,symbols_tot); string name_symb=""; for(int i=0;i<symbols_tot;i++) { name_symb=SymbolName(i,true); symbols[i]=name_symb; prevbars[i]=iBars(name_symb,TimeFrame); } EventSetTimer(1); ... } ////////////////////////////////////////////////////////////////////////////////////////////////// void OnTimer() { //all symbols for(int i=0;i<ArraySize(symbols);i++) { if(prevbars[i]==iBars(symbols[i],TimeFrame)) continue; ... prevbars[i]=iBars(symbols[i],TimeFrame); } }
Thank you for your help. I will test it. Sounds easy to keep the last bar in memory.
I'm wondering why my code failed sometimes.
FamWue:
Thanks to whom?
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hey guys,
before starting i want to apologize for my bad english. I will try to explain my problem and hope you can understand me und help me.
With this code below my text i'm trying to scan a lot of forex pairs from one chart.
The code should run the main part only in the first minute of an hour and show me if the pairs startet a new candle. After this i want to check the candle of the last hour (No.1) for traing set ups.
This code is an example for this post. It should show me the number of the candle of the last hour of each pair.
My problem is:
Sometimes it shows me the wrong number and i can't find why. I get the number of the candle two hours before
altough the next candle started.
Can anyone finde the misstake?
Thanks a lot!