//+------------------------------------------------------------------+ //| MAMy_Cross(AM).mq4 | //| Andrey Matvievskiy | //| | //+------------------------------------------------------------------+ #property copyright "Andrey Matvievskiy" #property link "" //---- #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 Red #property indicator_color2 Red #property indicator_color3 Silver #property indicator_color4 Silver //---- double CrossUp1[]; double CrossDown1[]; double CrossUp2[]; double CrossDown2[]; extern int period = 3; extern int ma_method = 3; extern int CountedBars = 3; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0, DRAW_ARROW,0,0); SetIndexArrow(0, 233); SetIndexBuffer(0, CrossUp1); SetIndexStyle(1, DRAW_ARROW,0,0); SetIndexArrow(1, 234); SetIndexBuffer(1, CrossDown1); SetIndexStyle(2, DRAW_ARROW,0,0); SetIndexArrow(2, 233); SetIndexBuffer(2, CrossUp2); SetIndexStyle(3, DRAW_ARROW,0,0); SetIndexArrow(3, 234); SetIndexBuffer(3, CrossDown2); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, counter; 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; //---- double close = iMA(NULL, 0, period, 0, ma_method, 0, i); double open = iMA(NULL, 0, period, 0, ma_method, 1, i); double weighted = iMA(NULL, 0, period, 0, ma_method, 6, i); double close_2 = iMA(NULL, 0, period, 0, ma_method, 0, i+1); double open_2 = iMA(NULL, 0, period, 0, ma_method, 1, i+1); double weighted_2 = iMA(NULL, 0, period, 0, ma_method, 6, i+1); //---- double X = ((weighted - open) + (close - weighted))*1000; double Y = (close - weighted)*1000; double X_2 = ((weighted_2 - open_2) + (close_2 - weighted_2))*1000; double Y_2 = (close_2 - weighted_2)*1000; //---- if ((Y > 0) &&(Y_2 < 0)) { CrossUp1[i]=Low[i] - Range*0.3; } else if ((Y < 0) &&(Y_2 > 0)) { CrossDown1[i]=High[i] + Range*0.3; } if ((X > 0) &&(X_2 < 0)) { CrossUp2[i]=Low[i] - Range*0.6; } else if ((X < 0) &&(X_2 > 0)) { CrossDown2[i]=High[i] + Range*0.6; } } return(0); } //+------------------------------------------------------------------+