//+-------------------------------------------------------------------+ #property copyright "Copyright © 2018, Brian Lillard" #property description "MTF-MAC POINT HISTO" #property version "1.00" #property link "https://www.mql5.com/en/users/subgenius/seller" //+-------------------------------------------------------------------+ #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 Lime #property indicator_color2 Green #property indicator_color3 Red #property indicator_color4 Maroon #property strict //+-------------------------------------------------------------------+ input ENUM_MA_METHOD Method1 = MODE_EMA; // MA Fast Method input int Period1 = 10; // MA Fast Period input ENUM_APPLIED_PRICE Price1 = PRICE_OPEN; // MA Fast Price input int Shift1 = 0; // MA Fast Shift input ENUM_MA_METHOD Method2 = MODE_EMA; // MA Slow Method input int Period2 = 200; // MA Slow Period input ENUM_APPLIED_PRICE Price2 = PRICE_OPEN; // MA Slow Price input int Shift2 = 0; // MA Slow Shift //+-------------------------------------------------------------------+ long ExtChartID=0; int curr_scale,width[6]={1,2,2,4,8,15}; int scale0 = 1; // Width scale 1 int scale1 = 2; // Width scale 2 int scale2 = 2; // Width scale 3 int scale3 = 4; // Width scale 4 int scale4 = 8; // Width scale 5 int scale5 = 15; // Width scale 6 double DNDC[],DN[],UPDC[],UP[]; //+-------------------------------------------------------------------+ double dMA(int per,int shi,int met,int pri,int bar) { return(NormalizeDouble(iMA(NULL,0,per,shi,met,pri,bar),Digits)); } //+-------------------------------------------------------------------+ int OnInit() { IndicatorBuffers(4); ExtChartID=ChartID(); curr_scale=(int)ChartGetInteger(ExtChartID,CHART_SCALE); width[0]=scale0; width[1]=scale1; width[2]=scale2; width[3]=scale3; width[4]=scale4; width[5]=scale5; SetIndexBuffer(0,UP); SetIndexStyle(0,DRAW_HISTOGRAM,0.0,width[curr_scale]); SetIndexLabel(0,"UP"); SetIndexBuffer(1,UPDC); SetIndexStyle(1,DRAW_HISTOGRAM,0.0,width[curr_scale]); SetIndexLabel(1,"UP Decrease"); SetIndexBuffer(2,DN); SetIndexStyle(2,DRAW_HISTOGRAM,0.0,width[curr_scale]); SetIndexLabel(2,"DN"); SetIndexBuffer(3,DNDC); SetIndexStyle(3,DRAW_HISTOGRAM,0.0,width[curr_scale]); SetIndexLabel(3,"DN Decrease"); IndicatorDigits(Digits); IndicatorShortName("MTF-MAC POINT HISTO"); return(INIT_SUCCEEDED); } //+-------------------------------------------------------------------+ 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 counted_bars=Bars-IndicatorCounted()-1; for(int shift=counted_bars;shift>=0;shift--) { double FMA=dMA(Period1,Shift1,Method1,Price1,shift),SMA=dMA(Period2,Shift2,Method2,Price2,shift); double FMA1=dMA(Period1,Shift1,Method1,Price1,shift+1),SMA1=dMA(Period2,Shift2,Method2,Price2,shift+1); if(FMA > SMA) { if (FMA1 - SMA1 <= FMA - SMA) { UPDC[shift]=EMPTY_VALUE; DN[shift]=EMPTY_VALUE; DNDC[shift]=EMPTY_VALUE; UP[shift]=FMA - SMA; } if (FMA1 - SMA1 > FMA - SMA) { UP[shift]=EMPTY_VALUE; DN[shift]=EMPTY_VALUE; DNDC[shift]=EMPTY_VALUE; UPDC[shift]=FMA - SMA; } } else { if(SMA1 - FMA1 <= SMA - FMA) { UP[shift]=EMPTY_VALUE; UPDC[shift]=EMPTY_VALUE; DNDC[shift]=EMPTY_VALUE; DN[shift]=FMA- SMA; } if(SMA1 - FMA1 > SMA - FMA) { UP[shift]=EMPTY_VALUE; UPDC[shift]=EMPTY_VALUE; DN[shift]=EMPTY_VALUE; DNDC[shift]=FMA - SMA; } } } return(rates_total); } //+------------------------------------------------------------------+ void OnChartEvent(const int id,const long &lparam,const double &dparam,const string &sparam) { if(id==CHARTEVENT_CHART_CHANGE && curr_scale!=(int)ChartGetInteger(ExtChartID,CHART_SCALE)) { OnInit(); ChartRedraw(ExtChartID); } } //+------------------------------------------------------------------+