ang_PR (Din)-v1

Download script
ang_PR (Din)-v1

This script functions as a sophisticated mathematical tool designed to project price trends on a trading chart. Rather than relying on simple moving averages or basic trend lines, it utilizes advanced statistical modeling to estimate where the price is headed based on historical data.

Core Logic and Mechanism

The underlying logic follows a structured three-step mathematical process:

1. Data Collection and Preparation The script begins by analyzing a specific window of recent market history (defined by the user's time settings). It gathers the closing prices from this period and prepares them for a complex calculation known as a "Least Squares" approach. This involves creating a matrix of data points that represent both the price movements and the mathematical weight of the time elapsed.

2. Statistical Modeling (The Gauss Process) The heart of the script is a sophisticated elimination process. It organizes the market data into a systematic grid to identify patterns. It then performs a series of "reductions"—mathematically simplifying the relationship between past price points—to isolate the most significant drivers of the current trend. By doing this, the script filters out "noise" and focuses on the underlying curve that best fits the recent price action.

3. Trend Projection Once the model is refined, the script calculates a trajectory for the future. It solves for the unknown variables to determine the most likely path of the price. Instead of just drawing a line back through past data, it uses these calculated coefficients to project a new line forward into "uncharted" territory.

Visual Output

On the trading platform, this logic manifests as a dynamic blue line. The script identifies the current point in time and projects an extension that shows the anticipated direction of the price based on the mathematical curvature established by the recent history.

Essentially, the tool acts as a "mathematical crystal ball," using high-level polynomial regression to tell the trader: "Based on the curve the market has traveled over the last X hours, this is the trajectory it is currently following."

Miscellaneous
Implements a curve of type %1
12 Views
1 Downloads
0 Favorites
ang_PR (Din)-v1
//+------------------------------------------------------------------+
//|                                              ang_PR (Din)-v1.mq4 |
//|                           Copyright © 2006, ANG3110@latchess.com |
//+------------------------------------------------------------------+

#property  copyright "ANG3110@latchess.com"
//---------ang_PR (Din)--------------------
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue
//----
extern double hours = 24;
extern int m = 2;
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;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() 
  {
   IndicatorShortName("at_PR (Din)");
   SetIndexStyle(0, DRAW_LINE, 0, 2);
   SetIndexBuffer(0, fx);
   if(fs == 0) 
     {
       sName = CurTime(); 
       fs = 1;
     }
   p = hours*60 / Period(); 
   nn = m + 1; 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |                                                                 |
//+------------------------------------------------------------------+
int deinit() 
  {
    ObjectDelete("pr" + sName);
  }
//+------------------------------------------------------------------+
//| Custom indicator start function                                  |
//+------------------------------------------------------------------+
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