Author: neo
percent

This tool is designed to provide a visual representation of price consistency within a specific timeframe on your trading chart. Instead of focusing on simple upward or downward movements, it measures how often the current market price sits within the range of previous historical prices.

How the Logic Works

The script operates by looking back at a set number of candles (defined by the "N" parameter, which defaults to 60). For every point on your chart, the tool performs the following calculation:

  1. Historical Comparison: It takes the closing price of the current candle and compares it against the opening prices of the previous 60 candles.
  2. Range Verification: It checks if the current price is "trapped" or contained within the boundaries of those previous candles. Specifically, it counts how many times the current closing price falls between the starting point and the ending point of a past period.
  3. Percentage Calculation: Once it finishes counting these occurrences, it converts that number into a percentage based on the 60-candle window.

Visual Output

The result is displayed in a separate window below your main trading chart as a line graph ranging from 0% to 100%.

  • High Percentage: A high value on the line suggests that the current price is frequently overlapping with historical prices from the recent past, indicating a period of consolidation or a specific price range where the market is "hovering."
  • Low Percentage: A lower value suggests that the current price is moving into new territory that hasn't been mirrored as frequently in the previous 60 candles.

In short, this indicator acts as a "density" meter, showing you what percentage of recent historical price action is being touched or occupied by the current market price.

Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
percent
//+------------------------------------------------------------------+
//|                                                      percent.mq4 |
//|                                                              neo |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "neo"
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_minimum 0
#property indicator_maximum 100

#property indicator_buffers 1
#property indicator_color1 Black

//---- input parameters
extern int N=60;


//---- indicator buffers
double perct[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {

   SetIndexDrawBegin(0,N);

   SetIndexBuffer(0,perct);

   SetIndexStyle(0,DRAW_LINE);

   SetIndexLabel(0,"percent");

   return(0);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
int start()
  {
   int count=1;

   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);

	  
//---- main loop
	 
   for(int i=0; i<Bars-N; i++)
     {
       count = 0;
		 for(int k=1; k<=N; k++)
		   {	 
		     if( Close[i]>=Open[i+k] && Close[i]<=Close[i+k] )   count++; 
		   }
		 perct[i]=1.0*count/N*100;

     }  

//---- done
   return(0);
  }
//+------------------------------------------------------------------+

Comments