P. 1
3MA

3MA

|Views: 1|Likes:
Published by Clarken Tran

More info:

Published by: Clarken Tran on Aug 15, 2012
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

08/15/2012

pdf

text

original

//+------------------------------------------------------------------+ //| MA-Crossover_Alert.mq4 | //| Copyright © 2005, Jason Robinson (jnrtrading) | //| http://www.jnrtading.co.

uk | //| Modified by Robert Hill to add LSMA and alert or send email | //| Added Global LastAlert to try to have alert only on new cross | //| but does not seem to work. So indicator does alert every bar | //+------------------------------------------------------------------+ /* +------------------------------------------------------------------+ | Allows you to enter two ma periods and it will then show you at | | Which point they crossed over. It is more usful 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. (emas are initially set at 5 and 6) | +------------------------------------------------------------------+ */ #property copyright "Copyright © 2005, Jason Robinson (jnrtrading)" #property link "http://www.jnrtrading.co.uk" #property #property #property #property indicator_chart_window indicator_buffers 2 indicator_color1 LawnGreen indicator_color2 Red

extern bool SoundON=true; extern bool EmailON=false; extern int FastMA_Mode = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma extern int FastMA_Period = 5; extern int FastPriceMode = 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 SlowMA_Mode = 1; //0=sma, 1=ema, 2=smma, 3=lwma, 4=lsma extern int SlowMA_Period = 6; extern int SlowPriceMode = 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, 3); SetIndexArrow(0, 233); SetIndexBuffer(0, CrossUp); SetIndexStyle(1, DRAW_ARROW, EMPTY, 3); SetIndexArrow(1, 234); SetIndexBuffer(1, CrossDown); GlobalVariableSet("AlertTime"+Symbol()+Period(),CurTime()); GlobalVariableSet("SignalType"+Symbol()+Period(),OP_SELLSTOP); // GlobalVariableSet("LastAlert"+Symbol()+Period(),0); //---return(0); } //+------------------------------------------------------------------+

break.break. double tmp. sum+=tmp. i >= 1 . 4=median(high+low)/2. } //+------------------------------------------------------------------+ //| LSMA with PriceMode | //| PrMode 0=close. | //| 5=typical(high+low+close)/3. switch (prMode) { case 0: pr = Close[length-i+shift]. int prMode. return(wt). case 5: pr = (High[length-i+shift] + Low[length-i+shift] + Close[length-i+s hift])/3. case 6: pr = (High[length-i+shift] + Low[length-i+shift] + Close[length-i+s hift] + Close[length-i+shift])/4. tmp = 0.break.lengthvar)*pr. double wt. sum = 0. 6=weighted(high+low+close+close)/4 | //+------------------------------------------------------------------+ double LSMA(int Rperiod. int length.break. //---return(0). case 4: pr = (High[length-i+shift] + Low[length-i+shift])/2. } wt = sum*6/(length*(length+1)).break. case 1: pr = Open[length-i+shift]. double sum. // GlobalVariableDel("LastAlert"+Symbol()+Period()). 3=low. lengthvar /= 3. GlobalVariableDel("SignalType"+Symbol()+Period()). int shift) { int i. } tmp = ( i .//| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---GlobalVariableDel("AlertTime"+Symbol()+Period()). case 2: pr = High[length-i+shift]. i--) { lengthvar = length + 1. pr. length = Rperiod. for(i = length. case 3: pr = Low[length-i+shift]. 2=high. double lengthvar. } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ .break.break. 1=open.

i++) { counter=i. slowMAprevious = LSMA( SlowMA_Period. SlowPriceMode. i+1). } if ((fastMAnow > slowMAnow) && (fastMAprevious < slowMAprevious)) { if (i == 1 && flagval1==0){ flagval1=1. double tmp=0. fastMAprevious = iMA(NULL. i+1). 0. limit=Bars-counted_bars. int counted_bars=IndicatorCounted(). i <= limit. FastPriceMode. SlowPriceMode. } else { fastMAnow = iMA(NULL. //---. AvgRange=0. AvgRange. FastMA_Period. double Range. double fastMAnow. SlowMA_Period. 0. i+1). Range=0. 0. 0. fastMAprevious. for(i = 0. FastPriceM ode.counter<=i+9.int start() { int limit. . i. i+1). fastMAprevious = LSMA(FastMA_Period. //---. } else if ((fastMAnow < slowMAnow) && (fastMAprevious > slowMAprevious)) { if (i == 1 && flagval2==0) { flagval2=1.last counted bar will be recounted if(counted_bars>0) counted_bars--. } if (SlowMA_Mode == 4) { slowMAnow = LSMA( SlowMA_Period. SlowMA_Mode. SlowPriceM ode. FastMA_Mode. 0.check for possible errors if(counted_bars<0) return(-1). slowMAprevious = iMA(NULL. SlowPriceMode. } Range=AvgRange/10. FastPriceMode. } else { slowMAnow = iMA(NULL. 0. SlowMA_Period. i). FastPriceMode. FastMA_Mode. i). flagval1=0. i). flagval2=0. 0. if (FastMA_Mode == 4) { fastMAnow = LSMA(FastMA_Period. i). slowMAnow. for (counter=i .75. FastMA_Period. } CrossDown[i] = High[i] + Range*0. SlowMA_Mode. counter.counter++) { AvgRange=AvgRange+MathAbs(High[counter]-Low[counter]).Range*0. } CrossUp[i] = Low[i] .75. 0. slowMAprevious.

TIME_DATE)+" "+TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+P eriod()). } return(0)."BUY signal at Ask="+DoubleToStr( Ask. // } tmp = CurTime() + (Period()-MathMod(Minute().Period()))*60.Bid.OP_SELL). Bid="+DoubleToStr(Bid." ".5) // { if (SoundON) Alert("BUY signal at Ask=".TimeHour(CurTime()). } if (flagval2==1 && CurTime() > GlobalVariableGet("AlertTime"+Symbol()+Period( )) && GlobalVariableGet("SignalType"+Symbol()+Period())!=OP_SELL) { // if (GlobalVariableGet("LastAlert"+Symbol()+Period()) > -0.4)+".OP_BUY).Time ToStr(CurTime().TimeMinute(CurTime())." ".Period()). if (EmailON) SendMail("SELL signal alert".TIME_DATE)+" "+ TimeHour(CurTime())+":"+TimeMinute(CurTime())+" Symbol="+Symbol()+" Period="+Per iod())."\n Symbol=".tmp).TimeHour(CurTime())."SELL signal at Ask="+DoubleToSt r(Ask. if (EmailON) SendMail("BUY signal alert".TimeT oStr(CurTime()."\n Time="."\n Date=".5) // { if (SoundON) Alert("SELL signal at Ask=".4)+".Symbol()."\n Bid=". Date="+TimeToStr(CurTime().Ask.TIME_DATE)."\n Bid=". // GlobalVariableSet("LastAlert"+Symbol()+Period(). GlobalVariableSet("AlertTime"+Symbol()+Period(). GlobalVariableSet("AlertTime"+Symbol()+Period().TIME_DATE).Period()))*60. // } tmp = CurTime() + (Period()-MathMod(Minute().":". GlobalVariableSet("SignalType"+Symbol()+Period().Ask." Period=".} } if (flagval1==1 && CurTime() > GlobalVariableGet("AlertTime"+Symbol()+Period( )) && GlobalVariableGet("SignalType"+Symbol()+Period())!=OP_BUY) { // if (GlobalVariableGet("LastAlert"+Symbol()+Period()) < 0.Period()).Symbol().1).-1). Date="+TimeToStr(CurTime(). Bid="+DoubleToStr(Bid." Period=". // GlobalVariableSet("LastAlert"+Symbol()+Period(). } .TimeMinute(CurTime()).4)+".Bid.4)+". GlobalVariableSet("SignalType"+Symbol()+Period().":"."\n Symbol=".tmp).

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->