//+------------------------------------------------------------------+ //| RSI Signals.mq4 | //| Copyright © 2010, Иван Третьяков | //| tretyak-off@inbox.ru | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, Иван Третьяков" #property link "tretyak-off@inbox.ru" #property indicator_chart_window #property indicator_buffers 4 //---- для RSI #property indicator_color1 Red #property indicator_color2 Blue //---- input parameters extern int RSIPeriod=14; extern double _Up=70.0; //OverBoughtLevel - уровень перекупленности extern double _Mid=50.0; extern double _Down=30.0;//OverSoldLevel - уровень перепроданности extern bool ShowMidSignals=false; extern bool SoundON=true; //---- значки extern int DownArrow=234; extern int UpArrow=233; //---- buffers double UpBuffer[]; double DownBuffer[]; //---- переключатели int flagval1=0; int flagval2=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0,DRAW_ARROW); SetIndexArrow(0,DownArrow);//Вниз SetIndexBuffer(0,UpBuffer); SetIndexEmptyValue(0,0.0); SetIndexStyle(1,DRAW_ARROW); SetIndexArrow(1,UpArrow);//Вверх SetIndexBuffer(1,DownBuffer); SetIndexEmptyValue(1,0.0); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit,i,counter; double Range,AvgRange; double RSIPrev,RSIAnow; int counted_bars=IndicatorCounted(); if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; if(counted_bars==0) limit-=1+9; 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; RSIPrev=iRSI(Symbol(),0,RSIPeriod,PRICE_CLOSE,i+1); RSIAnow=iRSI(Symbol(),0,RSIPeriod,PRICE_CLOSE,i); UpBuffer[i]=EMPTY_VALUE; DownBuffer[i]=EMPTY_VALUE; if((RSIPrev<_Down) && (RSIAnow>_Down)) { 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()); } DownBuffer[i]=Low[i]-Range*0.5; UpBuffer[i]=EMPTY_VALUE; flagval1=0; } if((ShowMidSignals) && ((RSIPrev<_Mid) && (RSIAnow>_Mid))) { 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()); } DownBuffer[i]=Low[i]-Range*0.5; UpBuffer[i]=EMPTY_VALUE; flagval1=0; } if((RSIPrev>_Up) && (RSIAnow<_Up)) { if(i==1 && flagval2==0) { flagval2=1; flagval1=0; if(SoundON) Alert("SELL signal at Ask=",Ask,"\n Bid=",Bid,"\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period()); } UpBuffer[i]=High[i]+Range*0.5; DownBuffer[i]=EMPTY_VALUE; flagval2=0; } if((ShowMidSignals) && ((RSIPrev>_Mid) && (RSIAnow<_Mid))) { if(i==1 && flagval2==0) { flagval2=1; flagval2=0; if(SoundON) Alert("SELL signal at Ask=",Ask,"\n Bid=",Bid,"\n Time=",TimeToStr(CurTime(),TIME_DATE)," ",TimeHour(CurTime()),":",TimeMinute(CurTime()),"\n Symbol=",Symbol()," Period=",Period()); } UpBuffer[i]=High[i]+Range*0.5; DownBuffer[i]=EMPTY_VALUE; flagval2=0; } } return(0); } //+------------------------------------------------------------------+