//+------------------------------------------------------------------+ //| bool newBar() //| Returns true if a new bar is detected on the Chart Symbol/Period that //| the EA is attached to. | //+------------------------------------------------------------------+ bool newBar() { static datetime lastbar; datetime curbar = iTime(_Symbol,_Period,0); if(lastbar != curbar && BarsCalculated(handle_MA)>0) { lastbar = curbar; return(true); } return(false); } //+------------------------------------------------------------------+
Hi Ernst,
Thanks for your post. I don't think that will work as there doesn't seem to be any bars calculated ever when daily is selected as the timeframe in tester settings. It seems like the data is not being loaded. With an SMA period of 50 it works OK but 100 and 200 does not work.
Any other ideas?
Cheers
Hi Ernst,
Thanks for your post. I don't think that will work as there doesn't seem to be any bars calculated ever when daily is selected as the timeframe in tester settings. It seems like the data is not being loaded. With an SMA period of 50 it works OK but 100 and 200 does not work.
Any other ideas?
Cheers
It seems to only load the right amount of bars if the test starts on 2019.11.25 and ends today. For me anyway.
void OnTick() { //--- bool newbar=NewBar(); if(newbar) { double MA[]; if(CopyBuffer(handleMA,0,0,1,MA)==WRONG_VALUE) { Print("CopyBuffer failed. Error: ",_LastError); return; } printf("Date: %s MA: %f",TimeToString(TimeCurrent(),TIME_DATE),MA[0]); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ bool NewBar() { static datetime preTime=0; datetime curTime=iTime(_Symbol,_Period,0); if(preTime!=curTime && BarsCalculated(handleMA)>0) { preTime=curTime; return(true); } //--- return(false); } //+------------------------------------------------------------------+ 2022.01.26 16:18:53.107 EURUSD,Weekly: history cache allocated for 214 bars and contains 96 bars from 2017.12.31 00:00 to 2019.10.27 00:00 2022.01.26 16:18:53.107 EURUSD,Weekly: history begins from 2017.12.31 00:00 2022.01.26 16:19:13.073 2019.11.25 00:01:00 Date: 2019.11.25 MA: 1.141771 2022.01.26 16:19:13.498 2019.11.26 00:00:00 Date: 2019.11.26 MA: 1.141766

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone,
I have an EA which uses a daily timeframe for trading but also uses a weekly timeframe as a filter. When testing the EA I noticed that BarsCalculated returns -1 (No data). After playing around for a bit I created the following code to test this out further.
The behaviour is different depending on what I select for the trading timeframe under settings of the tester. When it is set to Daily I get BarsCalculated = -1 and when it is set to Weekly I get 103. Is there a way of forcing the correct amonut of weekly data to be loaded within the code when I have daily selected in tester settings? Any help would be appreciated.