CoeffofLine_trueEdit

Download script
CoeffofLine_trueEdit

This script is designed as a visual trading tool that analyzes price action to identify momentum and trend direction. It works by comparing two different types of weighted averages to determine if the market's current movement is accelerating or decelerating.

How it Works

The logic operates by calculating two distinct values based on historical price data (specifically the highs and lows of recent candles):

  1. The Primary Value: This represents a customized calculation of the average price over a specific period. It applies a weighted mathematical formula to the price history to establish a baseline for current market activity.
  2. The Comparative Value: This is derived from a Smoothed Moving Average (SMMA) of the median prices. By comparing this "smoothed" data against the primary value, the tool can detect subtle shifts in market velocity.

Signal Generation

Once these two values are calculated, the script performs a mathematical operation to determine the "Coefficient of Line." Here is how that translates into what you see on your screen:

  • Trend Identification: The script calculates the ratio between these two values and applies a logarithmic transformation. This creates a relative intensity score.
  • Visual Feedback:
    • Green Histograms: When the current coefficient is higher than it was in the previous period, the tool indicates upward momentum or strengthening strength in the current trend.
    • Red Histograms: When the coefficient drops compared to the previous period, it signals a loss of momentum or a potential weakening of the trend.
  • Currency Specifics: The script contains built-in logic that automatically adjusts the direction of these calculations for specific major currency pairs (such as EURUSD, GBPUSD, and others), ensuring the visual output remains consistent with standard market behavior for those assets.

Summary for the User

Essentially, this tool acts as a momentum "speedometer." Rather than just telling you the price is going up or down, it shows you how fast that movement is happening relative to recent history. When the histograms are active and changing color, it provides a visual cue of whether the market's current energy is expanding or contracting.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
12 Views
0 Downloads
0 Favorites
CoeffofLine_trueEdit
//+----------------------------------------------------------------+
//|                                          CoeffofLine_true.mq4  |
//|                                     Ramdass - Conversion only  |
//+----------------------------------------------------------------+
//http://codebase.mql4.com/ru/624
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1  Black
#property indicator_color2 Green
#property indicator_color3 Red
//----
extern int ndot = 5;
extern int CountBars = 300;
//---- buffers
double Work[];
double Up[];
double Dw[];
//+----------------------------------------------------------------+
//| Custom indicator initialization function                       |
//+----------------------------------------------------------------+
int init()
  {
//---- indicator line
   SetIndexBuffer(0, Work);
   SetIndexBuffer(1, Up);
   SetIndexBuffer(2, Dw);   
   SetIndexStyle(0, DRAW_NONE); 
   SetIndexStyle(1, DRAW_HISTOGRAM, 0, 2); 
   SetIndexStyle(2, DRAW_HISTOGRAM, 0, 2);
//----
   IndicatorShortName("CoeffofLine_true2(" + ndot + ")");
   SetIndexLabel(1,NULL);
   SetIndexLabel(2,NULL);      
//----
   if (CountBars >= Bars) 
       CountBars = Bars;
   SetIndexDrawBegin(0, Bars - CountBars + ndot + 1);
   SetIndexDrawBegin(1, Bars - CountBars + ndot + 1);
//----
   return(0);
  }
//+----------------------------------------------------------------+
//| CoeffofLine_true                                               |
//+----------------------------------------------------------------+
int start()
  {
   int i, shift, cnt; //counted_bars=IndicatorCounted();
   double TYVar, ZYVar, TIndicatorVar, ZIndicatorVar, M, N, AY, 
          AIndicator, cfl, cfl1;
//----
   if(Bars <= ndot) 
       return(0);
//----
   shift = CountBars - ndot - 1;
//----
   while(shift >= 0)
     {
       cfl1 = cfl;  
       TYVar = 0;
       ZYVar = 0;
       N = 0;
       M = 0;
       TIndicatorVar = 0;
       ZIndicatorVar = 0;
       //----
       for(cnt = ndot; cnt >= 1; cnt--) // n=5 -  ?? ???? ??????
         {
           ZYVar = ZYVar + (High[shift+cnt-1] + Low[shift+cnt-1]) / 
                            2*(ndot - cnt + 1);
           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, ndot, 3, 
                           MODE_SMMA, PRICE_MEDIAN, 
                           shift + cnt - 1)*(ndot - cnt + 1);
           TIndicatorVar = TIndicatorVar + iMA(NULL, 0, ndot, 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() == "EURAUD" || 
          Symbol() == "GBPCHF" || Symbol() == "NZDUSD")
         {
           cfl = (-1000)*MathLog(AY / AIndicator);
         }
       else 
         {
           cfl = (1000)*MathLog(AY / AIndicator);
         }
       //----
       if(cfl > cfl1) 
         {
           Work[shift] = cfl;
           Up[shift] = cfl; 
           Dw[shift] = 0.0;
         }
       else 
         {
           Work[shift] = cfl;
           Dw[shift] = cfl; 
           Up[shift] = 0.0;
         }
       shift--;
     }
   return(0);
  }
//+----------------------------------------------------------------+

Comments