Author: Maks aka ug
Levels

This script is designed to automatically identify and project key price levels on your trading chart based on the behavior of previous market movements. Instead of relying on manual drawing, it analyzes recent price action to calculate potential areas of support and resistance.

Core Logic Overview

1. Market Analysis (The "Diap" Selection) The script first looks at the most recent completed candle to determine its size. It evaluates whether the move was exceptionally large, very small, or a "normal" standard movement. This is important because market volatility changes how traders react to price; a massive spike creates different psychological levels than a tiny, quiet fluctuation.

2. Dynamic Level Calculation Based on the size of that previous candle, the script selects one of three mathematical models to project future levels:

  • High Volatility (Large Moves): If the previous candle is very large, the script uses specific percentage constants to project levels that are tighter and more sensitive to the high-intensity move.
  • Normal Volatility: If the previous candle falls within a standard range, the script applies a balanced set of percentages to find common equilibrium points.
  • Low Volatility (Small Moves): If the previous candle is very small, the script uses wider percentage constants. This helps identify significant zones when price action is consolidating or moving slowly.

3. Support and Resistance Projection Once the appropriate model is chosen, the script calculates a series of five "Support" levels (potential areas where price might stop falling) and five "Resistance" levels (potential areas where price might stop rising). These are calculated using a combination of:

  • The opening, closing, high, and low prices of the previous period.
  • A mathematical progression that builds outward from the most recent price action.

4. Visual Representation Finally, the script draws these levels directly onto your chart as horizontal lines.

  • Support Levels: Displayed in a specific color (defaulting to Dark Orange) to highlight where buyers might enter or hold their ground.
  • Resistance Levels: Displayed in a different color (defaulting to Blue) to show where sellers may be likely to push the price back down.

By automating this process, the tool ensures that your support and resistance levels are always updated relative to the current market environment, allowing you to see potential "turning points" without having to calculate the geometry of the candles yourself.

Price Data Components
Series array that contains close prices for each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
12 Views
0 Downloads
0 Favorites
Levels
//+------------------------------------------------------------------+
//|                                                       Levels.mq4 |
//|                                                             Maks |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Maks aka ug"
#property link      ""

#property indicator_chart_window

extern string Timeframe="D1";

extern color LineColor_sopr = Blue;
extern int LineWidth_sopr = 2;
extern int LineStyle_sopr = 0;

extern color LineColor_pod = DarkOrange;
extern int LineWidth_pod = 2;
extern int LineStyle_pod = 0;

//Ñëóæàò äëÿ âàðèàíòà ðàñ÷åòà â çàâèñèìîñòè îò ðàçìåðîâ ïðåäûäóùåé ñâå÷è (50 < X < 200, çíà÷èò íîðìàëüíûé)
extern int high_diap = 200;
extern int low_diap = 50;

double close_price,high_price,low_price;
double R[5],S[5];
int PeriodName=0;
int diap = 0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  if (Timeframe=="M1") PeriodName=PERIOD_M1;
   else
      if (Timeframe=="M5") PeriodName=PERIOD_M5;
      else
         if (Timeframe=="M15")PeriodName=PERIOD_M15;
         else
            if (Timeframe=="M30")PeriodName=PERIOD_M30;
            else
               if (Timeframe=="H1") PeriodName=PERIOD_H1;
               else
                  if (Timeframe=="H4") PeriodName=PERIOD_H4;
                  else
                     if (Timeframe=="D1") PeriodName=PERIOD_D1;
                     else
                        if (Timeframe=="W1") PeriodName=PERIOD_W1;
                        else
                           if (Timeframe=="MN") PeriodName=PERIOD_MN1;
                           else
                             {
                              return(0);
                             }
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
for(int i=1; i<=5; i++)
{
   ObjectDelete("Lines" + i);
   ObjectDelete("Linep" + i);
}
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

   close_price=iClose(NULL,PeriodName,1);
   high_price=iHigh(NULL,PeriodName,1);
   low_price=iLow(NULL,PeriodName,1);
   
   if (high_price - low_price > high_diap) diap = 1;
   if (high_price - low_price < low_diap) diap = 2;

if (diap == 1)
{   
//Ñóæåííûé
S[1] = close_price - ((high_price - low_price)*0.146)/2;
R[1] = ((high_price - low_price)*0.146)/2 + close_price;
R[2] = ((high_price - low_price)*0.236)+R[1];
R[3] = R[1]+2*((high_price - low_price)*0.236);
R[4] = R[3] + (R[1] - S[1]);
R[5] = R[4] + ((high_price - low_price)*0.236);
S[2] = S[1] - ((high_price - low_price)*0.236);
S[3] = S[1]- ((high_price - low_price)*0.236)*2;
S[4] = S[3] - (R[1] - S[1]);
S[5] = S[4] - ((high_price - low_price)*0.236);
}

if (diap == 0)
{
//Íîðìàëüíûé
S[1] = close_price - ((high_price - low_price)*0.236)/2; 
R[1] = ((high_price - low_price)*0.236)/2 + close_price;
R[2] = ((high_price - low_price)*0.382)+R[1];
R[3] = R[1]+2*((high_price - low_price)*0.382);
R[4] = R[3] + (R[1] - S[1]);
R[5] = R[4] + ((high_price - low_price)*0.382);
S[2] = S[1] - ((high_price - low_price)*0.382);
S[3] = S[1]-2*((high_price - low_price)*0.382);
S[4] = S[3] - (R[1] - S[1]);
S[5] = S[4] - ((high_price - low_price)*0.382);
}

if (diap == 2)
{
//Ðàñøèðåííûé
S[1] = close_price - ((high_price - low_price)*0.382)/2; 
R[1] = ((high_price - low_price)*0.382)/2 + close_price;
R[2] = ((high_price - low_price)*0.618)+R[1];
R[3] = R[1]+2*((high_price - low_price)*0.618);
R[4] = R[3] + (R[1] - S[1]);
R[5] = R[4] + ((high_price - low_price)*0.618);
S[2] = S[1] - ((high_price - low_price)*0.618);
S[3] = S[1]-2*((high_price - low_price)*0.618);
S[4] = S[3] - (R[1] - S[1]);
S[5] = S[4] - ((high_price - low_price)*0.618);
}

for(int i=1; i<=5; i++)
{
   ObjectCreate("Lines" + i,OBJ_HLINE,0,0,R[i]);
   ObjectSet("Lines" + i,OBJPROP_COLOR,LineColor_sopr);
   ObjectSet("Lines" + i,OBJPROP_WIDTH,LineWidth_sopr);
   ObjectSet("Lines" + i,OBJPROP_STYLE,LineStyle_sopr);
   
   ObjectCreate("Linep" + i,OBJ_HLINE,0,0,S[i]);
   ObjectSet("Linep" + i,OBJPROP_COLOR,LineColor_pod);
   ObjectSet("Linep" + i,OBJPROP_WIDTH,LineWidth_pod);
   ObjectSet("Linep" + i,OBJPROP_STYLE,LineStyle_pod);
}   
   return(0);
  }
//+------------------------------------------------------------------+

Comments