level_sensor_116

Author: Copyright � 2005, Sfen
level_sensor_116

This script is designed to act as a visual "sensor" for your trading chart. Its primary purpose is to identify and highlight price levels that have experienced significant activity based on historical data. By scanning past movements, it identifies specific price zones where the market has "touched" or reacted most frequently, and projects these onto your screen as horizontal markers.

How the Logic Works

1. Scanning the History The script begins by looking back at a specific number of previous candles (defined by the maximum history setting). It examines every single candle in this period to determine the highest peak and the lowest valley reached. This establishes the total price range that the script will analyze.

2. Defining the Grid Once the total price range is established, the script divides that space into a series of equal "steps" or levels. Think of this as creating an invisible vertical grid across the entire price range from the bottom to the top.

3. Activity Detection (The "Sensor") The core logic then performs a deep dive into each historical candle. For every candle, the script checks if it covered any of the grid levels created in the previous step. If a candle's movement spanned across one of these levels, the script notes that activity down as a "hit."

The more often a specific price level is touched or crossed by different candles throughout the history, the higher its significance becomes within the script's logic.

4. Visual Representation After calculating which levels are the most active, the script draws these results onto your chart. It creates horizontal trend lines at each of these identified levels. These markers serve as a visual map of "high-traffic" areas in the market.

By looking at where these lines appear, you can quickly see which price zones have historically been magnets for price action, helping you identify potential areas of support or resistance where the market has shown a preference for activity in the past.

Summary of Features

  • Automatic Cleanup: The script is designed to clear old markings automatically when it starts or stops, ensuring your chart stays clean and only shows current data.
  • Customizable Range: You can adjust how much history the script looks at and how granular the grid levels should be.
  • Visual Clarity: All detected levels are plotted clearly in red, allowing for an immediate visual assessment of market "hotspots."
11 Views
0 Downloads
0 Favorites
level_sensor_116
//+------------------------------------------------------------------+
//|                                                 Level Sensor.mq4 |
//|                                          Copyright © 2005, Sfen. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, Sfen"
#property indicator_chart_window
// input parameters
extern int MAX_HISTORY = 500;
extern int STEP = 1;
//----
string OBJECT_PREFIX = "LEVELS";
int ObjectId = 0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double CSH(int shift)
  {
   return (MathMax(Open[shift], Close[shift]));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double CSL(int shift)
  {
   return (MathMin(Open[shift],Close[shift]));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string IntToStr(int X)
  {
    return (DoubleToStr(X, 0));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
string ObGetUniqueName(string Prefix)
  {
   ObjectId++;
   return (Prefix+" "+IntToStr(ObjectId));
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ObDeleteObjectsByPrefix(string Prefix)
  {
   int L = StringLen(Prefix);
   int i = 0; 
   while(i < ObjectsTotal())
     {
       string ObjName = ObjectName(i);
       if(StringSubstr(ObjName, 0, L) != Prefix) 
         { 
           i++; 
           continue;
         }
       ObjectDelete(ObjName);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   ObDeleteObjectsByPrefix(OBJECT_PREFIX);
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   string S;
   ObDeleteObjectsByPrefix(OBJECT_PREFIX);
   double HH = 0;
   double LL = 1000000;
   int History = MathMin(Bars,MAX_HISTORY);
   int i, j, k;
   for(i = 1; i < History; i++)
     {
       HH = MathMax(HH, CSH(i));
       LL = MathMin(LL, CSL(i));
     }
   int NumberOfPoints = (HH - LL) / (1.0*Point*STEP) + 1;
   int Count[];
   ArrayResize(Count, NumberOfPoints);
   for(i = 0; i < NumberOfPoints; i++) 
       Count[i] = 0;
   for(i = 1; i < History; i++)
     {
       double C = CSL(i);
       while(C < CSH(i))
         {
           int Index = (C-LL) / (1.0*Point*STEP);
           Count[Index]++;    
           C += 1.0*Point*STEP;
         }
     }
   for(i = 0; i < NumberOfPoints; i++)
     {
       double StartX = Time[5];
       double StartY = LL + 1.0*Point*STEP*i;
       double EndX   = Time[5+Count[i]];
       double EndY   = StartY;
       string ObjName = ObGetUniqueName(OBJECT_PREFIX);
       ObjectDelete(ObjName);
       ObjectCreate(ObjName, OBJ_TREND, 0, StartX, StartY, EndX, EndY);
       ObjectSet(ObjName, OBJPROP_RAY, 0);
       ObjectSet(ObjName, OBJPROP_COLOR, Red);
     }
   return(0);
  }
//+------------------------------------------------------------------+

Comments