There is a separate file for each time frame. So there will be a file that stores the last daily, h4, and h1 last candle time.
Each function accepts a period parameter.
What ever timeframe you call, it will create a file for it...
//the filename "PABS"+symbol+timeframe
But I make sure I record the current candle time on init() so nothing should happen for the current candle...
bool writeCurrentCandleTime(string symbol, int timeframe) { datetime currentCandleTime = iTime(symbol, timeframe, 0); string setTime = TimeToStr(currentCandleTime); if(StoreStringToFile(setTime, "PABS"+symbol+timeframe)) { return(true); } return(false); } int OnInit() { writeCurrentCandleTime(Symbol(), Period()); }

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
I have an indicator which will send notifications when candle patterns are detected. On only want it to run when the code sees a new candle as formed.
I record the current candle open time to a file. So if the indicator is closed, and re-opened it knows where to pick up from.
Here are the functions I am using. The file storing functions are working fine so I won't clog up the post by putting those here.
I call the main function from within onCalculate which should take care of everything
sendCandlePatternNotificationMsg(Period());
Everything seems to be working, except when I flick through time frames. If I select a timeframe the indicator had not encountered before, it sends an alert if something is there.
I don't want this to happen, so to get around it, I am writing a new candle time inside the init code...
This doesn't work for some reason.
When the indicator comes across a new timeframe, sends out the alert without waiting for a new candle to form.
It only fails on the very first time the code is exposed to a new timeframe, then it works ok.
Can anyone see what I am missing here.