TrendLineRange

Download script
Author: ���������� �������
TrendLineRange

This tool is designed to monitor the proximity of the current market price to a specific trend line drawn on your trading chart. Its primary purpose is to provide real-time alerts based on how close the price gets to that line, categorized into three distinct "zones" of sensitivity.

How it Works

The script constantly calculates the distance between the live market price and the value of a designated trend line. It interprets this distance using three user-defined thresholds (Range 1, Range 2, and Range 3).

The logic is divided into three nested proximity zones:

  • Zone 1 (Outer Boundary): If the price enters the widest specified range, the tool triggers an alert.
  • Zone 2 (Middle Boundary): If the price moves even closer, entering the middle specified range, a second unique alert is triggered.
  • Zone 3 (Inner Boundary): If the price reaches the closest specified range, a final alert is issued.

Key Features

  • Smart Filtering: To prevent your workspace from being flooded with constant notifications, the script uses an internal "memory" system. It will only send one alert per zone. Once an alert for a specific zone is triggered, it remains silenced until the price moves significantly away and then returns to that zone again.
  • Dynamic Tracking: The tool automatically identifies the correct trend line based on the index you provide, allowing you to monitor multiple lines independently if needed.
  • Real-Time Feedback: The script displays the current calculated distance directly on your chart screen as a comment, providing a constant visual reference of how far the price is from your target line.

Summary for Traders

Think of this tool as a multi-stage proximity alarm. Instead of just telling you when the price hits a line exactly, it warns you progressively as the price approaches, allowing you to prepare for potential market reactions at different levels of closeness.

Miscellaneous
It issuies visual alerts to the screen
15 Views
0 Downloads
0 Favorites
TrendLineRange
//+------------------------------------------------------------------+
//|                                               TrendLineRange.mq4 |
//|                                               Ñîêðàòèëèí Àëåêñåé |
//|                                        sokratilin@brocompany.com |
//+------------------------------------------------------------------+
#property copyright "Ñîêðàòèëèí Àëåêñåé"
#property link      "sokratilin@brocompany.com"

#property indicator_chart_window
//---- input parameters
extern int       PointsRange1=20;            //1-îå ðàññòîÿíèå äî òðåíäîâîé ëèíèè  
extern int       PointsRange2=10;            //2-îå ðàññòîÿíèå äî òðåíäîâîé ëèíèè
extern int       PointsRange3=5;             //3-åå ðàññòîÿíèå äî òðåíäîâîé ëèíèè
extern string    IndexTrendLine;             //Èíäåêñ òðåíäîâîé ëèíèè â ñïèñêå îáúåêòîâ
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   static int S1,S2,S3;                               //Ñ÷åò÷èêè ñèãíàëîâ
   string TrendLine="Trendline "+IndexTrendLine;      //Äîáàâëåíèå èíäåêñà òåíäîâîé ëèíèè ê "Trendline"
   double Price=Bid;                                  //Òåêóùàÿ öåíà
   double TrendLineValue=NormalizeDouble(ObjectGetValueByShift(TrendLine,0),Digits);       //Òåêóùåå çíà÷åíèå òðåíäîâîé ëèíèè
   
   int Range=MathAbs((NormalizeDouble(Price,Digits)-TrendLineValue)*MathPow(10,Digits));
                                                       //Âû÷èñëåíèå ðàññòîÿíèÿ ìåæäó òåêóùåé öåíîé è òðåíäîâîé ëèíèåé
   
   Comment("Range=",Range);
      
   if (Range<=PointsRange1 && Range>PointsRange2 && S1==0)     //Åñëè òåêóùåå ðàñññòîÿíèå <= ðàññòîÿíèÿ1 è > ðàññòîÿíèÿ2
      {                                                        //ñèãíàë íà ýòîì ïðîìåæóòêå íå ïîäàâàëñÿ, òî ïîäàåì îäèí ñèãíàë.
         Alert("Range=",Range," Price=",Price," TrendLine=",TrendLineValue);
         S1=1; S2=0; S3=0;                                     //Îáíóëåíèå ñ÷åò÷èêîâ
      }   
   else
   if (Range<=PointsRange2 && Range>PointsRange3 && S2==0)     //Åñëè òåêóùåå ðàñññòîÿíèå <= ðàññòîÿíèÿ2 è > ðàññòîÿíèÿ3
      {                                                        //ñèãíàë íà ýòîì ïðîìåæóòêå íå ïîäàâàëñÿ, òî ïîäàåì îäèí ñèãíàë.
         Alert("Range=", Range, " Price=", Price, " TrendLine=",TrendLineValue);
         S1=0; S2=1; S3=0;                                     //Îáíóëåíèå ñ÷åò÷èêîâ
      }   
   else
   if (Range<=PointsRange3 && S3==0)                           //Åñëè òåêóùåå ðàñññòîÿíèå <= ðàññòîÿíèÿ3
      {                                                        //ñèãíàë íà ýòîì ïðîìåæóòêå íå ïîäàâàëñÿ, òî ïîäàåì îäèí ñèãíàë.
         Alert("Range=", Range, " Price=", Price, " TrendLine=",TrendLineValue);
         S1=0; S2=0; S3=1;                                     //Îáíóëåíèå ñ÷åò÷èêîâ
      }   
  
   return(0);
  }
//+------------------------------------------------------------------+

Comments