Author: Teo_Onica
lineaire

This script functions as a visual trend analysis tool designed to help traders identify the trajectory of price movements and establish potential boundaries for market activity. By analyzing historical data, it creates a dynamic "channel" on the chart that highlights the core direction of the asset.

Core Methodology

The logic operates by performing a sophisticated linear regression over a specific set of historical bars (defined by the user). Unlike simple moving averages that only show where the price has been, this script calculates the "line of best fit"—the mathematical path that most accurately represents the overall trend of the price.

How it Works

The indicator processes the market data through three distinct phases:

1. Trend Calculation (The Center Line) The script looks back at a large amount of historical price information to determine the velocity and direction of the market. It calculates a primary trend line (the "Regression" line). This represents the equilibrium path of the price, smoothing out short-term "noise" and erratic fluctuations to show the underlying momentum.

2. Deviation Analysis Once the central trend is established, the script measures how much the price typically wanders away from that center line. It calculates the standard deviation—a statistical measure of volatility. By understanding how far the price usually moves away from the average path, the script can determine what constitutes a "normal" price swing versus an extreme one.

3. Boundary Mapping (The Channels) Finally, the script projects two outer boundaries based on that calculated deviation:

  • Upper Bound: A line representing the upper limit of typical price behavior.
  • Lower Bound: A line representing the lower limit of typical price behavior.

Visual Representation

On your chart, this results in a visual corridor or "tunnel." The central line indicates the prevailing trend, while the upper and lower lines create a boundary zone.

For a trader, this logic helps visualize the market's "fair value" range. When the price stays within these boundaries, it is following the established trend; when the price pushes toward or breaks out of these outer lines, it may indicate significant overextended movement or a potential shift in market sentiment.

Miscellaneous
Implements a curve of type %1
2 Views
0 Downloads
0 Favorites
lineaire
//+------------------------------------------------------------------+
//|                                                        Bears.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Teo_Onica"
#property link      "phone:0612480123"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 LawnGreen
#property indicator_color2 Blue
#property indicator_color3 Orange

//---- input parameters
extern int per=1000;
extern double BandsDeviations=0.5;
//extern int signal=5;
//extern int main=3;
//---- buffers
double regr[];
double regrh[];
double regrb[];


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
//---- indicator buffers mapping
   SetIndexBuffer(0,regr);
     SetIndexStyle(1,DRAW_LINE);
//---- indicator buffers mapping
   SetIndexBuffer(1,regrh);
 //ObjectCreate("Rezist", OBJ_TREND, 0,0,0,0,0);
   SetIndexStyle(2,DRAW_LINE);
//---- indicator buffers mapping
   SetIndexBuffer(2,regrb);
  
   
   return(0);
  }
  int deinit()
{
//ObjectDelete("Rezist");

//---- 
//----
  return(0);
 }
//+------------------------------------------------------------------+
//| Bears Power                                                      |
//+------------------------------------------------------------------+
int start()
  {
  double x,y,etapc,xy,etapd,xx,etapf,yy,coefa,coefb,naw,nawb,rac,cor,temp,tempp,sum,deviation,deviationtemp;
   int i,a,b,c,k,counted_bars=IndicatorCounted();
//----
   //if(Bars<=BearsPeriod) return(0);
//----
  // int limit=Bars-counted_bars;
  // if(counted_bars>0) limit++;
   //for(i=0; i<limit; i++)
     // TempBuffer[i]=iMA(NULL,0,BearsPeriod,0,MODE_EMA,PRICE_CLOSE,i);
//----
   i=per;
   a=per;
   b=per;
   c=per;
   
   x=0;
   y=0;
   xy=0;
   etapc=0;
   etapd=0;
   xx=0;
   etapf=0;
   yy=0;
  
   while(i>=0)
     {
    x=x+i;
    y=y+Close[i];
    etapc=Close[i]*i;
    xy=xy+etapc;
etapd=i*i;
xx=xx+etapd;
etapf=Close[i]*Close[i];
yy=yy+etapf;
    
     
      i--;
     }
     
     coefb=((per*xy)-(x*y))/((per*xx)-(x*x));
     coefa=(y-(coefb*x))/per;
     //vala=coefa+(coefb*1);
     //valb=coefa+(coefb*per);
     naw=((per*xx)-(x*x))*((per*yy)-(y*y));
     nawb= MathAbs(naw);
     rac=MathSqrt(nawb);
     cor=((per*xy)-(x*y))/rac;
     int haut =iHighest(NULL,0,MODE_HIGH,per,1);
     int bas =iLowest(NULL,0,MODE_LOW,per,1);
      
      while(a>=0)
     {
     
      regr[a]=coefa+(coefb*a);
      a--;
     }
      
    
     //ObjectSet("Rezist", OBJPROP_TIME1 ,Time[per]);
    //ObjectSet("Rezist", OBJPROP_TIME2 ,Time[1]);
    //ObjectSet("Rezist", OBJPROP_TIME3 ,Time[1]);
    //ObjectSet("Rezist", OBJPROP_PRICE1,valb);
    //ObjectSet("Rezist", OBJPROP_PRICE2,vala);
    //ObjectSet("Rezist", OBJPROP_PRICE3,valc);
    //ObjectSet("Rezist", OBJPROP_RAY   , True);
    
   // double priceh = ObjectGetValueByShift("Rezist", haut);
    //double priceb = ObjectGetValueByShift("Rezist", bas);
    
     //Comment("haut ",hh,"  bas ",bb," correlation ",cor," ym ",ym);
     //----
   
   
   i=0;
    
      sum=0.0;
      k=i+per-1;
      temp=regr[i];
      while(k>=i)
        {
         tempp=Close[k]-temp;
         sum+=tempp*tempp;
         k--;
        }
        
      deviation=BandsDeviations*MathSqrt(sum/per);
     
      
     
    
     
     
      i=per;
     
   while(i>=0)
     {
     
      temp=regr[i];
     
      regrh[i]=temp+deviation;
      regrb[i]=temp-deviation;
      i--;
     }
//----
     
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments