SHARE
TWEET

Untitled

Alpyic Apr 13th, 2019 114 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //+------------------------------------------------------------------+
  2. //|                                                  RSI Monitor.mq4 |
  3. //|                                          Copyright 2015, Awran5. |
  4. //+------------------------------------------------------------------+
  5.  
  6. #property description "Clean panel that shows RSI values on all timeframes with Oversold and Overbought Notification"
  7. #property strict
  8. #property indicator_chart_window
  9. input string               lb_0              = "";              // ----------- PANEL -----------
  10. extern ENUM_BASE_CORNER    Corner            = 0;               // Panel Side
  11. extern bool                AllowSubwindow    = false;           // Allow sub window
  12. extern color               Pbgc              = C'10,10,10';     // Panel Backgroud color
  13. extern color               Ptc               = clrTomato;       // Panel Title color
  14. extern string              Pfn               = "Calibri";       // Panel Font Name
  15. extern color               Pfc               = clrSilver;       // Panel Text Color
  16. extern color               Pvc               = clrDodgerBlue;   // Panel Values Color
  17. extern color               obic              = clrLime;         // OverBought icon color
  18. extern color               osic              = clrRed;          // OverSold icon color
  19. extern color               nic               = clrGray;         // Normal icon color
  20. input string               lb_1              = "";              // ----------- RSI -----------
  21. extern int                 RSIPeriod         = 14;              // RSI period
  22. extern ENUM_APPLIED_PRICE  RSIApplied        = 0;               // RSI Applied Price
  23. extern double              MinRSI            = 30;              // RSI OverSold Level
  24. extern double              MaxRSI            = 70;              // RSI OverBought Level
  25. input string               lb_2              = "";              // ----------- NOTIFICATION -----------
  26. input bool                 UseAlert          = true;           // Enable Alert
  27. input bool                 UseEmail          = false;           // Enable Email
  28. input bool                 UseNotification   = true;           // Enable Notification
  29. input bool                 UseSound          = true;           // Enable Sound
  30. input string               SoundName         = "alert2.wav";    // Sound Name
  31.  
  32. string iName;
  33. //+------------------------------------------------------------------+
  34. //| Custom indicator initialization function                         |
  35. //+------------------------------------------------------------------+
  36. int OnInit()
  37.   {
  38. //--- indicator buffers mapping
  39.  
  40.    iName="RSI Monitor";
  41.    IndicatorShortName(iName);
  42. //---
  43.    return(INIT_SUCCEEDED);
  44.   }
  45. //+------------------------------------------------------------------+
  46. //| deinitialization function                                        |
  47. //+------------------------------------------------------------------+
  48. void OnDeinit(const int reason)
  49.   {
  50. //---
  51.    for(int i=ObjectsTotal(); i>=0; i--)
  52.      {
  53.       string name=ObjectName(i);
  54.       if(StringFind(name,iName)==0) ObjectDelete(name);
  55.      }
  56. //---
  57.   }
  58. //+------------------------------------------------------------------+
  59. //| Custom indicator iteration function                              |
  60. //+------------------------------------------------------------------+
  61. int OnCalculate(const int rates_total,
  62.                 const int prev_calculated,
  63.                 const datetime &time[],
  64.                 const double &open[],
  65.                 const double &high[],
  66.                 const double &low[],
  67.                 const double &close[],
  68.                 const long &tick_volume[],
  69.                 const long &volume[],
  70.                 const int &spread[])
  71.   {
  72. //--- draw background "webdings" font
  73.    Draw("BG","ggg",70,"Webdings",Pbgc,Corner,1,1);
  74. //--- draw background title
  75.    Draw("Title","--- RSI MONITOR ---",10,Pfn,Ptc,Corner,80,10);
  76. //--- define arrays and vars
  77.    string TimeFrames[9]={"1m","5m","15m","30m","1h","4h","D1","W1","M1"};
  78.    int period[9]={1,5,15,30,60,240,1440,10080,43200};
  79.    double rsi[9]={};
  80. //--- create timeframe labels
  81.    for(int i=0; i<9; i++)
  82.      {
  83.       Draw("Period "+(string)i,TimeFrames[i],8,Pfn,Pfc,Corner,i*30+13,35);
  84.       //--- create values and icons
  85.       rsi[i]=iRSI(NULL,period[i],RSIPeriod,RSIApplied,0);
  86.       Draw("Value "+(string)i,DoubleToStr(rsi[i],1),8,Pfn,Pvc,Corner,i*30+10,55);
  87.       //--- overbought, oversold icons and alert
  88.       if(rsi[i]>MaxRSI)
  89.         {
  90.          Draw("Overbought "+(string)i,CharToStr(108),8,"Wingdings",obic,Corner,i*30+15,75);
  91.          doAlert("RSI has entered in OVERBOUGHT Zone at "+Symbol()+" on "+PeriodToStr(period[i])+" time frame");
  92.         }
  93.       else if(rsi[i]<MinRSI)
  94.         {
  95.          Draw("Oversold "+(string)i,CharToStr(108),8,"Wingdings",osic,Corner,i*30+15,75);
  96.          doAlert("RSI has entered in OVERSOLD Zone at "+Symbol()+" on "+PeriodToStr(period[i])+" time frame");
  97.         }
  98.       else Draw("Normal "+(string)i,CharToStr(108),8,"Wingdings",nic,Corner,i*30+15,75);
  99.      }
  100. //--- return value of prev_calculated for next call
  101.    return(rates_total);
  102.   }
  103. //+------------------------------------------------------------------+
  104. //| alert function
  105. //+------------------------------------------------------------------+
  106. bool doAlert(string message)
  107.   {
  108. //--- See if this bar is new and conditions are met
  109.    static datetime TimeNow;
  110.    if(TimeNow!=Time[0])
  111.      {
  112.       if(UseAlert) Alert(message);
  113.       if(UseEmail) SendMail("RSI Notification!",message);
  114.       if(UseSound) PlaySound(SoundName);
  115.       if(UseNotification) SendNotification(message);
  116.       // Store the time of the current bar, preventing further action during this bar
  117.       TimeNow=Time[0];
  118.       return(true);
  119.      }
  120.    return(false);
  121. //---
  122.   }
  123. //+------------------------------------------------------------------+
  124. //| draw function
  125. //+------------------------------------------------------------------+
  126. void Draw(string name,string label,int size,string font,color clr,int corner,int x,int y)
  127.   {
  128. //---
  129.    name=iName+": "+name;
  130.    int windows=0;
  131.    if(AllowSubwindow && WindowsTotal()>1) windows=1;
  132.    ObjectDelete(name);
  133.    ObjectCreate(name,OBJ_LABEL,windows,0,0);
  134.    ObjectSetText(name,label,size,font,clr);
  135.    ObjectSet(name,OBJPROP_CORNER,corner);
  136.    ObjectSet(name,OBJPROP_XDISTANCE,x);
  137.    ObjectSet(name,OBJPROP_YDISTANCE,y);
  138. //---
  139.   }
  140. //+------------------------------------------------------------------+
  141. //| Period To String - Credit to the author
  142. //+------------------------------------------------------------------+
  143.  
  144. string PeriodToStr(int tf)
  145.   {
  146. //---
  147.    if(tf == NULL) return(PeriodToStr(Period()));
  148.    int p[9]={1,5,15,30,60,240,1440,10080,43200};
  149.    string sp[9]={"M1","M5","M15","M30","H1","H4","D1","W1","MN1"};
  150.    for(int i= 0; i < 9; i++) if(p[i] == tf) return(sp[i]);
  151.    return("--");
  152. //---
  153.   }
  154. //+-------------------------- END -----------------------------------+
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top