//+------------------------------------------------------------------+ //| Wobbles SignalsIndicator.mq4 | //| Copyright © 2009.04.10, SwingMan | //| | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009.04.10, SwingMan" #property link "" // Source Code: /*+------------------------------------------------------------------+ RSI-Div-Arrows.mq4 / Copyright © 2009, Lakshmi Inc. RSI EMA1.mq4 / Copyright © 2009, Lakshmi Inc. Waddah_Attar_Def_RSI.mq4 / Copyright © 2007, Eng. Waddah Attar //+-----------------------------------------------------------------*/ #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 Red //RSI-Div-Arrows #property indicator_color2 Green #property indicator_color3 DeepSkyBlue //osWAD_RSI #property indicator_color4 Magenta #property indicator_width1 1 #property indicator_width2 1 #property indicator_width3 1 #property indicator_width4 1 //---- extern parameters --------------------------------------------- //-------------------------------------------------------------------- //-- RSI-Div-Arrows ================================================== //---- buffers double B1[], B2[], B3[], B4[], B5[], B6[]; //---- constants //-- RSI-Div-Arrows int Rsi_Period1=5; int Rsi_Period2=21; int RsiEMA_Period1=5; int RsiEMA_Period2=5; //---- variables double emaFactor1, emaFactor2; double oldRSI1, oldRSI2; //-- osWAD_RSI ======================================================= int RSI_WadPeriod1=14; int RSI_WadPeriod2=28; int RSI_WadSmoothPeriod=14; double up_buffer1[]; double dn_buffer1[]; double ind_buffer1[]; double ind_buffer2[]; double MABuffer1[]; //---- variables datetime oldTime; int TradeDirection; double entryPrice, exitPrice, diffPrice, SumDiffPrice; datetime entryTime, exitTime, thisTime; double Spread; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //RSI-Div-Arrows ================================================== //---- initialisations emaFactor1 = 2.0 / (RsiEMA_Period1 + 1); emaFactor2 = 2.0 / (RsiEMA_Period2 + 1); Spread = MarketInfo(Symbol(),MODE_SPREAD) * Point; TradeDirection = 0; ObjectsDeleteAll(); SumDiffPrice = 0; //---- indicator buffers mapping SetIndexBuffer(0,B5); SetIndexStyle(0, DRAW_ARROW); SetIndexArrow(0,242); //-dn SetIndexBuffer(1,B6); SetIndexStyle(1, DRAW_ARROW); SetIndexArrow(1,241); //-up ArraySetAsSeries(B1,true); ArraySetAsSeries(B2,true); ArraySetAsSeries(B3,true); ArraySetAsSeries(B4,true); //-- osWAD_RSI ==================================================== SetIndexBuffer(2,up_buffer1); SetIndexStyle(2, DRAW_ARROW); SetIndexArrow(2,233); //-up SetIndexBuffer(3,dn_buffer1); SetIndexStyle(3, DRAW_ARROW); SetIndexArrow(3,234); //-dn ArraySetAsSeries(ind_buffer1,true); ArraySetAsSeries(ind_buffer2,true); ArraySetAsSeries(MABuffer1,true); return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { ObjectsDeleteAll(); return(0); } //#################################################################### //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int i, limit; int counted_bars=IndicatorCounted(); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; //================================================================= //-- RSI-Div-Arrows ----------------------------------------------- ArrayResize(B1,Bars); ArrayResize(B2,Bars); ArrayResize(B3,Bars); ArrayResize(B4,Bars); for (i=limit;i>=0;i--) { B1[i] = RSI_EMA1(i, Rsi_Period1, emaFactor1, oldRSI1); //-- call FUNCTION B2[i] = RSI_EMA1(i, Rsi_Period2, emaFactor2, oldRSI2); //-- call FUNCTION B3[i] = B1[i] - B2[i]; B4[i] = B3[i] - B3[i+1]; } for(i=0;i<=limit;i++) { if(B1[i]>B2[i] && B1[i+1]B2[i+1]) { B6[i]=0; B5[i]=(High[i] + (0.001*High[i])); //-dn } else { B5[i]=0; B6[i]=0; } } } //================================================================= //-- osWAD_RSI ==================================================== ArrayResize(ind_buffer1,Bars); ArrayResize(ind_buffer2,Bars); ArrayResize(MABuffer1,Bars); double rsi1, rsi2; for(i = limit; i >= 0; i--) { rsi1 = iRSI(NULL, 0, RSI_WadPeriod1, PRICE_CLOSE, i); rsi2 = iRSI(NULL, 0, RSI_WadPeriod2, PRICE_CLOSE, i); MABuffer1[i] = (rsi1-rsi2); } for(i = 0; i <= limit; i++) { ind_buffer1[i] = iMAOnArray(MABuffer1,0,RSI_WadSmoothPeriod,0,MODE_SMA,i); } /* for(i = limit; i >= 0; i--) { MABuffer1[i] = osWAD_RsiBuffer(i, RSI_WadPeriod1, RSI_WadPeriod2); } for(i = 0; i <= limit; i++) { ind_buffer1[i] = osWAD_IndBuffer(i, RSI_WadSmoothPeriod); }*/ //+------------------------------------------------------------------+ for(i=0;i<=limit;i++) ind_buffer2[i]=MABuffer1[i]-ind_buffer1[i]; for(i=0;i<=limit;i++) { if(ind_buffer2[i]>0 && ind_buffer2[i+1]<=0) { dn_buffer1[i]=0; up_buffer1[i]=Low[i]; } else { if(ind_buffer2[i]<0 && ind_buffer2[i+1]>=0) { up_buffer1[i]=0; dn_buffer1[i]=High[i]; } else { up_buffer1[i]=0; dn_buffer1[i]=0; } } } //================================================================= //-- Draw Lines =================================================== int iWidth = 2; color dColor; string sName, sText; for(i = limit; i >= 0; i--) { thisTime = iTime(Symbol(),Period(),i); //---- new bars if (thisTime != oldTime) { //---- LONG ------------------------------------------------ //---- check entry if (TradeDirection == 0) { //---- long entry if ( (B6[i+2]>0 && up_buffer1[i+1] > 0) || (B6[i+1]>0 && up_buffer1[i+2] > 0) || (B6[i+1]>0 && up_buffer1[i+1] > 0) ) { TradeDirection = 1; entryTime = thisTime; entryPrice = iOpen(Symbol(), Period(), i); } else //---- short entry if ( (B5[i+2]>0 && dn_buffer1[i+1] > 0) || (B5[i+1]>0 && dn_buffer1[i+2] > 0) || (B5[i+1]>0 && dn_buffer1[i+1] > 0) ) { TradeDirection = -1; entryTime = thisTime; entryPrice = iOpen(Symbol(), Period(), i); } } else //---- check exit Long trade ------------------------------- if (TradeDirection == 1) { if (B5[i+1]>0 || dn_buffer1[i+1] > 0) { TradeDirection = 0; exitTime = thisTime; exitPrice = iOpen(Symbol(), Period(), i); diffPrice = exitPrice - entryPrice;// - Spread; SumDiffPrice = SumDiffPrice + diffPrice / Point; if (diffPrice >= 0) dColor = DarkOrange; else dColor = Red; sName = "Line_"+TimeToStr(entryTime); Draw_TrendLine(sName, 0, entryTime, entryPrice, exitTime, exitPrice, STYLE_SOLID, dColor, iWidth); sName = "Text_"+TimeToStr(exitTime); sText = "["+ DoubleToStr(diffPrice/Point,0) +"]"; Draw_Text(sName, 0, sText, exitTime,exitPrice, 9, dColor); } } else //---- check exit Short trade ------------------------------- if (TradeDirection == -1) { if (B6[i+1]>0 || up_buffer1[i+1] > 0) { TradeDirection = 0; exitTime = thisTime; exitPrice = iOpen(Symbol(), Period(), i); diffPrice = entryPrice - exitPrice;// - Spread; SumDiffPrice = SumDiffPrice + diffPrice / Point; if (diffPrice >= 0) dColor = DarkOrange; else dColor = Red; sName = "Line_"+TimeToStr(entryTime); Draw_TrendLine(sName, 0, entryTime, entryPrice, exitTime, exitPrice, STYLE_SOLID, dColor, iWidth); sName = "Text_"+TimeToStr(exitTime); sText = "["+ DoubleToStr(diffPrice/Point,0) +"]"; Draw_Text(sName, 0, sText, exitTime,exitPrice, 9, dColor); } } Comment("Sum= ",SumDiffPrice); //Comment("LastDiff= ",diffPrice/Point); oldTime = thisTime; } } //---- return(0); } //+------------------------------------------------------------------+ //+------------------------------------------------------------------+ // Draw Text //+------------------------------------------------------------------+ void Draw_Text(string sName, int iWindow, string sText, datetime time1, double price1, int fontSize, color iColor) { ObjectCreate(sName, OBJ_TEXT, iWindow, time1, price1); ObjectSetText(sName, sText,fontSize,"Arial Bold",iColor); } //+------------------------------------------------------------------+ // Draw Trend Line //+------------------------------------------------------------------+ void Draw_TrendLine(string sName, int iWindow, datetime time1, double price1, datetime time2, double price2, int iStyle, color iColor, int iWidth) { ObjectCreate(sName, OBJ_TREND, iWindow, time1, price1, time2, price2); ObjectSet(sName, OBJPROP_COLOR, iColor); ObjectSet(sName, OBJPROP_STYLE, iStyle); ObjectSet(sName, OBJPROP_WIDTH, iWidth); ObjectSet(sName, OBJPROP_RAY, false); } //+------------------------------------------------------------------+ //+ RSI EMA1 //+------------------------------------------------------------------+ double RSI_EMA1(int pos, int RSI_Period, double emaFactor, double& oldRSI) { double curRSI; if(pos==Bars-2) curRSI = iRSI(Symbol(),Period(),RSI_Period,PRICE_CLOSE,pos+1); else curRSI = iRSI(Symbol(),Period(),RSI_Period,PRICE_CLOSE,pos)*emaFactor + oldRSI*(1-emaFactor); oldRSI = curRSI; return(curRSI); } /* //+------------------------------------------------------------------+ //+ osWAD Buffers //+------------------------------------------------------------------+ double osWAD_RsiBuffer(int pos, int RSI_Period1, int RSI_Period2) { double rsi1, rsi2; rsi1 = iRSI(Symbol(), Period(), RSI_Period1, PRICE_CLOSE, pos); rsi2 = iRSI(Symbol(), Period(), RSI_Period2, PRICE_CLOSE, pos); //MABuffer1[pos] = (rsi1-rsi2); return(rsi1-rsi2); } double osWAD_IndBuffer(int pos, int RSI_SmoothPeriod) { ind_buffer1[pos] = iMAOnArray(MABuffer1,0,RSI_SmoothPeriod,0,MODE_SMA,pos); }*/