#property description "MT4 Speed of Offline Chart Bar."

#property copyright "2014 Halley Comet"
#property version "1.2"
#property link "http://omnia-ea.eu/#"

#property icon "\\Images\\Comet.ico";

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1  Blue
#property indicator_minimum 0.0
#property indicator_width1 4

#include <Halley/MT4IndicatorManager.class.mqh>
#include <Halley/MT4IndicatorScope.class.mqh>
#include <Halley/MT4DrawingIndicator.class.mqh>

void main() {
	MT4IndicatorScope* scope = manager.destroyOnExit(new MT4IndicatorScope (""));
	manager.add(new SpeedBarIndicator(scope));
}

class SpeedBarIndicator: public MT4DrawingIndicator {
	MT4DrawingBuffer* extSpeedBuffer;
public:
	SpeedBarIndicator(MT4IndicatorScope* aScope) : MT4DrawingIndicator(aScope) {
		extSpeedBuffer = addDrawingBuffer("Speed");
		extSpeedBuffer.setType(DRAW_HISTOGRAM);
	}

	void calculate() {   
		string symb = scope.getSymbol().name();
		int period = scope.getTimeframe();
		for (int i = indicatorAdded(true)-1; i>=0; i--) {
			long difference = iTime(symb,period,i) - iTime(symb,period,i+1);
			extSpeedBuffer.set(i+1,(1.0/difference));
		}
		// current bar
		extSpeedBuffer.set(0,EMPTY_VALUE);
	}
};