ang_PR (Din)-v2

Download script
ang_PR (Din)-v2

Technical Overview and Logic Summary

This script is a sophisticated analytical tool designed to project potential price trends on a trading chart. Rather than relying on simple moving averages or basic momentum indicators, this script utilizes advanced mathematical modeling—specifically Polynomial Regression and Gaussian Elimination—to interpret historical market data and forecast future movement.

Core Functionality

The primary objective of the script is to identify the underlying "curve" of price action over a specific period. By analyzing the relationship between time and price, it attempts to filter out "market noise" to reveal the underlying trend. It then uses this mathematical model to project where that trend is likely heading based on current momentum.

How the Logic Works:

The script processes information through several distinct logical phases:

1. Data Window Definition The tool begins by establishing a look-back window (determined by the user's hours and timeframes). It captures the closing prices within this period to create a data set for analysis.

2. Polynomial Modeling Instead of drawing a straight line, the script treats price movement as a polynomial curve. It calculates coefficients for these curves to see how different "powers" of time correlate with price changes. This allows the tool to recognize complex movements—such as accelerating growth or decelerating declines—more accurately than standard linear tools.

3. Matrix Construction and Gaussian Elimination This is the core "engine" of the script. To find the most accurate curve that fits the historical data, the script builds a mathematical matrix. It then applies a process called Gaussian Elimination. This is a systematic method used in linear algebra to solve complex systems of equations. In this context, it allows the script to calculate the exact coefficients needed to make the projected curve align as closely as possible with every historical price point in the selected window.

4. Trend Projection Once the mathematical model (the curve) is solved, the script performs the final calculation:

  • It projects the curve forward into the future.
  • It generates two primary visual components: a primary trend line and an offset indicator that helps traders visualize the trajectory of the price.

Visual Representation

The result is a dynamic line on your chart that updates as new data arrives. It provides a visual "pathway" for the market, helping users identify whether the current price action is deviating from the established mathematical trend or if it is following a predictable trajectory based on previous behavior.

Miscellaneous
Implements a curve of type %1
16 Views
0 Downloads
0 Favorites
ang_PR (Din)-v2
#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