//+------------------------------------------------------------------+ //| Alert_OsMA.mq4 | //| Copyright © 2011 | //| | //| Awesome oscillator (AO) to be the first bar which changes the //| direction from short to long ((Acc0 > 0) && (Acc0 > Acc1)) //| for long (not necessary to cross 0 line); //| //| OsMA to change the direction (not necessary to cross 0 line) //| so I added just (OsMA0 > OsMA1); //| Accelerator (Acc) to be in the same direction AND with //| the “0” line already crossed, //| so I added ((Acc0 > 0) && (Acc0 > Acc1)). //| I attach a picture, the red lines should be short signals //| Friday in GBP/JPY, the blue lines long signals; //| Trying to simplify it, I reduced the formula //| just to (AO0>AO1) or (OsMA0 > OsMA1) or (ACC0 > 0) //+------------------------------------------------------------------+ #property copyright "Copyright © 2011" //---- indicator settings #property indicator_chart_window // Set indicator_buffers to number of output buffers #property indicator_buffers 2 #property indicator_color1 MediumBlue #property indicator_color2 Crimson #property indicator_width1 2 #property indicator_width2 2 //---- indicator buffers extern bool AlertOn = true; extern bool UseAcc_6_13 = true; double OsMA[]; double Acc[]; double AO[]; double AccHelper[]; double Up[]; double Down[]; int CurrentTrend = 0; int PriorTrend = 0; int starttime = 0; bool NewBar() { static datetime LastTime = 0; if (Time[0] != LastTime) { LastTime = Time[0]; return (true); } else return (false); } //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { IndicatorBuffers(6); // add 3 for working buffers SetIndexStyle(0, DRAW_ARROW, EMPTY); SetIndexArrow(0, 233); SetIndexBuffer(0, Up); SetIndexStyle(1, DRAW_ARROW, EMPTY); SetIndexArrow(1, 234); SetIndexBuffer(1, Down); // Following are working buffers SetIndexBuffer(2,Acc); SetIndexBuffer(3,OsMA); SetIndexBuffer(4,AO); SetIndexBuffer(5,AccHelper); starttime = TimeLocal(); //---- name for DataWindow and indicator subwindow label IndicatorShortName("Momentum Alert"); return(0); } int deinit() { return(0); } //+------------------------------------------------------------------+ //| Oscillators | //+------------------------------------------------------------------+ int start() { int limit, i, counter; int counted_bars=IndicatorCounted(); double Range, AvgRange; double OsMA0,OsMA1; double Acc0, Acc1; double AO0, AO1, AO2; //---- macds counted in the 1-st additional buffer //---- check for possible errors if(counted_bars<0) return(-3); //---- last counted bar will be recounted if(counted_bars>0) counted_bars--; limit = Bars - counted_bars; /// control the loops if (limit < 5) limit = 5; // Make sure it continues to paint // Get values in working buffers for(i = 0; i <= limit; i++) { // Standard OsMA uses close for price // OsMA[i]=iOsMA(NULL,0,12,26,9,PRICE_WEIGHTED,i); OsMA[i]=iOsMA(NULL,0,12,26,9,PRICE_CLOSE,i); AO[i]=iMA(NULL,0,5,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,34,0,MODE_SMA,PRICE_MEDIAN,i); // Acc actually uses AO for the first values // You first need this for your version of Acc AccHelper[i]=iMA(NULL,0,6,0,MODE_SMA,PRICE_MEDIAN,i)-iMA(NULL,0,13,0,MODE_SMA,PRICE_MEDIAN,i); } // This gets values for Acc for(i = 0; i <= limit; i++) { if (UseAcc_6_13) Acc[i]=iMAOnArray(AccHelper,Bars,5,0, MODE_SMA,i); // Your version else Acc[i]=iMAOnArray(AO,Bars,5,0, MODE_SMA,i); // MT4 version } // Now put arrows on chart for(i = 0; i <= limit; i++) { // Determine placement of arrows counter=i; Range=0; AvgRange=0; for (counter=i ;counter<=i+9;counter++) { AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]); } Range=AvgRange/10; //---- dispatch values between 2 buffers Acc0=Acc[i]; Acc1=Acc[i+1]; OsMA0=OsMA[i]; OsMA1=OsMA[i+1]; AO0=Acc[i]; AO1=Acc[i+1]; AO2=Acc[i+2]; // if ((Acc0 > 0) && (Acc0 > Acc1) && (OsMA0 > OsMA1) && (AO0>AO1) && (AO1 Acc1) && (OsMA0 > OsMA1) && (AO0>AO1) && (AO1