Navigation´╝ÜHome > Content >

MAX_NonLagMA.mq4

Time: 2018-11-12 | Download file:MAX_NonLagMA.mq4

//+------------------------------------------------------------------+=0A=
//|                                                  NonLagMA_v7.mq4 |=0A=
//|                                Copyright =A9 2006, TrendLaboratory |=0A=
//|            http://finance.groups.yahoo.com/group/TrendLaboratory |=0A=
//|                                   E-mail: [email protected] |=0A=
//+------------------------------------------------------------------+=0A=
#property copyright "Copyright =A9 2006, TrendLaboratory"=0A=
#property link      =
"http://finance.groups.yahoo.com/group/TrendLaboratory"=0A=
=0A=
=0A=
#property indicator_chart_window=0A=
#property indicator_buffers 3=0A=
#property indicator_color1 Yellow=0A=
#property indicator_width1 2=0A=
#property indicator_color2 Lime=0A=
#property indicator_width2 2=0A=
#property indicator_color3 Red=0A=
#property indicator_width3 2=0A=
=0A=
=0A=
//---- input parameters=0A=
extern int     Price          =3D 0;  //Apply to =
Price(0-Close;1-Open;2-High;3-Low;4-Median price;5-Typical =
price;6-Weighted Close) =0A=
extern int     Length         =3D 21;  //Period of NonLagMA=0A=
extern int     Displace       =3D 0;  //DispLace or Shift =0A=
extern double  PctFilter      =3D 0;  //Dynamic filter in decimal=0A=
extern int     Color          =3D 1;  //Switch of Color mode (1-color)  =0A=
extern int     ColorBarBack   =3D 1;  //Bar back for color mode=0A=
extern double  Deviation      =3D 0;  //Up/down deviation        =0A=
extern int     SoundAlertMode =3D 0;  //Sound Alert switch =0A=
//---- indicator buffers=0A=
double MABuffer[];=0A=
double UpBuffer[];=0A=
double DnBuffer[];=0A=
double trend[];=0A=
double Del[];=0A=
double AvgDel[];=0A=
=0A=
double alfa[];=0A=
int i, Phase, Len, Cycle=3D4;=0A=
double Coeff, beta, t, Sum, Weight, g;=0A=
double pi =3D 3.1415926535;    =0A=
bool   UpTrendAlert=3Dfalse, DownTrendAlert=3Dfalse;=0A=
//+------------------------------------------------------------------+=0A=
//| Custom indicator initialization function                         |=0A=
//+------------------------------------------------------------------+=0A=
  int init()=0A=
  {=0A=
   IndicatorBuffers(6);=0A=
   SetIndexStyle(0,DRAW_LINE);=0A=
   SetIndexBuffer(0,MABuffer);=0A=
   SetIndexStyle(1,DRAW_LINE);=0A=
   SetIndexBuffer(1,UpBuffer);=0A=
   SetIndexStyle(2,DRAW_LINE);=0A=
   SetIndexBuffer(2,DnBuffer);=0A=
   SetIndexBuffer(3,trend);=0A=
   SetIndexBuffer(4,Del);=0A=
   SetIndexBuffer(5,AvgDel); =0A=
   string short_name;=0A=
//---- indicator line=0A=
   =0A=
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));=0A=
//---- name for DataWindow and indicator subwindow label=0A=
   short_name=3D"MOACX NonLagMA ("+Length+")";=0A=
   IndicatorShortName(short_name);=0A=
   SetIndexLabel(0,"NonLagMA");=0A=
   SetIndexLabel(1,"Up");=0A=
   SetIndexLabel(2,"Dn");=0A=
//----=0A=
   SetIndexShift(0,Displace);=0A=
   SetIndexShift(1,Displace);=0A=
   SetIndexShift(2,Displace);=0A=
   =0A=
   SetIndexEmptyValue(0,EMPTY_VALUE);=0A=
   SetIndexEmptyValue(1,EMPTY_VALUE);=0A=
   SetIndexEmptyValue(2,EMPTY_VALUE);=0A=
   =0A=
   SetIndexDrawBegin(0,Length*Cycle+Length+1);=0A=
   SetIndexDrawBegin(1,Length*Cycle+Length+1);=0A=
   SetIndexDrawBegin(2,Length*Cycle+Length+1);=0A=
//----=0A=
   =0A=
   Coeff =3D  3*pi;=0A=
   Phase =3D Length-1;=0A=
   Len =3D Length*Cycle + Phase;  =0A=
   ArrayResize(alfa,Len);=0A=
   Weight=3D0;    =0A=
      =0A=
      for (i=3D0;i 0 )  limit=3DBars-counted_bars;=0A=
   if ( counted_bars < 0 )  return(0);=0A=
   if ( counted_bars =3D=3D0 )  limit=3DBars-Len-1; =0A=
   if ( counted_bars < 1 ) =0A=
   =0A=
   for(i=3D1;i=3D0;shift--) =0A=
   {	=0A=
      Sum =3D 0;=0A=
      for (i=3D0;i<=3DLen-1;i++)=0A=
	   { =0A=
      price =3D iMA(NULL,0,1,0,3,Price,i+shift);      =0A=
      Sum +=3D alfa[i]*price;=0A=
      =0A=
      }=0A=
   =0A=
	if (Weight > 0) MABuffer[shift] =3D (1.0+Deviation/100)*Sum/Weight;=0A=
   =0A=
      =0A=
      if (PctFilter>0)=0A=
      {=0A=
      Del[shift] =3D MathAbs(MABuffer[shift] - MABuffer[shift+1]);=0A=
   =0A=
      double sumdel=3D0;=0A=
      for (i=3D0;i<=3DLength-1;i++) sumdel =3D sumdel+Del[shift+i];=0A=
      AvgDel[shift] =3D sumdel/Length;=0A=
    =0A=
      double sumpow =3D 0;=0A=
      for (i=3D0;i<=3DLength-1;i++) =
sumpow+=3DMathPow(Del[shift+i]-AvgDel[shift+i],2);=0A=
      double StdDev =3D MathSqrt(sumpow/Length); =0A=
     =0A=
      double Filter =3D PctFilter * StdDev;=0A=
     =0A=
      if( MathAbs(MABuffer[shift]-MABuffer[shift+1]) < Filter ) =
MABuffer[shift]=3DMABuffer[shift+1];=0A=
      }=0A=
      =0A=
      if (Color>0)=0A=
      {=0A=
      trend[shift]=3Dtrend[shift+1];=0A=
      if (MABuffer[shift]-MABuffer[shift+1] > Filter) trend[shift]=3D 1; =0A=
      if (MABuffer[shift+1]-MABuffer[shift] > Filter) trend[shift]=3D-1; =0A=
         if (trend[shift]>0)=0A=
         {  =0A=
         UpBuffer[shift] =3D MABuffer[shift];=0A=
         if (trend[shift+ColorBarBack]<0) =
UpBuffer[shift+ColorBarBack]=3DMABuffer[shift+ColorBarBack];=0A=
         DnBuffer[shift] =3D EMPTY_VALUE;=0A=
//         if (SoundAlertMode>0 && trend[shift+1]<0 && shift=3D=3D0) =
PlaySound("alert2.wav");=0A=
         }=0A=
         if (trend[shift]<0) =0A=
         {=0A=
         DnBuffer[shift] =3D MABuffer[shift];=0A=
         if (trend[shift+ColorBarBack]>0) =
DnBuffer[shift+ColorBarBack]=3DMABuffer[shift+ColorBarBack];=0A=
         UpBuffer[shift] =3D EMPTY_VALUE;=0A=
//         if (SoundAlertMode>0 && trend[shift+1]>0 && shift=3D=3D0) =
PlaySound("alert2.wav");=0A=
         }=0A=
      }=0A=
   }=0A=
//----------   =0A=
   string Message;=0A=
   =0A=
//   if ( trend[2]<0 && trend[1]>0 && Volume[0]>1 && !UpTrendAlert)=0A=
=0A=
   if ( trend[2]<0 && trend[1]>0 && !UpTrendAlert)=0A=
	{=0A=
	Message =3D " "+Symbol()+" M"+Period()+": NLMA Signal for BUY";=0A=
	if ( SoundAlertMode>0 )=0A=
	 {=0A=
	  Alert (Message);=0A=
	  PlaySound("alert2.wav");=0A=
	  Sleep(100000);=0A=
     PlaySound("alert2.wav");=0A=
     Sleep(100000);=0A=
     PlaySound("alert2.wav");=0A=
    } =0A=
	UpTrendAlert=3Dtrue; DownTrendAlert=3Dfalse;=0A=
	} =0A=
	 	  =0A=
//	  if ( trend[2]>0 && trend[1]<0 && Volume[0]>1 && !DownTrendAlert)=0A=
=0A=
   if ( trend[2]>0 && trend[1]<0 && !DownTrendAlert)=0A=
	{=0A=
	Message =3D " "+Symbol()+" M"+Period()+": NLMA Signal for SELL";=0A=
	if ( SoundAlertMode>0 )=0A=
	 {=0A=
	  Alert (Message);=0A=
	  PlaySound("alert2.wav");=0A=
	  Sleep(100000);=0A=
     PlaySound("alert2.wav");=0A=
     Sleep(100000);=0A=
     PlaySound("alert2.wav");=0A=
    }=0A=
	DownTrendAlert=3Dtrue; UpTrendAlert=3Dfalse;=0A=
	} 	         =0A=
//----=0A=
	return(0);	=0A=
}=0A=
=0A=

Recommend