ang_PR (Din)-v2_v1

Download script
ang_PR (Din)-v2_v1

This script is a sophisticated technical analysis tool designed to provide traders with a smoothed, mathematically derived view of price trends. Instead of simply following the raw "zigzag" of market prices, it uses advanced polynomial regression to identify the underlying momentum and direction of an asset.

Core Logic and Methodology

1. Dynamic Data Collection The script begins by scanning a specific window of historical price data, governed by user-defined settings (such as the look-back period). It focuses on the "Closing" prices of candles within this timeframe to build a foundation for its calculations.

2. Polynomial Curve Fitting Unlike simple moving averages that just average out past prices, this tool employs a mathematical process called Polynomial Regression. It treats price points as coordinates and attempts to find the best-fitting curve that minimizes the distance between the actual price and the calculated line. This allows it to distinguish between "market noise" (temporary fluctuations) and the true prevailing trend.

3. The Gaussian Elimination Process To achieve high accuracy, the script utilizes a complex linear algebra technique known as Gaussian Elimination. This is a systematic method used to solve systems of equations. By applying this to the price data, the script can calculate the specific coefficients needed to draw a smooth, continuous curve that represents the most statistically probable path of the asset.

4. Forecasting and Projection One of the unique features of this logic is its ability to project forward. Once it has determined the mathematical "shape" of the current trend using historical data, it calculates the trajectory of that curve into the immediate future. This results in a visual projection that helps traders anticipate where the price might be heading based on its current momentum.

Visual Representation

The result is presented on the chart as a smooth line (DeepSkyBlue). Rather than reacting instantly and erratically to every tick, the line provides a stabilized view of the market's "path." It effectively filters out the "jitter" of the market, allowing for a clearer perspective on whether the trend is accelerating, stabilizing, or beginning to reverse.

Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
ang_PR (Din)-v2_v1
/*-----------------------------+
|			       |
| Shared by www.Aptrafx.com    |
|			       |
+------------------------------*/

#property  copyright "ANG3110@latchess.com"
//---------ang_PR (Din)--------------------
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 DeepSkyBlue
#property indicator_color2 DeepSkyBlue
//-----------------------------------
extern double hours = 24;
extern int m = 3;
extern int i0 = 5;
//-----------------------
double fx[],fxn[];
double ai[10,10],b[10],x[10],sx[20];
double sum; 
int p,n,f,sName,fs,i;
double qq,mm,tt;
int ii,jj,kk,ll,nn;
//*******************************************
int init() {
 IndicatorShortName("at_PR (Din)");
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,fx);
   SetIndexBuffer(1,fxn);
   SetIndexShift(1,i0);
if (fs==0) {sName=CurTime(); fs=1;}
   p=hours*60/Period(); 
   nn=m+1; 
return(0);}
//----------------------------------------------------------
int deinit() {ObjectDelete("pr"+sName);}
//**********************************************************************************************
int start(){ 
int mi;
//-------------------------------------------------------------------------------------------
if (f==1) { 
p=iBarShift(Symbol(),Period(),ObjectGet("pr"+sName,OBJPROP_TIME1));} 
sx[1]=p+1;
SetIndexDrawBegin(0,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;} 
for (n=0;n<=i0;n++) {sum=0; for(kk=1;kk<=m;kk++) {sum+=x[kk+1]*MathPow(n-i0,kk);} fxn[n]=x[1]+sum;}
//----------------------------------------------------------------------------------------------------------------------------
ObjectCreate("pr"+sName,22,0,Time[p],fx[p]);
ObjectSet("pr"+sName,14,159);
ObjectSet("pr"+sName,OBJPROP_TIME1,Time[p]);
ObjectSet("pr"+sName,OBJPROP_PRICE1,fx[p]);
//-------------------------------------------
f=1;
//----------------------------------------------------------------------------------------------------------------------------
 return(0);}
//==========================================================================================================================   

Comments