Multi-timeframe indicator without repainting: how do you read the higher-TF value safely?
Such things have been discussed a lot of times on this forum, with a lot of inputs and ideas. Did you make a search before posting ?
You agree to website policy and terms of use
Hello everyone,
I am working on a small multi-timeframe trend panel (M15 chart showing H1 and H4 values) and I keep running into the same three issues that I see in many MTF indicators shared online:
For point 1 and 2 this is the helper I use at the moment. It always takes the last closed higher-TF bar for a given chart bar, and returns false if the data is not ready, so the caller can return 0 from OnCalculate() and try again on the next tick:
bool GetClosedHTFValue(const int handle, const ENUM_TIMEFRAMES htf, const datetime barTime, double &value) { if(BarsCalculated(handle) <= 0) return false; // higher-TF indicator not calculated yet int shift = iBarShift(_Symbol, htf, barTime, false); if(shift < 0) return false; // higher-TF history not loaded yet double buf[1]; if(CopyBuffer(handle, 0, shift + 1, 1, buf) != 1) // +1 = last CLOSED HTF bar return false; value = buf[0]; return true; }The trade-off is clear: no repainting, but the signal shows up one higher-TF bar later (up to 1 hour late on H1). For a trend filter I am fine with that, for entries maybe not.
For point 3 I am thinking about copying the whole higher-TF buffer once per new higher-TF bar into an array, and then only mapping chart bars to it with iBarShift(), instead of calling CopyBuffer() for every bar.
Questions for other developers:
Thanks, I will share the final version once it is tested on gold and a few forex pairs.