//+------------------------------------------------------------------+ //| Average Speed.mq5 | //| Copyright 2013, Totom Sukopratomo | //| https://login.mql5.com/en/users/tomsuk001 | //+------------------------------------------------------------------+ //////////////////////////////////////////// //-------------------------------------- // This is the Aritmatical approach // Speed // http://en.wikipedia.org/wiki/Speed // v = d / t // d = distance between priceseries // t = timeframe // speed unit ---> point / minute // ---- // Average Speed // using Aritmathic Mean // http://en.wikipedia.org/wiki/Arithmetic_mean#Definition // http://upload.wikimedia.org/math/2/1/a/21a3e8a3a9291e84e2a2cce5fc91d297.png // A = 1/n(x1+,...,+xn) // where: // x = speed // n = days // speed unit ---> point / minute //--------------------------------------- ///////////////// #property copyright "Copyright 2013, Totom Sukopratomo" #property link "https://login.mql5.com/en/users/tomsuk001" #property version "2.00" #property indicator_separate_window #property indicator_minimum 0 #property indicator_buffers 1 #property indicator_plots 1 //--- plot Output #property indicator_label1 "Output" #property indicator_type1 DRAW_HISTOGRAM #property indicator_color1 clrGreen #property indicator_style1 STYLE_SOLID #property indicator_width1 2 //--- input parameters input int n=3; input ENUM_APPLIED_PRICE price=PRICE_CLOSE; //--- indicator buffers double OutputBuffer[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,OutputBuffer,INDICATOR_DATA); //--- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- int limit; if(prev_calculated==0) { limit=n; } else { limit=prev_calculated-1; } for(int i=limit; i