//+------------------------------------------------------------------+ //| MaPercent.mq4 | //| Copyright © 2018, atico | //| tidicofx@yahoo.com | //| developed for fxaria | //+------------------------------------------------------------------+ #property copyright "Copyright © 2018, atico" #property link "www.atico.com" #property version "1.00" #property strict #property indicator_separate_window #property indicator_buffers 1 #property indicator_color1 clrDodgerBlue #property indicator_width1 1 //+------------------------------------------------------------------+ //| Input Parameters Definition | //+------------------------------------------------------------------+ input int MaPeriod = 400; input ENUM_MA_METHOD MaMethod = MODE_SMA; input ENUM_APPLIED_PRICE MaApplied = PRICE_CLOSE; //+------------------------------------------------------------------+ //| Local Parameters Definition | //+------------------------------------------------------------------+ string lbl = "MaPercent."; double map[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //------------------------------------------------------------------ IndicatorShortName("Ma ("+IntegerToString(MaPeriod)+") Percent"); SetIndexBuffer(0, map); SetIndexStyle(0, DRAW_LINE); SetIndexLabel(0, "Ma Percent"); //------------------------------------------------------------------ return (INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //------------------------------------------------------------------ //------------------------------------------------------------------ } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate (const int rates_total, // size of input time series const int prev_calculated, // bars handled in previous call const datetime& time[], // Time const double& open[], // Open const double& high[], // High const double& low[], // Low const double& close[], // Close const long& tick_volume[], // Tick Volume const long& volume[], // Real Volume const int& _spread[] // Spread ) { //------------------------------------------------------------------ int limit = rates_total - prev_calculated; if (prev_calculated == 0) limit --; if (limit < 1) limit = 1; for (int i = limit; i >= 0; i --) { double ma = iMA(NULL, 0, MaPeriod, 0, MaMethod, MaApplied, i); map[i] = MathAbs(ma-close[i])*100/close[i]; } //------------------------------------------------------------------ return (rates_total); } //+------------------------------------------------------------------+ void OnTimer() { //------------------------------------------------------------------ //------------------------------------------------------------------ } //+------------------------------------------------------------------+