CoeffofLine_true_v1

Download script
CoeffofLine_true_v1

This tool functions as a specialized visual indicator designed to analyze and display market trends by comparing different price data points. Instead of looking at raw price movements alone, it evaluates the relationship between various mathematical averages of "High" and "Low" prices over a specific period.

How the Logic Works

1. Data Collection and Weighting The script examines a small window of recent price history (a set number of bars). For every point in this window, it calculates the midpoint between the highest and lowest prices reached during that timeframe. Rather than treating all these points equally, it applies a weighted calculation, giving different importance to older versus newer data points within that small window.

2. Dual-Pathway Comparison The core logic creates two distinct mathematical "paths":

  • Path A: This focuses on the raw midpoint values derived directly from the price history.
  • Path B: This uses a smoothed moving average (specifically a Smoothed Moving Average or SMMA) to represent the same data.

By calculating these two different types of averages simultaneously, the script can identify the "distance" or the variance between the actual market behavior and its smoothed trend.

3. Ratio Analysis The script then compares Path A against Path B. It calculates a ratio to determine how much the current market price is deviating from its smoothed average. This is essentially looking for "stretch"—identifying when the market is moving significantly faster or slower than its established rhythm.

4. Dynamic Scaling and Visualization Finally, the script converts this ratio into a visual line on a separate window:

  • Logarithmic Conversion: It uses a logarithmic calculation to smooth out the results, making it easier for a human trader to read large fluctuations clearly.
  • Automatic Directional Adjustment: The tool is programmed with specific logic to handle different currency pairs. For certain major pairs (like EURUSD or GBPUSD), it scales the output in one direction; for others, it flips the calculation to ensure the visual line remains consistent and intuitive regardless of which asset is being viewed.

Summary for the User

In simple terms, this script filters out the "noise" of the market to show you the underlying momentum. It measures how much the price is pulling away from its smoothed average. When the resulting line shows significant movement, it indicates a divergence between short-term price action and the long-term trend, helping you visualize whether the market is overextended or maintaining steady progress.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
13 Views
1 Downloads
0 Favorites
CoeffofLine_true_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

//+------------------------------------------------------------------+
//| CoeffofLine_true.mq4 
//| Ramdass - Conversion only
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DarkKhaki



extern int CountBars=300;
//---- buffers
double cfl[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- indicator line
   IndicatorBuffers(1);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,cfl);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| CoeffofLine_true                                                              |
//+------------------------------------------------------------------+
int start()
  {
  

  
   if (CountBars>=Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars+5+1);
   int i,shift,cnt,ndot1,ndot=5,counted_bars=IndicatorCounted();
   double TYVar,ZYVar,TIndicatorVar,ZIndicatorVar,M,N,AY,AIndicator;
//----
   if(Bars<=ndot) return(0);

//----
   shift=CountBars-ndot-1;


   while(shift>=0)
     {
     
   TYVar=0;
	ZYVar=0;
	N=0;
	M=0;
	TIndicatorVar=0;
	ZIndicatorVar=0;
	ndot1=ndot;

	for (cnt=ndot; cnt>=1; cnt--) // n=5 -  ïî ïÿòè òî÷êàì
	{
	   ZYVar=ZYVar+(High[shift+cnt-1]+Low[shift+cnt-1])/2*(6-cnt);
		TYVar=TYVar+(High[shift+cnt-1]+Low[shift+cnt-1])/2;
		N=N+cnt*cnt; //ðàâíî 55
		M=M+cnt; //ðàâíî 15
		ZIndicatorVar=ZIndicatorVar+iMA(NULL,0,5,3,MODE_SMMA,PRICE_MEDIAN,shift+cnt-1)*(6-cnt);
		TIndicatorVar=TIndicatorVar+iMA(NULL,0,5,3,MODE_SMMA,PRICE_MEDIAN,shift+cnt-1);
	
	}
	AY=(TYVar+(N-2*ZYVar)*ndot/M)/M;
	AIndicator=(TIndicatorVar+(N-2*ZIndicatorVar)*ndot/M)/M;
	if (Symbol()=="EURUSD" || Symbol()=="GBPUSD" || Symbol()=="USDCAD" || Symbol()=="USDCHF" 
	 || Symbol()=="EURGBP" || Symbol()=="EURCHF" || Symbol()=="AUDUSD"
	 || Symbol()=="GBPCHF")
	{cfl[shift]=(-1000)*MathLog(AY/AIndicator);}
	else {cfl[shift]=(1000)*MathLog(AY/AIndicator);}


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

Comments