ang_PR_(Din)-v1
Download scriptThis indicator is designed to provide a visual projection on your trading chart by analyzing historical price behavior and calculating a mathematical trend. Instead of simply following current price movements, the script looks at past data to estimate where the price might head next.
How it Works
The logic behind this tool can be broken down into three main stages:
1. Data Collection and Scaling The tool begins by looking back at a specific number of candles (defined by your settings). It collects the closing prices from this period to establish a baseline for the current market trend. It calculates how much "weight" each previous price should carry, ensuring that more recent data is factored into the calculation appropriately.
2. Mathematical Modeling (The Matrix) This is the core of the script. It uses a sophisticated mathematical method known as Gaussian elimination. To do this, it:
- Builds a complex "matrix" (a grid of interconnected numbers) based on the historical price data.
- Performs a series of algebraic calculations to solve for specific variables.
- Essentially, it is trying to find the "best fit" equation that describes the current movement of the market. It treats the market trend like a curve and tries to find the most accurate formula to represent that curve.
3. Trend Projection Once the script has solved the mathematical equation for the current trend, it projects that line forward into the future.
- It calculates the expected value for the next price point based on the "best fit" curve it just created.
- On your chart, this appears as a visual indicator (a line or point) that shows you the projected path based on the momentum and historical patterns of the preceding candles.
Key Takeaways for the User
- Predictive Nature: The script does not tell you what the price will do with 100% certainty; rather, it provides a mathematical "best guess" based on current momentum.
- Dynamic Adjustment: Because it constantly recalculates its matrix as new candles form, the projection adjusts automatically as the market's behavior changes.
- Visual Guidance: It serves as a tool to help you see the underlying curve of the market, helping traders identify whether the current trend is accelerating, decelerating, or shifting direction.
#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