CoeffofLine_v1

Download script
CoeffofLine_v1

This tool is designed to provide a visual representation of market momentum and price behavior by comparing two different types of weighted averages. It operates on the principle of identifying the discrepancy between "raw" price trends and "smoothed" moving average trends to calculate a specific coefficient.

How the Logic Works

1. Data Collection and Weighting The script looks back at a specific number of historical bars (user-defined) to analyze recent price action. It specifically focuses on the midpoint of each candle (the average between the high and low prices). Rather than treating all past candles equally, it applies a weighted mathematical system where more recent data points are given significance relative to older ones.

2. The Dual Calculation Process The core logic performs two distinct types of calculations simultaneously:

  • Price-Based Trend: It calculates a value based directly on the high and low price points of the candles.
  • Indicator-Based Trend: It calculates a corresponding value using a smoothed moving average (SMMA).

By running these two separate processes, the tool can "see" how much the actual market price is deviating from its underlying smoothed trend.

3. Coefficient Generation The script then compares these two values. It calculates the ratio between the Price-Based Trend and the Indicator-Based Trend. This ratio is converted into a logarithmic scale, which helps to normalize the data into a more readable format.

4. Currency-Specific Adjustment Because different currency pairs can have different price volatilities and behaviors, the logic includes a specific filter. If you are trading major pairs like EURUSD or GBPUSD, the script applies a negative multiplier to the final result. For other pairs, it uses a positive multiplier. This ensures that the resulting line on your chart remains consistent and interpretable regardless of which currency pair you are viewing.

Summary for the Trader

In simple terms, this tool measures the "gap" between where the price is currently moving and where the mathematical trend suggests it should be. The resulting yellow line represents this coefficient; by watching how this line moves, traders can attempt to identify the intensity of market trends or potential deviations in price action.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
1 Downloads
0 Favorites
CoeffofLine_v1
//+------------------------------------------------------------------+
//| CoeffofLine.mq4 
//| Ramdass - Conversion only
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Yellow



extern int ndot=5;
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_v1                                                              |
//+------------------------------------------------------------------+
int start()
  {
  

  
   if (CountBars>=Bars) CountBars=Bars;
   SetIndexDrawBegin(0,Bars-CountBars+ndot+1);
   int i,shift,cnt,ndot1,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=ndot1; cnt>=1; cnt--) // n=5 -  ïî ïÿòè òî÷êàì
	{
		ZYVar=ZYVar+(High[shift-cnt+1]+Low[shift-cnt+1])/2*(ndot+1-cnt);
		TYVar=TYVar+(High[shift-cnt+1]+Low[shift-cnt+1])/2;
		ZIndicatorVar=ZIndicatorVar+iMA(NULL,0,5,3,MODE_SMMA,PRICE_MEDIAN,shift-cnt+1)*(ndot+1-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