Author: TOPpoint
RES-SUP_v1

This script is designed to identify and display key horizontal price levels on a trading chart, specifically focusing on Support and Resistance zones. It helps traders visualize potential areas where the market might encounter difficulty moving higher or lower by analyzing historical daily data.

Core Logic and Functionality

1. Timeframe Compatibility The script is designed for short-term analysis and will not execute if applied to a timeframe larger than 4 hours. If you attempt to use it on a Daily or Weekly chart, the system will display a notification message rather than generating levels.

2. Data Sourcing Even though you may be viewing lower timeframes (like 15-minute or 1-hour charts), the script "looks back" at the Daily (D1) price history. It collects the Open, High, Low, and Close prices of previous days to determine where major price action occurred.

3. Support and Resistance Calculation The logic identifies specific levels based on the price movement of the previous trading day:

  • Daily Average: The script calculates a central point for the previous day's price action (the average of its High, Low, and Close).
  • Dynamic Offsets: From that center point, it calculates four distinct lines:
    • Support Levels: Two lines are projected below the center point. One is placed at a 50% offset, and the other is placed at a 61.8% offset (a common ratio used in technical analysis).
    • Resistance Levels: Two lines are projected above the center point using the same 50% and 61.8% offsets.

4. Automatic Updates The script is programmed to detect when a new day begins on the chart. Every time a new daily candle opens, it recalculates these levels based on the data from the newly completed day. This ensures that the support and resistance lines remain relevant to the most recent market history.

Visual Output

The indicator draws four dotted lines on your chart:

  • Support 0 & 1: These act as "floors" where buyers might enter the market or sellers might stop selling.
  • Resistance 0 & 1: These act as "ceilings" where sellers might enter the market or buyers might stop buying.

By focusing on these mathematical offsets from previous daily price ranges, the script provides a structured way to see where the market is likely to react based on recent history.

Indicators Used
Indicator of the average true range
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
RES-SUP_v1
//+------------------------------------------------------------------+
//|                                                     !RES-SUP.mq4 |
//|                                                          TOPpoint|
//|                                                toppoint@yandex.ru|
//+------------------------------------------------------------------+
#property copyright "TOPpoint"
#property link      "mailto:TOPpoint@yandex.ru"
//----
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 Red        // Öâåò ëèíèé ãðàôèêà
#property indicator_color2 Red
#property indicator_color3 Red
#property indicator_color4 Red
//----
#define   LevelMaxDeep  2000          //----- Ãëóáèíà ïðîñìîòðà óðîâíåé
// Èíäèêàòîð ðàññ÷èòûâàåò ïðèîðèòåòíûå óðîâíè ïîääåðæêè/ñîïðîòèâëåíèÿ 
// ïî çíà÷åíèÿì äíåâíîãî ATR
//extern int ATRPeriod = 10;          // Ïåðèîä ãðàôèêà
//extern int Aprox=1;                 // 0-ïîäàëüøå; 1 - ïîáëèæå
datetime PrevTime;                    // Lock äëÿ ïðåäóïðåæäåíèÿ ïîâòîðíîé îòðèñîâêè
string ShortName="RES-SUP";           // Êîðîòêîå íàçâàíèå èíäèêàòîðà â îêíå
double OHLC_D1[][6];                  // Ìàññèâ êóäà êîïèðóþòñÿ äíåâíûå ñâå÷êè
//---- buffers
double Sup0[],Sup1[],Res0[],Res1[];
//+------------------------------------------------------------------+
//| Èíèöèàëèçàöèÿ ìàññèâîâ                                           |
//+------------------------------------------------------------------+
int InitChart()
  {
//---- indicator line
   SetIndexStyle(0,DRAW_LINE,STYLE_DOT);
   SetIndexStyle(1,DRAW_LINE,STYLE_DOT);
   SetIndexStyle(2,DRAW_LINE,STYLE_DOT);
   SetIndexStyle(3,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(0,Sup0);
   SetIndexBuffer(1,Sup1);
   SetIndexBuffer(2,Res0);
   SetIndexBuffer(3,Res1);
//---- name for DataWindow and indicator subwindow label
   //  IndicatorShortName(ShortName+" ("+ATRPeriod+")");
   IndicatorShortName(ShortName);
   SetIndexLabel(0,"Ïîääåðæêà0");
   SetIndexLabel(1,"Ïîääåðæêà1");
   SetIndexLabel(2,"Ñîïðîòèâëåíèå0");
   SetIndexLabel(3,"Ñîïðîòèâëåíèå1");
//----
   SetIndexEmptyValue(0,0);
   SetIndexEmptyValue(1,0);
   SetIndexEmptyValue(2,0);
   SetIndexEmptyValue(3,0);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Ôóíêöèÿ èíèöèàëèçàöèè - óäàëÿåì ïðåäûäóùèå ëèíèè                 |
//+------------------------------------------------------------------+
int init()
  {
   InitChart();
   return(0);
  }
//+------------------------------------------------------------------+
//| Ôóíêöèÿ äåèíèöèàëèçàöèè - óäàëÿåì ïðåäûäóùèå ëèíèè               |
//+------------------------------------------------------------------+
int deinit()
  {
   InitChart();
   return(0);
  }
//+------------------------------------------------------------------+
//| Îñíîâàÿ ôóíêöèÿ ðàñ÷åòà óðîâíåé                                  |
//+------------------------------------------------------------------+
int start()
  {
   int  counted_bars=IndicatorCounted();
   int  lastday=0, i, j, daybar=0, chartbar=0;
   double LowYesterday, HighYesterday, LowToday, HighToday, fullatr1, fullatr2,fullatr4,fullatr5,fullatr3,L2,H2,L3,H3,L4,H4,L5,H5;
   double LowY,HighY,Avr,AvrY,UpLine1,UpLine2,DnLine1,DnLine2;
   //if (counted_bars<1) return(0);
   // Åñëè âðåìÿ áàðà íå èçìåíèëîñü, âûõîäèì
   if (PrevTime==Time[0]) return(-1);
   if(Period() > PERIOD_H4)
     {
      Comment("ATR Levels - îøèáêà: ïåðèîä ãðàôèêà áîëåå Í4 !");
      return(-1); // then exit
     }
   // 0 - time, 1 - open, 2 - low, 3 - high, 4 - close, 5 - volume.
   ArrayCopyRates(OHLC_D1, Symbol(), PERIOD_D1);
   lastday=TimeDay(Time[0]);
     for(i=0; i<Bars; i++) 
     {
        if (lastday!=TimeDay(Time[i])) 
        {
         // Âû÷èñëÿåì çíà÷åíèå ATR ïðåäûäóùåãî áàðà
 /*   fullatr1 = iATR(Symbol(), PERIOD_D1, ATRPeriod, daybar+1);
    fullatr2 = iATR(Symbol(), PERIOD_D1, ATRPeriod, daybar+2);
    fullatr3 = iATR(Symbol(), PERIOD_D1, ATRPeriod, daybar+3);
    fullatr4 = iATR(Symbol(), PERIOD_D1, ATRPeriod, daybar+4);
    fullatr5 = iATR(Symbol(), PERIOD_D1, ATRPeriod, daybar+5);
     // Îïðåäåëÿåì óðîâíè         
    LowYesterday  = OHLC_D1[daybar+1][3] - fullatr1;//Äëÿ ðàññ÷åòà Ïÿòèäíåâíîé   
    HighYesterday = OHLC_D1[daybar+1][2] + fullatr1;//Äëÿ ðàññ÷åòà Ïÿòèäíåâíîé 
    LowY = OHLC_D1[daybar+1][1] - fullatr1/2;//Äëÿ ïîñòðîåíèÿ êàíàëîâ   
    HighY = OHLC_D1[daybar+1][1] + fullatr1/2;//Äëÿ ïîñòðîåíèÿ êàíàëîâ
    L2=OHLC_D1[daybar+2][3] - fullatr2;
    H2=OHLC_D1[daybar+2][2] + fullatr2;
    L3=OHLC_D1[daybar+3][3] - fullatr3;
    H3=OHLC_D1[daybar+3][2] + fullatr3;
    L4=OHLC_D1[daybar+4][3] - fullatr4;
    H4=OHLC_D1[daybar+4][2] + fullatr4;
    L5=OHLC_D1[daybar+5][3] - fullatr5;
    H5=OHLC_D1[daybar+5][2] + fullatr5;
    LowToday  = OHLC_D1[daybar][1] - (fullatr1+fullatr2)/4;   
    HighToday = OHLC_D1[daybar][1] + (fullatr1+fullatr2)/4;
    Avr=(LowToday+HighToday)/2;
    AvrY=(LowY+HighY)/2;*/
         // Ñìåíèëñÿ äåíü, ðèñóåì ëèíèþ
         UpLine1=HighToday;
         UpLine2=HighYesterday;
         DnLine1=LowToday;
         DnLine2=LowYesterday;
         //=============================
           for(j=chartbar; j<i; j++) 
           {
            //Ôèêñèðîâàííîå ðàâíîâåñèå (äíåâíîå)
            //  Bline0[j]=(OHLC_D1[daybar+1][2]+OHLC_D1[daybar+1][3]+OHLC_D1[daybar+1][4])/3;
            //Áàëàíñîâûå ñòóïåíüêè (äíåâíîå)
            //  Bline1[j]=((OHLC_D1[daybar+1][2]+OHLC_D1[daybar+1][3]+OHLC_D1[daybar+1][4])/3+(OHLC_D1[daybar+2][2]+OHLC_D1[daybar+2][3]+OHLC_D1[daybar+2][4])/3+(OHLC_D1[daybar+3][2]+OHLC_D1[daybar+3][3]+OHLC_D1[daybar+3][4])/3+(OHLC_D1[daybar+4][2]+OHLC_D1[daybar+4][3]+OHLC_D1[daybar+4][4])/3+(OHLC_D1[daybar+5][2]+OHLC_D1[daybar+5][3]+OHLC_D1[daybar+5][4])/3)/5;    
            //Äèíàìè÷åñêîå ðàâíîâåñèå (ïÿòèäíåâíîå)
            //   Bline2[j]=(OHLC_D1[daybar][2]+OHLC_D1[daybar][3]+OHLC_D1[daybar][4])/3;
            Sup0[j]=(OHLC_D1[daybar+1][2]+OHLC_D1[daybar+1][3]+OHLC_D1[daybar+1][4])/3-(OHLC_D1[daybar+1][3]-OHLC_D1[daybar+1][2])*0.5;
            Sup1[j]=(OHLC_D1[daybar+1][2]+OHLC_D1[daybar+1][3]+OHLC_D1[daybar+1][4])/3-(OHLC_D1[daybar+1][3]-OHLC_D1[daybar+1][2])*0.618;
            Res0[j]=(OHLC_D1[daybar+1][2]+OHLC_D1[daybar+1][3]+OHLC_D1[daybar+1][4])/3+(OHLC_D1[daybar+1][3]-OHLC_D1[daybar+1][2])*0.5;
            Res1[j]=(OHLC_D1[daybar+1][2]+OHLC_D1[daybar+1][3]+OHLC_D1[daybar+1][4])/3+(OHLC_D1[daybar+1][3]-OHLC_D1[daybar+1][2])*0.618;
            // Bline1[j]=(LowYesterday+HighYesterday+L2+L3+H3+H2+L4+H4+L5+H5)/10;
            // Bline2[j]=(OHLC_D1[daybar][1]+(OHLC_D1[daybar+1][2]+OHLC_D1[daybar+1][3]+OHLC_D1[daybar+1][4])/3+(OHLC_D1[daybar+2][2]+OHLC_D1[daybar+2][3]+OHLC_D1[daybar+2][4])/3)/3;
            // Bline3[j]=(OHLC_D1[daybar][1]+OHLC_D1[daybar+1][1]+OHLC_D1[daybar+2][1]+OHLC_D1[daybar+3][1]+OHLC_D1[daybar+4][1])/5;
            //  Bline1[j]=((OHLC_D1[daybar+1][2]+OHLC_D1[daybar+1][3]+OHLC_D1[daybar+1][4])/3+(OHLC_D1[daybar+2][2]+OHLC_D1[daybar+2][3]+OHLC_D1[daybar+2][4])/3+(OHLC_D1[daybar+3][2]+OHLC_D1[daybar+3][3]+OHLC_D1[daybar+3][4])/3+(OHLC_D1[daybar+4][2]+OHLC_D1[daybar+4][3]+OHLC_D1[daybar+4][4])/3+(OHLC_D1[daybar+5][2]+OHLC_D1[daybar+5][3]+OHLC_D1[daybar+5][4])/3)/5;    
           }
         lastday=TimeDay(Time[i]);
         daybar++;
         chartbar=i;
        }
     }
   // Çàïîìèíàåì âðåìÿ ïîñëåäíåãî áàðà (÷òîáû íå ñ÷èòàòü äèâåðû ïîâòîðíî)
   PrevTime=Time[0];
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments