CoeffofLine_true2

Download script
CoeffofLine_true2

This indicator is designed to analyze market trends by calculating and comparing two different types of weighted averages based on price action. Its primary goal is to measure the relationship between these averages to identify underlying momentum or shifts in the market.

Core Logic Overview

The script examines a specific window of historical data (defined by the user) to generate a single visual line. It operates by performing a series of mathematical calculations for each point on the chart, comparing a standard weighted movement against a smoothed moving average.

How the Calculations Work

  1. Data Collection: The script looks at a small group of previous price points (specifically the last 5 bars). For each of these points, it identifies the midpoint between the high and low prices.
  2. Weighted Averages: It creates two distinct variables:
    • The Price-Based Value: This takes the midpoints of the recent price bars and applies a decreasing weight to them. This means more recent price action has a different impact on the result than older data within that 5-bar window.
    • The Indicator-Based Value: Instead of using raw price, this calculation uses a smoothed moving average (SMMA) of those same points, applying the same weighted logic used above.
  3. Comparison and Scaling: The script then compares these two values against one another to find a ratio. This ratio represents the "distance" or discrepancy between current price momentum and its smoothed average.
  4. Logarithmic Transformation: To make this data readable on a chart, it applies a logarithmic function to the ratio. This helps smooth out extreme fluctuations and focuses on the relative change between the two values.

Currency-Specific Adjustments

A unique feature of this script is its awareness of specific currency pairs. It includes a built-in list of major currencies (such as EURUSD, GBPUSD, etc.).

  • For these specific pairs, it applies a negative multiplier to the final calculation.
  • For all other pairs, it uses a positive multiplier.

This logic ensures that the line on your chart reflects the correct direction of the sentiment, adjusting the polarity of the indicator based on which market you are currently trading.

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