//+------------------------------------------------------------------+ //| Directed Movement.mq4 | //| Yuriy Tokman (YTG) | //| http://ytg.com.ua/ | //+------------------------------------------------------------------+ #property copyright "Yuriy Tokman (YTG)" #property link "http://ytg.com.ua/" #property version "1.00" #property strict #property indicator_separate_window #property indicator_buffers 5 #property indicator_color2 Red #property indicator_color3 Lime #property indicator_color4 Yellow #property indicator_color5 Aqua #property indicator_width2 1 #property indicator_width3 1 #property indicator_width4 1 #property indicator_width5 1 #property indicator_level1 30.0 #property indicator_level2 70.0 //---- extern int PERIOD=5; extern double up_line = 70; extern double dn_line = 30; //---- buffers double BU0[]; double BU1[]; double BU2[]; double BU3[]; double BU4[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping IndicatorShortName("Directed Movement "+DoubleToStr(PERIOD,0)); SetIndexBuffer(0, BU0); SetIndexStyle(0, DRAW_NONE); SetIndexBuffer(1, BU1); SetIndexStyle(1,DRAW_LINE); SetIndexDrawBegin(1,PERIOD*4); SetIndexBuffer(2, BU2); SetIndexStyle(2, DRAW_LINE); SetIndexDrawBegin(2,PERIOD*4); SetIndexBuffer(3, BU3); SetIndexStyle(3,DRAW_ARROW); SetIndexArrow(3,108); SetIndexDrawBegin(3,PERIOD*4); SetIndexBuffer(4, BU4); SetIndexStyle(4, DRAW_ARROW); SetIndexArrow(4,108); SetIndexDrawBegin(4,PERIOD*4); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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=rates_total - prev_calculated; if(prev_calculated==0)limit--; else limit++; //---- if(prev_calculated==0)limit=Bars-PERIOD*2; for(int i=0; i=BU2[i+2] && BU1[i+1]=up_line) BU3[i+1] = BU2[i+1]; if(BU1[i+2]<=BU2[i+2] && BU1[i+1]>BU2[i+1] && BU2[i+2]<=dn_line) BU4[i+1] = BU2[i+1]; } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+