MTF_WaddahAttar_RSI_Levels

Download script
Author: Copyright � 2007, www.metaforex.net
MTF_WaddahAttar_RSI_Levels

This tool is designed to provide traders with a visual representation of specific price levels based on the Relative Strength Index (RSI). While standard RSI indicators usually appear in a separate window at the bottom of the screen, this script translates those momentum levels directly onto your main price chart.

Core Functionality

The script works by calculating multiple "price targets" derived from the RSI. It looks at a specific timeframe (which you can customize) and determines where certain RSI milestones—such as 20, 30, 40, 50, 60, 70, 80, and a custom extra level—would actually sit in terms of market price.

How the Logic Works

To provide these levels on your chart, the script performs the following logical steps:

  • Multi-Timeframe Analysis: It monitors the RSI data from a higher timeframe (e.g., 4-hour charts) even if you are currently viewing a smaller timeframe (like 15-minute charts). This helps you see the "bigger picture" trends while trading smaller movements.
  • Mathematical Projection: Instead of just showing you a number (like "RSI is 70"), the script calculates the mathematical relationship between recent price changes and RSI fluctuations. It then projects these specific RSI values onto the current price candles.
  • Dynamic Level Mapping: The script identifies various key levels (20, 30, 40, 50, 60, 70, 80, and a user-defined extra level). For each of these, it draws a corresponding line on your chart.
  • Visual Feedback: Each level is assigned a distinct color and can be displayed with text labels or price tags. This allows you to see at a glance how close the current market price is to major momentum milestones.

Key Features for the User

  • Customizable Timeframes: You can choose which timeframe's RSI data dictates the levels shown on your screen.
  • Custom Periods: The calculation period for the RSI can be adjusted to suit different trading styles.
  • Visual Clarity: By placing these levels directly on the price chart, the script removes the need for the trader to constantly glance back and forth between a separate RSI window and the main price action.
  • Automated Labeling: The script automatically handles the creation and updating of text labels and price markers, ensuring that as the market moves, the levels adjust accordingly in real-time.
Price Data Components
Series array that contains close prices for each bar
Indicators Used
Relative strength index
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
MTF_WaddahAttar_RSI_Levels
//+------------------------------------------------------------------+
//| MTF_WaddahAttar_RSI_Levels                        Idea by Yamedo |
//| MTF mod.FoewxTSD.com 2007    Copyright © 2007, www.metaforex.net |
//|                                   Waddah Attar www.metaforex.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, www.metaforex.net"
#property link      "www.metaforex.net"
//---- 
#property indicator_chart_window
#property indicator_buffers 8
#property indicator_color1 Blue
#property indicator_color2 OrangeRed
#property indicator_color3 SeaGreen
#property indicator_color4 FireBrick
#property indicator_color5 Green
#property indicator_color6 Maroon
#property indicator_color7 DarkGreen
#property indicator_color8 Magenta
#property indicator_width1 1
#property indicator_width2 1
#property indicator_width3 1
#property indicator_width4 2
#property indicator_width5 2
#property indicator_width6 3
#property indicator_width7 3
#property indicator_width8 1
//---- 
extern int TimeFrame = 240;
extern int RSIDayPeriod = 14;
extern int ExtraLevel = 10;
extern bool ShowRSILevelLables = true;
extern bool ShowLevelPrice = false;
//---- buffers
double P1Buffer[];
double P2Buffer[];
double P3Buffer[];
double P4Buffer[];
double P5Buffer[];
double P6Buffer[];
double P7Buffer[];
double P8Buffer[];
//---- 
double L90, L80, L70, L60, L50, L40, L30, L20;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexBuffer(0, P1Buffer);
   SetIndexBuffer(1, P2Buffer);
   SetIndexBuffer(2, P3Buffer);
   SetIndexBuffer(3, P4Buffer);
   SetIndexBuffer(4, P5Buffer);
   SetIndexBuffer(5, P6Buffer);
   SetIndexBuffer(6, P7Buffer);
   SetIndexBuffer(7, P8Buffer);
//---- 
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexStyle(3, DRAW_LINE);
   SetIndexStyle(4, DRAW_LINE);
   SetIndexStyle(5, DRAW_LINE);
   SetIndexStyle(6, DRAW_LINE);
   SetIndexStyle(7, DRAW_LINE);
//---- 
   SetIndexLabel(0,"RSI("+RSIDayPeriod+") Lvl50; TF["+TimeFrame+"]");
   SetIndexLabel(1,"RSI("+RSIDayPeriod+") Lvl40; TF["+TimeFrame+"]");
   SetIndexLabel(2,"RSI("+RSIDayPeriod+") Lvl60; TF["+TimeFrame+"]");
   SetIndexLabel(3,"RSI("+RSIDayPeriod+") Lvl30; TF["+TimeFrame+"]");
   SetIndexLabel(4,"RSI("+RSIDayPeriod+") Lvl70; TF["+TimeFrame+"]");
   SetIndexLabel(5,"RSI("+RSIDayPeriod+") Lvl20; TF["+TimeFrame+"]");
   SetIndexLabel(6,"RSI("+RSIDayPeriod+") Lvl80; TF["+TimeFrame+"]");
   SetIndexLabel(7,"RSI("+RSIDayPeriod+") Lvl"+ExtraLevel+"; TF["+TimeFrame+"]");


//  Comment("RSI ( " + RSIDayPeriod + " ) Level By eng.Waddah Attar www.metaforex.net");
Comment("RSI (" + RSIDayPeriod + ") TF["+TimeFrame+"]");   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("rsi20" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("txtrsi20" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("rsi30" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("txtrsi30" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("rsi40" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("txtrsi40" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("rsi50" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("txtrsi50" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("rsi60" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("txtrsi60" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("rsi70" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("txtrsi70" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("rsi80" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("txtrsi80" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("rsi90" + DoubleToStr(RSIDayPeriod, 0));
   ObjectDelete("txtrsi90" + DoubleToStr(RSIDayPeriod, 0));
//---- 
   Comment("");
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int i, dayi, counted_bars = IndicatorCounted();
   double rsi1, rsi2, c1, c2, drsi, dc;
//---- check for possible errors
   if(counted_bars < 0) 
       return(-1);
//---- last counted bar will be recounted
   if(counted_bars > 0) 
       counted_bars--;  
   int limit = Bars - counted_bars;
//---- 
   for(i = limit - 1; i >= 0; i--)
     {
       dayi = iBarShift(Symbol(), TimeFrame, Time[i],true);
       if(dayi != -1)
         {
           rsi1 = iRSI(Symbol(), TimeFrame, RSIDayPeriod, PRICE_CLOSE, dayi + 1);
           rsi2 = iRSI(Symbol(), TimeFrame, RSIDayPeriod, PRICE_CLOSE, dayi + 2);
           //----
           c1 = iClose(Symbol(), TimeFrame, dayi + 1);
           c2 = iClose(Symbol(), TimeFrame, dayi + 2);
           //----
           drsi = rsi1 - rsi2;
           //----
           if(drsi == 0)
             {
               rsi2 = iRSI(Symbol(), TimeFrame, RSIDayPeriod, PRICE_CLOSE, dayi + 3);
             }
           //----
           drsi = rsi1 - rsi2;
           //----
           if(drsi == 0)
             {
               drsi = rsi1;
             }
           //----
           dc = c1 - c2;
           //----
           if(dc == 0)
             {
               c2 = iClose(Symbol(), TimeFrame, dayi + 3);
             }
           //----
           dc = c1 - c2;
           //----
           if(dc == 0)
             {
               dc = c1;
             }
           //----
           L90 = (((ExtraLevel - rsi1)*dc) / drsi) + c1;
           P8Buffer[i] = L90;
           if(ShowLevelPrice == true)
           SetPrice("rsi90" + DoubleToStr(RSIDayPeriod, 0), Time[i], 
                    L90, Magenta);
            if(ShowRSILevelLables == true)
            SetText("txtrsi90" + DoubleToStr(RSIDayPeriod, 0), "rsi" + 
                 DoubleToStr(ExtraLevel, 0), Time[i], L90, Magenta);
           //----
           L50 = (((50 - rsi1)*dc) / drsi) + c1;
           P1Buffer[i] = L50;
           if(ShowLevelPrice == true)
           SetPrice("rsi50" + DoubleToStr(RSIDayPeriod, 0), Time[i], 
                    L50, Blue);
           if(ShowRSILevelLables == true)
           SetText("txtrsi50" + DoubleToStr(RSIDayPeriod, 0), "rsi50", 
                   Time[i], L50, Blue);
           //---          
           L40=(((40 - rsi1)*dc) / drsi) + c1;
           P2Buffer[i] = L40;
            if(ShowLevelPrice == true)
           SetPrice("rsi40" + DoubleToStr(RSIDayPeriod, 0), Time[i], 
                    L40, Red);
           if(ShowRSILevelLables == true)
           SetText("txtrsi40" + DoubleToStr(RSIDayPeriod, 0), "rsi40", 
                   Time[i], L40, Red);
           //----
           L60 = (((60 - rsi1)*dc) / drsi) + c1;
           P3Buffer[i] = L60;
           if(ShowLevelPrice == true)
           SetPrice("rsi60" + DoubleToStr(RSIDayPeriod, 0), Time[i], 
                    L60, Green);
           if(ShowRSILevelLables == true)
           SetText("txtrsi60" + DoubleToStr(RSIDayPeriod, 0), "rsi60", 
                    Time[i], L60, Green);
           //----
           L30 = (((30 - rsi1)*dc) / drsi) + c1;
           P4Buffer[i] = L30;
           if(ShowLevelPrice == true)
           SetPrice("rsi30" + DoubleToStr(RSIDayPeriod, 0), Time[i], 
                    L30, Red);
           if(ShowRSILevelLables == true)
           SetText("txtrsi30" + DoubleToStr(RSIDayPeriod, 0), "rsi30", 
                   Time[i], L30, Red);
           //----
           L70 = (((70 - rsi1)*dc) / drsi) + c1;
           P5Buffer[i] = L70;
           if(ShowLevelPrice == true)
           SetPrice("rsi70" + DoubleToStr(RSIDayPeriod, 0), Time[i], 
                    L70, Green);
           if(ShowRSILevelLables == true)
           SetText("txtrsi70" + DoubleToStr(RSIDayPeriod, 0), "rsi70", 
                   Time[i], L70, Green);
           //----
           L20 = (((20 - rsi1)*dc) / drsi) + c1;
           P6Buffer[i] = L20;
           if(ShowLevelPrice == true)
           SetPrice("rsi20" + DoubleToStr(RSIDayPeriod, 0), Time[i], 
                    L20, Red);
           if(ShowRSILevelLables == true)
           SetText("txtrsi20" + DoubleToStr(RSIDayPeriod, 0), "rsi20", 
                   Time[i], L20, Red);
           //----
           L80 = (((80 - rsi1)*dc) / drsi) + c1;
           P7Buffer[i] = L80;
           if(ShowLevelPrice == true)
           SetPrice("rsi80" + DoubleToStr(RSIDayPeriod, 0), Time[i], 
                    L80, Green);
           if(ShowRSILevelLables == true)
           SetText("txtrsi80" + DoubleToStr(RSIDayPeriod, 0), "rsi80", 
                   Time[i], L80, Green);
        }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 
void SetPrice(string name, datetime Tm, double Prc, color clr)
  {
   if(ObjectFind(name) == -1)
     {
       ObjectCreate(name, OBJ_ARROW, 0, Tm, Prc);
       ObjectSet(name, OBJPROP_COLOR, clr);
       ObjectSet(name, OBJPROP_WIDTH, 1);
       ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
     }
   else
     {
       ObjectSet(name, OBJPROP_TIME1, Tm);
       ObjectSet(name, OBJPROP_PRICE1, Prc);
       ObjectSet(name, OBJPROP_COLOR, clr);
       ObjectSet(name, OBJPROP_WIDTH, 1);
       ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE);
     } 
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+ 
void SetText(string name,string txt,datetime Tm,double Prc,color clr)
  {
   if(ObjectFind(name) == -1)
     {
       ObjectCreate(name, OBJ_TEXT, 0, Tm, Prc);
       ObjectSetText(name, txt, 8, "Lucida Console", clr);
       ObjectSet(name, OBJPROP_CORNER, 2);
     }
   else
     {
       ObjectSet(name, OBJPROP_TIME1, Tm);
       ObjectSet(name, OBJPROP_PRICE1, Prc);
       ObjectSetText(name, txt, 8, "Lucida Console", clr);
       ObjectSet(name, OBJPROP_CORNER, 2);
     } 
  }
//+------------------------------------------------------------------+

Comments