//+------------------------------------------------------------------+ //| Color RSI.mq4 | //| mladen | //+------------------------------------------------------------------+ //2008fxtsd RSI_ColorRSI_v1.01_Maxim //OBOSlevels_reentry_signals ki #property copyright "mladen" #property link "" #property indicator_separate_window #property indicator_buffers 3 #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_color1 DimGray #property indicator_color2 LimeGreen #property indicator_color3 Red #property indicator_width2 2 #property indicator_width3 2 #property indicator_level1 70 #property indicator_level2 50 #property indicator_level3 30 #property indicator_levelcolor DarkSlateGray #property indicator_levelstyle 2 //#define SignalName "RSIsignal" string SignalName; //---- input parameters // // // // extern int RSIPeriod = 14; extern int PriceType = 5; extern string timeFrame = "Current time frame"; extern int OverBought = 70; extern int OverSold = 30; extern bool showArrows = true; //extern bool OBOS_Level_crossSig = true; //extern bool Level_50_crossSig = true; extern color ArrowUpColor = LimeGreen; extern color ArrowDnColor = Maroon; extern int UpDnArrowSize = 0; extern color RevUpColor = MediumSeaGreen; extern color RevDnColor = Red; extern int RevArrowSize = 1; extern double Signal_Gap= 1.3; extern bool alertsOn = false; extern bool OBOS_Level_crossAlert = false; extern bool Level_50_crossAlert = true; extern bool alertsMessage = true; extern bool alertsSound = false; extern bool alertsEmail = false; extern int repaintSignalStep = 0; extern int repaintSignalPrice = 0; extern int MaxArrowsScreensX = 3; extern string TimeFrames = "M1;5,15,30,H160;H4240;D11440;W110080;MN43200|0-CurrentTF"; //---- buffers // // // // // double RSIBuffer[]; double Upper[]; double Lower[]; double Prices[]; // // // // // int TimeFrame; datetime TimeArray[]; int maxArrows; int SignalGap; string prevSignal; int prevBar; //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int init() { string shortName = "RSI ("; SetIndexBuffer(0,RSIBuffer); SetIndexBuffer(1,Upper); SetIndexBuffer(2,Lower); SetIndexLabel(0,"RSI"); SetIndexLabel(1,NULL); SetIndexLabel(2,NULL); // // // // // shortName = "RSI ("+RSIPeriod+") "; TimeFrame = stringToTimeFrame(timeFrame); if (TimeFrame != Period()) shortName = shortName+"["+TimeFrameToString(TimeFrame)+"] "; shortName = shortName+PriceTypeToString(PriceType)+" | "; if (OverBought < OverSold) OverBought = OverSold; if (OverBought < 100) shortName = shortName+OverBought+","; if (OverSold > 0) shortName = shortName+OverSold +":"; IndicatorShortName(shortName); SignalName=MakeUniqueName("","RSIsignal" ); return(0); } // // // // // int deinit() { DeleteArrows(); return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); int limit; int i,y; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=MathMax(Bars-counted_bars,TimeFrame/Period()); ArrayCopySeries(TimeArray ,MODE_TIME ,NULL,TimeFrame); // // // // // for(i=0,y=0; i=0; i--) { if (RSIBuffer[i] > OverBought) { Upper[i] = RSIBuffer[i]; Upper[i+1] = RSIBuffer[i+1]; } else { Upper[i] = EMPTY_VALUE; if (Upper[i+2] == EMPTY_VALUE) Upper[i+1] = EMPTY_VALUE; } if (RSIBuffer[i] < OverSold) { Lower[i] = RSIBuffer[i]; Lower[i+1] = RSIBuffer[i+1]; } else { Lower[i] = EMPTY_VALUE; if (Lower[i+2] == EMPTY_VALUE) Lower[i+1] = EMPTY_VALUE; } } // // // // // DeleteArrows(); if (showArrows) { SignalGap = MathCeil(iATR(NULL,0,9,0)/Point); for (i=WindowBarsPerChart()*MaxArrowsScreensX; i>=0 ;i--) { if (RSIBuffer[i]>OverBought && RSIBuffer[i+1]OverBought) DrawArrow(i,"ReversDn"); if (RSIBuffer[i]OverSold) DrawArrow(i,"dn"); if (RSIBuffer[i]>OverSold && RSIBuffer[i+1]0)) if (prevBar==i+1) { double currPrice = iMA(NULL,0,1,0,MODE_SMA,repaintSignalPrice,i); double prevPrice = iMA(NULL,0,1,0,MODE_SMA,repaintSignalPrice,i+1); // // // // // if (prevSignal == "dn") if (RSIBuffer[i]= repaintSignalStep) { ObjectSet(StringConcatenate(SignalName,maxArrows),OBJPROP_TIME1,Time[i]); ObjectSet(StringConcatenate(SignalName,maxArrows),OBJPROP_PRICE1,Low[i] -(SignalGap*Point)); } if (prevSignal == "up") if (RSIBuffer[i]>OverBought) if ((currPrice-prevPrice)/Point >= repaintSignalStep) { ObjectSet(StringConcatenate(SignalName,maxArrows),OBJPROP_TIME1,Time[i]); ObjectSet(StringConcatenate(SignalName,maxArrows),OBJPROP_PRICE1,High[i]+(SignalGap*Point)); } } } } // // // // if (alertsOn) { if (OBOS_Level_crossAlert) { if (RSIBuffer[0]>OverBought && RSIBuffer[1]OverBought) doAlert(OverBought+" Level crossed Down"); if (RSIBuffer[0]OverSold) doAlert(OverSold+" Level crossed Down"); if (RSIBuffer[0]>OverSold && RSIBuffer[1]50 && RSIBuffer[1]<50) doAlert("Level 50 crossed Up"); if (RSIBuffer[0]<50 && RSIBuffer[1]>50) doAlert("Level 50 crossed Down"); } } // // // // // return(0); } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // void DrawArrow(int i,string type) { string name; maxArrows++; name = StringConcatenate(SignalName,maxArrows); ObjectCreate(name,OBJ_ARROW,0,Time[i],0); if (Signal_Gap==0)Signal_Gap=1; if (type=="up") { ObjectSet(name,OBJPROP_PRICE1,High[i]+(SignalGap*Signal_Gap*(1+UpDnArrowSize)*Point)); ObjectSet(name,OBJPROP_ARROWCODE,241); ObjectSet(name,OBJPROP_COLOR,ArrowUpColor); ObjectSet(name,OBJPROP_WIDTH,UpDnArrowSize); } if (type=="dn") { ObjectSet(name,OBJPROP_PRICE1,Low[i]-(SignalGap*Signal_Gap*(1+UpDnArrowSize)*Point)); ObjectSet(name,OBJPROP_ARROWCODE,242); ObjectSet(name,OBJPROP_COLOR,LimeGreen); ObjectSet(name,OBJPROP_COLOR,ArrowDnColor); ObjectSet(name,OBJPROP_WIDTH,UpDnArrowSize); } if (type=="ReversUp") { ObjectSet(name,OBJPROP_PRICE1,Low[i]-(SignalGap*Signal_Gap*(1+RevArrowSize)*Point)); ObjectSet(name,OBJPROP_ARROWCODE,241); ObjectSet(name,OBJPROP_COLOR,LimeGreen); ObjectSet(name,OBJPROP_COLOR,RevUpColor); ObjectSet(name,OBJPROP_WIDTH,RevArrowSize); } if (type=="ReversDn") { ObjectSet(name,OBJPROP_PRICE1,High[i]+(SignalGap*Signal_Gap*(1+RevArrowSize)*Point)); ObjectSet(name,OBJPROP_ARROWCODE,242); ObjectSet(name,OBJPROP_COLOR,RevDnColor); ObjectSet(name,OBJPROP_WIDTH,RevArrowSize); } prevSignal = type; prevBar = i; } void DeleteArrows() { while(maxArrows>0) { ObjectDelete(StringConcatenate(SignalName,maxArrows)); maxArrows--; } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ void doAlert(string doesWhat) { static string previousAlert="nothing"; static datetime previousTime; string message; if (previousAlert != doesWhat || previousTime != Time[0]) { previousAlert = doesWhat; previousTime = Time[0]; // // // // // message = StringConcatenate(Symbol(),", ",TimeToStr(TimeLocal(),TIME_SECONDS), "; ColorRSI (TF ",TimeFrameToString(TimeFrame), " at M",Period()," chart): ", doesWhat); if (alertsMessage) Alert(message); if (alertsSound) PlaySound("alert2.wav"); if (alertsEmail) SendMail(StringConcatenate(Symbol()," RSI crossing"),message); } } //+------------------------------------------------------------------+ //| | //+------------------------------------------------------------------+ // // // // // string PriceTypeToString(int pt) { string answer; switch(pt) { case 0: answer = "Close" ; break; case 1: answer = "Open" ; break; case 2: answer = "High" ; break; case 3: answer = "Low" ; break; case 4: answer = "Median" ; break; case 5: answer = "Typical" ; break; case 6: answer = "Wighted" ; break; default: answer = "Invalid price field requested"; Alert(answer); } return(answer); } int stringToTimeFrame(string tfs) { int tf=0; tfs = StringUpperCase(tfs); if (tfs=="M1" || tfs=="1") tf=PERIOD_M1; if (tfs=="M5" || tfs=="5") tf=PERIOD_M5; if (tfs=="M15"|| tfs=="15") tf=PERIOD_M15; if (tfs=="M30"|| tfs=="30") tf=PERIOD_M30; if (tfs=="H1" || tfs=="60") tf=PERIOD_H1; if (tfs=="H4" || tfs=="240") tf=PERIOD_H4; if (tfs=="D1" || tfs=="1440") tf=PERIOD_D1; if (tfs=="W1" || tfs=="10080") tf=PERIOD_W1; if (tfs=="MN" || tfs=="43200") tf=PERIOD_MN1; if (tf= 0) { char = StringGetChar(s, lenght); // // // // // if((char > 96 && char < 123) || (char > 223 && char < 256)) s = StringSetChar(s, lenght, char - 32); else if(char > -33 && char < 0) s = StringSetChar(s, lenght, char + 224); lenght--; } // // // // // return(s); } string MakeUniqueName(string first, string rest) { string result = first+(MathRand()%1001)+rest; while (WindowFind(result)>= 0) result = first+(MathRand()%1001)+rest; return(result); }