Five_MA_Crossover

Indikátor zobrazující křížení až 5 různých průměrů. Indikátor je poměrně variabilní a umožňuje nastavení typu průměru: SMA, EMA, SMMA, LWMA či LSMA a umožňuje také vybrat s jaké ceny má vycházet. Zda z close, open, high, low, nebo medianu (high+low)/2, (high+low+close)/3, bevo váženého průměru (high+low+close+close)/4.

 

 

//+——————————————————————+
//|                                      Five_MA-Crossover_Alert.mq4 |
//|                                    Copyright © 2006, Robert Hill |
//| Modified by Robert Hill to add LSMA and alert or send email      |
//+——————————————————————+

/*
+——————————————————————+
| Allows you to enter five ma periods and it will then show you at |
| which point price crossed over. It is more useful on the shorter |
| periods that get obscured by the bars / candlesticks and when    |
| the zoom level is out. Also allows you then to remove the  mas   |
| from the chart.                                                  |
+——————————————————————+
*/
#property copyright “Copyright © 2006, Robert Hill)”

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 LawnGreen
#property indicator_width1 2
#property indicator_color2 Red
#property indicator_width2 2

extern bool DisplayArrows = true;
extern bool SoundON=true;
extern bool EmailON=false;

extern int MA_Mode1 = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int MA_Period1 =   5;
extern int PriceMode1 = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern int MA_Mode2 = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int MA_Period2 =   8;
extern int PriceMode2 = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern int MA_Mode3 = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int MA_Period3 =   14;
extern int PriceMode3 = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern int MA_Mode4 = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int MA_Period4 =   21;
extern int PriceMode4 = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
extern int MA_Mode5 = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma
extern int MA_Period5 =   34;
extern int PriceMode5 = 0;//0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2, 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4
double CrossUp[];
double CrossDown[];
int flagval1 = 0;
int flagval2 = 0;
//+——————————————————————+
//| Custom indicator initialization function                         |
//+——————————————————————+
int init()
{
//—- indicators
SetIndexStyle(0, DRAW_ARROW, EMPTY);
SetIndexArrow(0, 233);
SetIndexBuffer(0, CrossUp);
SetIndexStyle(1, DRAW_ARROW, EMPTY);
SetIndexArrow(1, 234);
SetIndexBuffer(1, CrossDown);
//—-
return(0);
}
//+——————————————————————+
//| Custom indicator deinitialization function                       |
//+——————————————————————+
int deinit()
{
//—-

//—-
return(0);
}

//+——————————————————————+
//| LSMA with PriceMode                                              |
//| PrMode  0=close, 1=open, 2=high, 3=low, 4=median(high+low)/2,    |
//| 5=typical(high+low+close)/3, 6=weighted(high+low+close+close)/4  |
//+——————————————————————+

double LSMA(int Rperiod, int prMode, int shift)
{
int i;
double sum, pr;
int length;
double lengthvar;
double tmp;
double wt;

length = Rperiod;

sum = 0;
for(i = length; i >= 1  ; i–)
{
lengthvar = length + 1;
lengthvar /= 3;
tmp = 0;
switch (prMode)
{
case 0: pr = Close[length-i+shift];break;
case 1: pr = Open[length-i+shift];break;
case 2: pr = High[length-i+shift];break;
case 3: pr = Low[length-i+shift];break;
case 4: pr = (High[length-i+shift] + Low[length-i+shift])/2;break;
case 5: pr = (High[length-i+shift] + Low[length-i+shift] + Close[length-i+shift])/3;break;
case 6: pr = (High[length-i+shift] + Low[length-i+shift] + Close[length-i+shift] + Close[length-i+shift])/4;break;
}
tmp = ( i – lengthvar)*pr;
sum+=tmp;
}
wt = sum*6/(length*(length+1));

return(wt);
}
//+——————————————————————+
//| Custom indicator iteration function                              |
//+——————————————————————+
int start() {
int limit, i, counter;
double tmp=0, price;
double MA1, MA2, MA3, MA4, MA5;
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=Bars-counted_bars;

for(i = 0; 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;

if (MA_Mode1 == 4)
{
MA1 = LSMA(MA_Period1, PriceMode1, i);

}
else
{
MA1 = iMA(NULL, 0, MA_Period1, 0, MA_Mode1, PriceMode1, i);
}

if (MA_Mode2 == 4)
{
MA2 = LSMA(MA_Period2, PriceMode2, i);

}
else
{
MA2 = iMA(NULL, 0, MA_Period2, 0, MA_Mode2, PriceMode2, i);
}
if (MA_Mode3 == 4)
{
MA3 = LSMA(MA_Period3, PriceMode3, i);

}
else
{
MA3 = iMA(NULL, 0, MA_Period3, 0, MA_Mode3, PriceMode3, i);
}
if (MA_Mode4 == 4)
{
MA4 = LSMA(MA_Period4, PriceMode4, i);

}
else
{
MA4 = iMA(NULL, 0, MA_Period4, 0, MA_Mode4, PriceMode4, i);
}
if (MA_Mode5 == 4)
{
MA5 = LSMA(MA_Period5, PriceMode5, i);

}
else
{
MA5 = iMA(NULL, 0, MA_Period5, 0, MA_Mode5, PriceMode5, i);
}

price = Close[i];
if ((price > MA1) && (price > MA2) && (price > MA3) && (price > MA4) && (price > MA5))
{
if (DisplayArrows) CrossUp[i] = Low[i] – Range*0.75;
if (i == 1 && flagval1==0)
{
flagval1=1;
flagval2=0;
if (SoundON) Alert(“BUY signal at Ask=”,Ask,”\n Bid=”,Bid,”\n Time=”,TimeToStr(CurTime(),TIME_DATE),” “,TimeHour(CurTime()),”:”,TimeMinute(CurTime()),”\n Symbol=”,Symbol(),” Period=”,Period());
if (EmailON) SendMail(“BUY signal alert”,”BUY signal at Ask=”+DoubleToStr(Ask,4)+”, Bid=”+DoubleToStr(Bid,4)+”, Date=”+TimeToStr(CurTime(),TIME_DATE)+” “+TimeHour(CurTime())+”:”+TimeMinute(CurTime())+” Symbol=”+Symbol()+” Period=”+Period());
}
}
else if ((price < MA1) && (price < MA2) && (price < MA3) && (price < MA4) && (price < MA5))
{
if (DisplayArrows) CrossDown[i] = High[i] + Range*0.75;
if (i == 1 && flagval2==0)
{
flagval2=1;
flagval1=0;
if (SoundON) Alert(“SELL signal at Ask=”,Ask,”\n Bid=”,Bid,”\n Date=”,TimeToStr(CurTime(),TIME_DATE),” “,TimeHour(CurTime()),”:”,TimeMinute(CurTime()),”\n Symbol=”,Symbol(),” Period=”,Period());
if (EmailON) SendMail(“SELL signal alert”,”SELL signal at Ask=”+DoubleToStr(Ask,4)+”, Bid=”+DoubleToStr(Bid,4)+”, Date=”+TimeToStr(CurTime(),TIME_DATE)+” “+TimeHour(CurTime())+”:”+TimeMinute(CurTime())+” Symbol=”+Symbol()+” Period=”+Period());
}
}
}

return(0);
}

Napsat komentář

Vaše emailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *