This technical indicator is designed to provide traders with a sophisticated mathematical forecast of price action based on historical data. Rather than relying on simple moving averages or basic momentum oscillators, it utilizes high-level algebraic modeling to project potential price paths on the chart.
Core Methodology: Polynomial Regression
The primary logic behind this script is Polynomial Regression. While a standard linear regression tries to fit a straight line through a set of data points (like a "best fit" line), this script creates a curved path that accounts for the accelerating or decelerating trends in the market.
By utilizing adjustable parameters, the indicator determines the complexity of these curves. This allows it to "learn" from recent historical price movements and extend that mathematical trend into the future, providing a visual guide for where the price might gravitate next based on current momentum.
Dynamic Calculations
The indicator performs several complex operations in real-time:
- Data Summation: It systematically aggregates historical closing prices and applies power functions to them. This creates a foundation of data that defines the "shape" of the recent market movement.
- Matrix Processing: The script organizes these gathered values into a mathematical matrix. It then performs a process similar to Gaussian Elimination—a method used in advanced linear algebra—to solve for the coefficients of the curve.
- Curve Fitting: Once the coefficients are calculated, the indicator reconstructs the polynomial equation to plot a smooth, continuous line that follows the underlying trend of the price action.
Volatility and Boundary Mapping
Beyond simply drawing a trend line, the script provides a framework for understanding market variance:
- Dynamic Channels: It calculates standard deviations based on the predicted curve rather than just the historical average. This creates "upper" and "lower" boundaries that expand or contract depending on how much the price deviates from the mathematical forecast.
- Standard Deviation Alignment: By incorporating a multiplier (standard deviation), it establishes a range of "expected" price behavior, helping traders identify when the market is overextended relative to its calculated trend.
User Experience
For the user, this translates into a visual environment where the current trend is projected forward as a dynamic curve. The inclusion of upper and lower bounds provides a clear corridor of price action, allowing for a more nuanced view of potential support and resistance levels derived from pure mathematical modeling.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
#property copyright "ANG3110@latchess.com"
//---------ang_PR (Din)--------------------
#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 DeepSkyBlue
#property indicator_color2 Lime
#property indicator_color3 Lime
#property indicator_color4 Yellow
#property indicator_color5 Yellow
//-----------------------------------
extern double hours = 120;
extern int m = 2;
extern int i = 0;
extern int kstd = 2;
extern 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("at_PR (Din)");
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,fx);
SetIndexBuffer(1,sqh);
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_CLOSE,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