DynamicRS_v1

Download script
DynamicRS_v1

This script is designed to identify key price levels on a trading chart by automatically calculating and plotting dynamic support and resistance zones. Rather than using static horizontal lines, this tool adapts to the market's movement by reacting to price momentum and historical extremes.

Core Logic Overview

The tool operates by analyzing three primary components of price action: the highest point, the lowest point, and the closing price over a specific short-term window. By averaging these values, the script creates a "weighted price" baseline.

It then compares this weighted baseline against a longer-term moving average. The relationship between these two figures determines when the market structure shifts, triggering the identification of new support and resistance levels.

How it Works

  • Dynamic Resistance Detection: When the short-term weighted price crosses below its long-term moving average, the script identifies a potential shift in trend. It automatically looks back over a significant period to find the highest price point reached during that move, establishing this as a "Dynamic Resistance" level.
  • Dynamic Support Detection: Conversely, when the weighted price crosses above the long-term moving average, the script looks for the lowest price point reached during that preceding movement. This becomes the "Dynamic Support" level.
  • Mean Swing Calculation: To provide an additional layer of clarity, the script calculates a "Mean Swing" line. This is essentially the midpoint between the dynamic resistance and dynamic support levels, acting as a neutral zone or a center of gravity for current price action.

Visual Representation on Chart

The indicator produces three distinct visual elements to help traders navigate the market:

  1. Dynamic Resistance (Red): Represents the ceiling where price has historically faced difficulty breaking through during recent shifts.
  2. Dynamic Support (Green): Represents the floor where price has historically found a base during recent trends.
  3. Mean Swing (Gray Dashed Line): Represents the mathematical equilibrium between the identified support and resistance levels.

By using this logic, the tool helps traders visualize where the "strong" and "weak" zones currently lie based on actual price behavior, allowing for a more reactive approach to identifying potential reversal points or breakout areas.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
7 Views
0 Downloads
0 Favorites
DynamicRS_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

/*

Original Formula

WH:=HHV(HIGH,5);
WL:=LLV(LOW,5);
WBP:=(HHV(HIGH,5)+LLV(LOW,5)+CLOSE)/3;

RBAND:=VALUEWHEN(1,CROSS(MOV(WBP,25,S),WBP),
HHV(WH,25));


SBAND:=VALUEWHEN(1,CROSS(WBP,MOV(WBP,25,S)),
LLV(WL,25));

MSWNG:=(RBAND+SBAND)/2;

*/


#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Green
#property indicator_color3 Gray

//---- input parameters
extern int ShortPeriod=5;
extern int LongPeriod=25;

//---- buffers  WHH=HHV(WH,25);WLL=LLV(WL,25);WBP_MA=MOV(WBP,25,S)
double S[];
double R[];
double MS[];
double WBP[],WBP_MA[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 3 additional buffers are used for counting.
   IndicatorBuffers(5);
//---- name for DataWindow and indicator subwindow label


   SetIndexBuffer(3, WBP);

   SetIndexBuffer(4, WBP_MA);



//----
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   SetIndexBuffer(0, R);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2);SetIndexBuffer(1, S);
   SetIndexStyle(2,DRAW_LINE,STYLE_DASHDOT,2);SetIndexBuffer(2, MS);  
   short_name="Dynamic Support/Resistance";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"Dynamic Resistance");
   SetIndexLabel(1,"Dynamic Support");
   SetIndexLabel(2,"MeanSwing");
   SetIndexDrawBegin(0,LongPeriod);
 SetIndexDrawBegin(1,LongPeriod);
  SetIndexDrawBegin(2,LongPeriod); 
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Dynamic Support/Resistance                                        |
//+------------------------------------------------------------------+
int start()
  {
   int    i,k,counted_bars=IndicatorCounted();
   
   if(Bars<=LongPeriod) return(0);
//---- initial zero

//---- last counted bar will be recounted
   int limit=Bars-counted_bars;
   if(counted_bars>0) limit++; else { i=limit;
            {R[i]=High[i];S[i]=Low[i];}
          }

//---- WH,WL,WBP calculation

   for(i=0; i<limit; i++)
      WBP[i] = (High[Highest(NULL,0,MODE_HIGH,ShortPeriod,i)] + Low[Lowest(NULL,0,MODE_LOW,ShortPeriod,i)] + Close[i])/3;


//---- WBP MA calculation
for(i=0; i<limit; i++)
WBP_MA[i]=iMAOnArray(WBP,Bars,LongPeriod,0,MODE_SMA,i);



//---- Drawing Lines
for(i=limit-1; i>=0; i--)
  if (WBP[i+1]>WBP_MA[i+1] && WBP[i]<WBP_MA[i])
      R[i]=High[Highest(NULL,0,MODE_HIGH,ShortPeriod+LongPeriod,i)];
        else R[i]=R[i+1];
for(i=limit-1; i>=0; i--)
   if (WBP[i+1]<WBP_MA[i+1] && WBP[i]>WBP_MA[i])
      S[i]=Low[Lowest(NULL,0,MODE_LOW,ShortPeriod+LongPeriod,i)];
        else S[i]=S[i+1];
   for(i=0; i<limit; i++)
      MS[i]=(R[i]+S[i])/2;
/**/
   return(0);
  }
//+------------------------------------------------------------------+

Comments