ang_PR_(Din)-v1_v1
Download scriptThis tool is a sophisticated technical indicator designed to provide visual price projections on your trading charts. Rather than simply following historical trends, the script utilizes advanced mathematical modeling to estimate where the price might head next based on recent market behavior.
Core Logic and Methodology
The primary goal of this script is to calculate a trajectory for price movement. It achieves this through three distinct phases:
1. Data Collection and Period Analysis The indicator begins by looking at a specific window of historical data, which you can customize via the "hours" setting. It analyzes the relationship between time and price over this period to build a foundation for its calculations. By observing how the price has reacted over these hours, it identifies the underlying momentum.
2. Polynomial Regression Modeling Instead of using simple moving averages, the script employs a mathematical method known as polynomial regression. It attempts to find a "curve of best fit" for the price data. Think of this as drawing the smoothest possible line through a jagged set of historical price points. This allows the tool to separate market "noise" from the actual underlying trend.
3. Gaussian Elimination (Matrix Mathematics) To ensure the highest level of accuracy in its projection, the script uses a complex algebraic process called Gaussian Elimination. It organizes the collected data into a mathematical matrix—a structured grid of numbers—and solves for variables that define the shape of the trend. This allows the indicator to calculate a precise mathematical formula that represents the current market path.
Visual Output
Once the calculations are complete, the tool identifies the "endpoint" of its current calculation. It then projects a visual line on your chart that extends forward. This projection acts as a mathematical forecast, showing the predicted direction and magnitude of the price based on the trend identified by the regression model.
Summary for Traders
In practical terms, this script serves as a forecasting tool. It takes the "history" of the market and converts it into a "probability" line. By providing a visual curve that extends into the future, it helps traders visualize potential targets and see where the current momentum is mathematically leading the price.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
#property copyright "ANG3110@latchess.com"
//---------ang_PR (Din)--------------------
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DeepSkyBlue
//-----------------------------------
extern double hours = 24;
extern int m = 3;
extern int i = 0;
//-----------------------
double fx[];
double ai[10,10],b[10],x[10],sx[20];
double sum;
int p,n,f,sName,fs;
double qq,mm,tt;
int ii,jj,kk,ll,nn;
//*******************************************
int init() {
IndicatorShortName("at_PR (Din)");
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,fx);
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;}
//----------------------------------------------------------------------------------------------------------------------------
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