CoeffofLine_v1_v2

Download script
CoeffofLine_v1_v2

This script is designed as a specialized technical indicator for the MetaTrader platform. Its primary purpose is to analyze and visualize specific mathematical relationships between price action and moving averages to identify underlying trends or momentum.

Core Logic Overview

The tool operates by examining a rolling window of historical data (determined by the user) to calculate a unique coefficient. Instead of looking at simple price points, it performs a multi-layered calculation that compares two different types of weighted values:

  • Price Action Analysis: The script identifies the "Median Price" (the midpoint between the high and low of each bar) and applies a specific weight to these points over a 5-bar period.
  • Moving Average Comparison: Simultaneously, the script calculates a smoothed moving average (SMMA) over the same period. It applies a secondary weighting logic to this average to create a comparative baseline.

How the Calculation Works

The indicator performs a sophisticated "comparison of averages." It processes these two data sets—the weighted price action and the weighted moving average—to determine their relative proportions.

  1. Weighted Summation: It creates two distinct variables (referred to as AY and AIndicator). These represent the "weighted balance" of the market's current movement versus its smoothed historical average.
  2. Ratio Analysis: The script then takes these two balances and calculates the ratio between them. This tells the user how much the current price behavior is deviating from or aligning with its expected moving average path.
  3. Logarithmic Conversion: Finally, the script applies a logarithmic transformation to this ratio. This converts the raw mathematical relationship into a normalized value that is easier to read on a chart.

Visual Output

The result of these calculations is plotted as a yellow line in a separate window below your main price chart. By observing this line, traders can monitor the "Coefficient of Line," which provides a smoothed representation of momentum and price dynamics, helping to filter out market noise and highlight significant shifts in trend strength.

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

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

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Yellow



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                                                              |
//+------------------------------------------------------------------+
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;
//	if (shift+1<ndot1) ndot1=shift+1;
//	for (cnt=ndot; cnt>=1; cnt--) // n=5 -  ïî ïÿòè òî÷êàì
//	{ 
//		N=N+cnt*cnt;  //ðàâíî 55
//		M=M+cnt;      //ðàâíî 15
//	}
	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+(55-2*ZYVar)*5/15)/15;
	AIndicator=(TIndicatorVar+(55-2*ZIndicatorVar)*5/15)/15;
	}
	cfl[shift]=(-1000)*MathLog(AY/AIndicator);



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

Comments