BreakOutRSI-1

Download script
BreakOutRSI-1

This script is a custom technical analysis tool designed to help traders visualize market structure and momentum by identifying three distinct market states: Breakouts, Trends, and Range-Bound movements. It automates the calculation of key price levels and combines them with momentum indicators to provide a real-time summary on the trading chart.

Core Market Analysis Logic

The tool evaluates the current price action relative to historical data over a 16-period window. It performs three primary calculations to determine market behavior:

1. Dynamic Range Identification

  • Extreme Boundaries: The script identifies the highest point and the lowest point reached within the last 16 candles. These serve as the "Breakout" limits.
  • Average Zones: It calculates the average high and average low prices over that same period. This creates a central "Range Zone" representing the core area where price typically oscillates when there is no strong momentum.

2. Market State Classification Based on where the current price sits relative to these boundaries, the tool automatically classifies the market into one of five states:

  • Breaking-out Upwards / Downwards: Occurs when the price pierces through the absolute highest or lowest points of the recent 16-period window.
  • Trending Up / Down: Occurs when the price is moving towards the extremes but has not yet broken through the absolute high/low (moving outside the "Average Zone" but inside the boundaries).
  • Range Bound: Occurs when the price is hovering within the average high and average low levels, indicating a consolidation phase.

3. Momentum Filtering (RSI Integration) To increase the reliability of the signals, the script incorporates the Relative Strength Index (RSI). It uses this to determine if the current trend has "Favourable" momentum:

  • In an Upward trend, it checks if the RSI is above 50.
  • In a Downward trend, it checks if the RSI is below 50. If the price movement aligns with these momentum requirements, the tool labels the state as "Favourable."

Visual Representation on Chart

The script provides an interactive dashboard directly on your trading screen:

  • Visual Zones: It draws colored rectangles on the chart to represent the Breakout Range (the extreme boundaries) and the Average Range (the core consolidation area).
  • Live Status Text: A text display updates automatically to show the current market state (e.g., "Breaking-out Upwards" in Aqua or "Trending Down" in Red).
  • Data Feed: The script displays real-time numerical values for the RSI strength, as well as the specific price levels of the Breakout High and Breakout Low, allowing for quick reference without needing to manually calculate price targets.

Summary of Purpose

The primary goal of this logic is to remove the guesswork from identifying whether a market is currently "resting" (ranging) or "moving" (trending/breaking out). By combining structural boundaries with momentum filtering, it helps traders stay oriented on the current market direction and identify potential entry points based on confirmed breakouts.

Price Data Components
Series array that contains the highest prices of each bar
Indicators Used
Relative strength index
12 Views
1 Downloads
0 Favorites
BreakOutRSI-1
//+------------------------------------------------------------------+
//|                                                BreakOutRSI-1.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_chart_window

      double RSI;
      int    i, Dig, Trend;
      double AvgHighs, AvgLows;
      string TrendTxt, RSIState;
      color  TrendColor;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init(){}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
      Comment("");
      ObjectDelete("Trend");
      ObjectDelete("BrLong");
      ObjectDelete("BrShort");
      ObjectDelete("RSI");
      ObjectDelete("B-Range");
      ObjectDelete("B-Range2");
      ObjectDelete("A-Range");
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
      if(Close[0]>10)  {Dig=3; }  else
      if(Close[0]<10)  {Dig=5; }

      RSI  = iRSI(NULL,0,14,PRICE_OPEN,0);   

      double Top    = iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,16,1));
      double Bottom = iLow (NULL,0,iLowest (NULL,0,MODE_LOW, 16,1));
   
      AvgHighs = (High[1]+High[2]+High[3]+High[4]+High[5]+High[6]+High[7]+High[8]+High[9]+High[10]+High[11]+High[12]+High[13]+High[14]+High[15]+High[16])/16;
      AvgLows = (Low[1]+Low[2]+Low[3]+Low[4]+Low[5]+Low[6]+Low[7]+Low[8]+Low[9]+Low[10]+Low[11]+Low[12]+Low[13]+Low[14]+Low[15]+Low[16])/16;

         ObjectDelete("B-Range");
         ObjectCreate("B-Range", OBJ_RECTANGLE, 0, 0,0, 0,0);
         ObjectSet   ("B-Range", OBJPROP_STYLE, STYLE_SOLID);
         ObjectSet   ("B-Range", OBJPROP_COLOR, C'128,60,0');
         ObjectSet   ("B-Range", OBJPROP_BACK,  false);
         ObjectSet   ("B-Range", OBJPROP_TIME1 ,Time[17]);
         ObjectSet   ("B-Range", OBJPROP_PRICE1,Top);
         ObjectSet   ("B-Range", OBJPROP_TIME2 ,Time[0]+Time[0]-Time[1]);
         ObjectSet   ("B-Range", OBJPROP_PRICE2,Bottom);

         ObjectDelete("B-Range2");
         ObjectCreate("B-Range2", OBJ_RECTANGLE, 0, 0,0, 0,0);
         ObjectSet   ("B-Range2", OBJPROP_STYLE, STYLE_SOLID);
         ObjectSet   ("B-Range2", OBJPROP_COLOR, C'128,60,0');
         ObjectSet   ("B-Range2", OBJPROP_BACK,  true);
         ObjectSet   ("B-Range2", OBJPROP_TIME1 ,Time[0]+Time[0]-Time[1]);
         ObjectSet   ("B-Range2", OBJPROP_PRICE1,Top);
         ObjectSet   ("B-Range2", OBJPROP_TIME2 ,Time[0]+Time[0]-Time[2]);
         ObjectSet   ("B-Range2", OBJPROP_PRICE2,Bottom);

         ObjectDelete("A-Range");
         ObjectCreate("A-Range", OBJ_RECTANGLE, 0, 0,0, 0,0);
         ObjectSet   ("A-Range", OBJPROP_STYLE, STYLE_SOLID);
         ObjectSet   ("A-Range", OBJPROP_COLOR, C'75,50,50');
         ObjectSet   ("A-Range", OBJPROP_BACK,  true);
         ObjectSet   ("A-Range", OBJPROP_TIME1 ,Time[0]+Time[0]-Time[1]);
         ObjectSet   ("A-Range", OBJPROP_PRICE1,AvgHighs);
         ObjectSet   ("A-Range", OBJPROP_TIME2 ,Time[0]+Time[0]-Time[2]);
         ObjectSet   ("A-Range", OBJPROP_PRICE2,AvgLows);
  

      if (Close[0]>=Top) {Trend=2;}
      if (Close[0]>=AvgHighs && Close[0]<Top) {Trend=1;}
      if (Close[0]<AvgHighs && Close[0]>AvgLows) {Trend=0;}
      if (Close[0]<=AvgLows && Close[0]>Bottom) {Trend=-1;}
      if (Close[0]<=Bottom) {Trend=-2;}
      if (Trend==2){TrendTxt="Breaking-out Upwards";TrendColor=Aqua;}
      if (Trend==1){TrendTxt="Trending Up";TrendColor=Aqua;}
      if (Trend==0){TrendTxt="Range Bound";TrendColor=White;}
      if (Trend==-1){TrendTxt="Trending Down";TrendColor=Red;}
      if (Trend==-2){TrendTxt="Breaking-out Downwards";TrendColor=Red;}
      if (Trend==1 || Trend == 2 && RSI >=50)
         {RSIState="Favourable";}
         else if (Trend==-1 || Trend==-2 && RSI < 50)
                   {RSIState="Favourable";}
                    else if (Trend ==0){RSIState="";}
      else RSIState="Unfavourable";
      
      Comment(
   
       "\n"+"\n"+
       RSIState+" RSI:"+"\n"+
       "Breakout Long:"+"\n"+       
       "Breakout Short:"
          );                

      ObjectCreate("Trend", OBJ_LABEL, 0, 0, 0);
      ObjectSetText("Trend",TrendTxt,12,"Arial Black", TrendColor);
      ObjectSet("Trend", OBJPROP_CORNER, 0);
      ObjectSet("Trend", OBJPROP_XDISTANCE, 4);
      ObjectSet("Trend", OBJPROP_YDISTANCE, 13);

      ObjectCreate("RSI", OBJ_LABEL, 0, 0, 0);
      ObjectSetText("RSI",DoubleToStr(RSI,1),8,"Arial Black", White);
      ObjectSet("RSI", OBJPROP_CORNER, 0);
      ObjectSet("RSI", OBJPROP_XDISTANCE, 90);
      ObjectSet("RSI", OBJPROP_YDISTANCE, 34);

      ObjectCreate("BrLong", OBJ_LABEL, 0, 0, 0);
      ObjectSetText("BrLong",DoubleToStr(Top,Dig),8,"Arial Black", Red);
      ObjectSet("BrLong", OBJPROP_CORNER, 0);
      ObjectSet("BrLong", OBJPROP_XDISTANCE, 90);
      ObjectSet("BrLong", OBJPROP_YDISTANCE, 47);

      ObjectCreate("BrShort", OBJ_LABEL, 0, 0, 0);
      ObjectSetText("BrShort",DoubleToStr(Bottom,Dig),8,"Arial Black", Red);
      ObjectSet("BrShort", OBJPROP_CORNER, 0);
      ObjectSet("BrShort", OBJPROP_XDISTANCE, 90);
      ObjectSet("BrShort", OBJPROP_YDISTANCE, 58);

  return(0);
  }
//+------------------------------------------------------------------+

Comments