ATM_LRCpath
Download scriptThis script is a sophisticated technical analysis tool designed to project potential price movements by calculating the underlying mathematical trends of a financial instrument. Rather than relying on simple moving averages, it uses advanced algebraic methods to "smooth" out market noise and identify the core direction of the price action.
Core Logic Overview
The tool functions by analyzing a specific historical window of price data (defined by the user's hourly settings) to build a mathematical model of how the asset has been behaving. It then uses this model to project a path forward.
1. Data Collection and Matrix Building
The script begins by gathering closing prices over a set period. It organizes these values into a mathematical structure known as a matrix. This allows the tool to look at the relationship between different price points simultaneously, rather than looking at each bar in isolation.
2. The Gaussian Elimination Process
To find the "true" trend within that matrix, the script employs a process called Gauss Elimination. In non-technical terms, this is a systematic method of simplifying a complex system of equations into a solvable form. By performing these calculations, the script isolates the most significant variables affecting the price and discards the random fluctuations (market "noise").
3. Trend Projection
Once the core trend is isolated, the script calculates a primary path—the LRCpath. This represents the most likely trajectory of the price based on the mathematical patterns identified in the previous steps. You can visualize this as the "backbone" of where the price is headed.
4. Volatility and Boundary Mapping
To account for market uncertainty, the tool doesn't just provide a single line; it also calculates boundaries:
- Standard Deviation: The script measures how much the price typically fluctuates away from the main trend.
- Upper and Lower Envelopes: Using this volatility data, the tool generates high and low "channels."
Visual Interpretation for Traders
The final output provides a clear visual guide on your chart:
- The Central Path: The primary projected movement of the asset.
- The Boundaries: A corridor showing the expected range of price action. If the price stays within these bounds, it is following the calculated mathematical trend; if it breaks out significantly, it suggests a potential shift in market dynamics.
By combining complex linear algebra with standard volatility measures, this script aims to provide a clearer picture of where the market may be heading by filtering out the distractions of short-term price spikes.
#property copyright "ANG3110@latchess.com"
//---------ang_PR (Din)--------------------
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 Purple
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Yellow
#property indicator_color5 Yellow
//-----------------------------------
extern double hours = 120;
extern int m = 2;
extern int i = 0;
extern int kstd = 2;
int sName = 1102;
//-----------------------
double fx[],sqh[],sql[],stdh[],stdl[];
double ai[10,10],b[10],x[10],sx[20];
double sum;
int ip,p,n,f;
double qq,mm,tt;
int ii,jj,kk,ll,nn;
double sq,std;
//*******************************************
int init() {
IndicatorShortName("LRCpath");
SetIndexStyle(0,DRAW_LINE,0,2);
SetIndexBuffer(0,fx);
SetIndexStyle(1,DRAW_LINE,0,2);
SetIndexBuffer(1,sqh);
SetIndexStyle(2,DRAW_LINE,0,2);
SetIndexBuffer(2,sql);
SetIndexBuffer(3,stdh);
SetIndexBuffer(4,stdl);
p=hours*60/Period();
nn=m+1;
ObjectCreate("pr"+sName,22,0,Time[p],fx[p]);
ObjectSet("pr"+sName,14,159);
return(0);}
//----------------------------------------------------------
//int deinit() {ObjectDelete("pr"+sName);}
//**********************************************************************************************
int start(){
int mi;
//-------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------
ip=iBarShift(Symbol(),Period(),ObjectGet("pr"+sName,OBJPROP_TIME1)); p=ip;
sx[1]=p+1;
SetIndexDrawBegin(0,Bars-p-1);SetIndexDrawBegin(1,Bars-p-1);SetIndexDrawBegin(2,Bars-p-1);SetIndexDrawBegin(3,Bars-p-1);SetIndexDrawBegin(4,Bars-p-1);
//----------------------sx-------------------------------------------------------------------
for(mi=1;mi<=nn*2-2;mi++) {sum=0; for(n=i;n<=i+p;n++) {sum+=MathPow(n,mi);} sx[mi+1]=sum;}
//----------------------syx-----------
for(mi=1;mi<=nn;mi++) {sum=0.00000; for(n=i;n<=i+p;n++) {if (mi==1) sum+=Close[n]; else sum+=Close[n]*MathPow(n,mi-1);} b[mi]=sum;}
//===============Matrix=======================================================================================================
for(jj=1;jj<=nn;jj++) {for(ii=1; ii<=nn; ii++) {kk=ii+jj-1; ai[ii,jj]=sx[kk];}}
//===============Gauss========================================================================================================
for(kk=1; kk<=nn-1; kk++) {
ll=0; mm=0; for(ii=kk; ii<=nn; ii++) {if (MathAbs(ai[ii,kk])>mm) {mm=MathAbs(ai[ii,kk]); ll=ii;}} if (ll==0) return(0);
if (ll!=kk) {for(jj=1; jj<=nn; jj++) {tt=ai[kk,jj]; ai[kk,jj]=ai[ll,jj]; ai[ll,jj]=tt;} tt=b[kk]; b[kk]=b[ll]; b[ll]=tt;}
for(ii=kk+1;ii<=nn;ii++) {qq=ai[ii,kk]/ai[kk,kk]; for(jj=1;jj<=nn;jj++) {if (jj==kk) ai[ii,jj]=0; else ai[ii,jj]=ai[ii,jj]-qq*ai[kk,jj];} b[ii]=b[ii]-qq*b[kk];}
}
x[nn]=b[nn]/ai[nn,nn]; for(ii=nn-1;ii>=1;ii--) {tt=0; for(jj=1;jj<=nn-ii;jj++) {tt=tt+ai[ii,ii+jj]*x[ii+jj]; x[ii]=(1/ai[ii,ii])*(b[ii]-tt);}}
//===========================================================================================================================
for (n=i;n<=i+p;n++) {sum=0; for(kk=1;kk<=m;kk++) {sum+=x[kk+1]*MathPow(n,kk);} fx[n]=x[1]+sum;}
//-----------------------------------Std-----------------------------------------------------------------------------------
sq=0.0; for (n=i;n<=i+p;n++) {sq+=MathPow(Close[n]-fx[n],2);} sq=MathSqrt(sq/(p+1))*kstd;
std=iStdDev(NULL,0,p,MODE_SMA,0,PRICE_MEDIAN,i)*kstd;
for (n=i;n<=i+p;n++) {sqh[n]=fx[n]+sq; sql[n]=fx[n]-sq; stdh[n]=fx[n]+std; stdl[n]=fx[n]-std;}
//-------------------------------------------------------------------------------
ObjectMove("pr"+sName,0,Time[p],fx[p]);
//----------------------------------------------------------------------------------------------------------------------------
return(0);}
//==========================================================================================================================
Comments