//+------------------------------------------------------------------+ //| Stochastic_Cross_Levels(AM).mq4 | //| Andrey Matvievskiy | //| | //+------------------------------------------------------------------+ #property copyright "Andrey Matvievskiy" #property link "" #property indicator_chart_window #property indicator_buffers 6 #property indicator_color1 Aqua #property indicator_color2 Aqua #property indicator_color3 Silver #property indicator_color4 Silver #property indicator_color5 Orange #property indicator_color6 Orange //---- input parameters extern int KPeriod=5; extern int DPeriod=3; extern int Slowing=3; extern int MA_Method = 0; // SMA 0, EMA 1, SMMA 2, LWMA 3 extern int PriceField = 0; // Low/High 0, Close/Close 1 extern int L_1= 80; extern int L_2= 50; extern int L_3= 20; extern int CountedBars = 30; double CrossUp1[]; double CrossDown1[]; double CrossUp2[]; double CrossDown2[]; double CrossUp3[]; double CrossDown3[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0, DRAW_ARROW, EMPTY); SetIndexArrow(0, 233); SetIndexBuffer(0, CrossUp1); SetIndexStyle(1, DRAW_ARROW, EMPTY); SetIndexArrow(1, 234); SetIndexBuffer(1, CrossDown1); SetIndexStyle(2, DRAW_ARROW, EMPTY); SetIndexArrow(2, 233); SetIndexBuffer(2, CrossUp2); SetIndexStyle(3, DRAW_ARROW, EMPTY); SetIndexArrow(3, 234); SetIndexBuffer(3, CrossDown2); SetIndexStyle(4, DRAW_ARROW, EMPTY); SetIndexArrow(4, 233); SetIndexBuffer(4, CrossUp3); SetIndexStyle(5, DRAW_ARROW, EMPTY); SetIndexArrow(5, 234); SetIndexBuffer(5, CrossDown3); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, counter; double tmp=0; double fastMAnow, slowMAnow, fastMAprevious, slowMAprevious, fastMAprevious2; double Range, AvgRange; int counted_bars=IndicatorCounted(); //---- check for possible errors if(counted_bars<0) return(-1); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit=CountedBars; for(i = 1; i <= limit; i++) { counter=i; Range=0; AvgRange=0; for (counter=i ;counter<=i+9;counter++) { AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]); } Range=AvgRange/10; fastMAnow = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i); fastMAprevious = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i+1); fastMAprevious2 = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_MAIN, i+2); slowMAnow = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_SIGNAL, i); slowMAprevious = iStochastic(NULL, 0, KPeriod, DPeriod, Slowing,MA_Method, PriceField, MODE_SIGNAL, i+1); CrossUp1[i] = 0; CrossDown1[i] = 0; CrossUp2[i] = 0; CrossDown2[i] = 0; CrossUp3[i] = 0; CrossDown3[i] = 0; if ((fastMAnow > slowMAnow) && (fastMAprevious < slowMAprevious)) { CrossUp1[i] = Low[i] - Range*0.4; } else if ((fastMAnow < slowMAnow) && (fastMAprevious > slowMAprevious)) { CrossDown1[i] = High[i] + Range*0.4; } if ((fastMAnow > L_1) && (fastMAprevious < L_1)) { CrossUp2[i] = Low[i] - Range*0.2; } else if ((fastMAnow < L_1) && (fastMAprevious > L_1)) { CrossDown2[i] = High[i] + Range*0.2; } if ((fastMAnow > L_2) && (fastMAprevious < L_2)) { CrossUp2[i] = Low[i] - Range*0.2; } else if ((fastMAnow < L_2) && (fastMAprevious > L_2)) { CrossDown2[i] = High[i] + Range*0.2; } if ((fastMAnow > L_3) && (fastMAprevious < L_3)) { CrossUp2[i] = Low[i] - Range*0.2; } else if ((fastMAnow < L_3) && (fastMAprevious > L_3)) { CrossDown2[i] = High[i] + Range*0.2; } if ((fastMAprevious2 > fastMAprevious) && (fastMAprevious < fastMAnow)) { CrossUp3[i] = Low[i] - Range*0.6; } else if ((fastMAprevious2 < fastMAprevious) && (fastMAprevious > fastMAnow)) { CrossDown3[i] = High[i] + Range*0.6; } } return(0); }