CoeffofLine_v1_v1

Download script
CoeffofLine_v1_v1

This tool is designed to provide a visual representation of market dynamics by calculating and plotting a specific coefficient on a separate window within your trading platform. Instead of showing standard price movements, it focuses on the relationship between different moving averages and price centers over a rolling period.

How the Logic Works

Data Collection and Smoothing The script looks back at a specific number of bars (customizable by the user) to analyze historical price data. It specifically focuses on the "Median Price"—the midpoint between the highest and lowest prices reached during a given timeframe. It then combines this with Smoothed Moving Averages (SMMA) to identify underlying trends.

Weighted Calculations Rather than treating every piece of data equally, the script applies a weighting system. It performs two different types of calculations simultaneously:

  1. One calculation tracks the weighted average of the median prices.
  2. The other tracks the weighted average of the smoothed moving averages.

By applying these weights differently, the script creates two distinct "indicators" (labeled internally as AY and AIndicator). These represent variations of trend data that react at different sensitivities to price fluctuations.

The Final Coefficient The core logic comes down to a comparison between these two calculated indicators. The script determines the ratio between them and applies a logarithmic transformation.

Visual Output The final result is converted into a yellow line shown in a separate window. This line acts as a mathematical "coefficient." When the relationship between the smoothed trend and the raw price center shifts significantly, this line reacts, allowing traders to see abstract market momentum or exhaustion that might not be immediately obvious on a standard price chart.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
CoeffofLine_v1_v1
//+------------------------------------------------------------------+
//| 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