CoeffofLine_v2
Download scriptThis script is designed to function as a specialized technical indicator for trading platforms, specifically created to analyze price action and identify underlying momentum or deviations in currency pairs. Instead of simply plotting the raw price of an asset, this tool calculates a specific mathematical coefficient to help traders visualize market behavior in a separate window.
Core Logic and Methodology
The script operates by processing historical price data over a user-defined number of bars (defaulting to 300). It focuses on two primary components: the actual price action (Highs and Lows) and a smoothed moving average.
1. Data Synthesis For every point in time, the script looks at a small window of previous candles (defined by a "dot" count). It calculates the midpoint of these candles—the average between the highest and lowest prices—to establish a baseline for movement.
2. Weighted Comparisons The logic performs a complex balancing act between two different types of averages:
- It creates a weighted sum of the standard price midpoints.
- It simultaneously calculates a weighted sum based on a smoothed moving average (SMMA) of those same prices.
By comparing these two values, the script essentially measures the "weight" or "momentum" of the current price movement relative to its recent historical average. It looks for discrepancies between where the price is going and where it has traditionally moved over the last few bars.
3. Coefficient Calculation The heart of the script lies in its final calculation. It takes the ratio between these two different weighted averages and applies a logarithmic transformation. This converts complex market movements into a singular, readable line.
4. Dynamic Adjustment To ensure accuracy across different types of currency pairs, the script includes an automatic switch. If you are trading major pairs like EURUSD or GBPUSD, it applies a specific mathematical orientation (negative multiplier); for other pairs, it flips the logic (positive multiplier). This ensures that regardless of which currency you are watching, the indicator remains consistent and readable.
Visual Output
The result is a smooth line plotted in a separate window below your main chart. Rather than showing you "how much" a price moved, this line tells you about the intensity or quality of that move. It serves as a filter to help traders distinguish between standard market noise and significant shifts in momentum.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| 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