Lagranges_Interpolation_PolynomialM_test01
Download scriptThis tool is designed to provide a more fluid and continuous visual representation of market price movements by using a mathematical technique known as Lagrange Interpolation. In simpler terms, it helps "connect the dots" between specific historical price points to create a smoother curve rather than relying on jagged, disconnected lines.
How the Logic Works
1. Data Selection (The Anchors) The script looks at a specific window of historical data that you define as the "beginning" and "end." It takes the closing prices from these specific points and treats them as fixed anchors. Instead of just looking at the most recent price, it uses this defined range to understand the "shape" of the recent market trend.
2. Curve Calculation (The Bridge) Rather than drawing a straight line between Point A and Point B, the script applies a polynomial calculation. It analyzes the relationship between all prices within your chosen window simultaneously. By doing this, it calculates a curved path that passes through every one of those historical points.
3. Forecasting and Smoothing The logic is designed to extend slightly beyond your chosen start and end points (based on a "forecast" setting). This allows the indicator to project the momentum of the current trend into the immediate future. It essentially predicts where the price should go next based on the mathematical arc established by the recent history.
4. Visual Output On your trading chart, this manifests as a continuous line in a separate window.
- The Red and Blue Markers: The script automatically places vertical lines on your chart to show you exactly where your "anchor" data starts and ends.
- The Result: You see a smooth, orange curve that represents the mathematical trajectory of the price. This helps traders visualize the underlying momentum and flow of the market more clearly than standard price bars alone.
Summary for the User
Think of this tool as a way to see the "arc" of the market. While standard charts show you where the price was, this script uses historical data to draw a smooth path of where the price is trending, helping you identify the underlying direction of the market movement more intuitively.
//+------------------------------------------------------------------+
//| Interpolation.mq4 |
//| Copyright © 2008, Gryb Alexander |
//| ICQ: 478-923-832 E-mail: alexandergrib@rambler.ru |
//+------------------------------------------------------------------+
//Lagranges_Interpolation_PolynomialM
//Fduch (2008.11.18 10:24) http://codebase.mql4.com/4861 http://codebase.mql4.com/ru/4860
#property copyright "Copyright © 2008, Gryb Alexander"
#property link "ICQ: 478-923-832 E-mail: alexandergrib@rambler.ru"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Orange
extern double numPrognoz = 2;
extern int begin=1;
extern int end=5;
extern int Shift=5;
extern int Inst=1;//ind. instance on the chart 4 object name
double index_buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0,index_buffer);
SetIndexStyle(0,DRAW_LINE);
SetIndexShift(0,Shift);
ObjectCreate("begin"+Inst,OBJ_VLINE,0,0,0);
ObjectSet("begin"+Inst,OBJPROP_COLOR,Red);
ObjectCreate("end"+Inst,OBJ_VLINE,0,0,0);
ObjectSet("end"+Inst,OBJPROP_COLOR,Blue);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
ObjectDelete("begin"+Inst);
ObjectDelete("end"+Inst);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//----
int k; int z; int bar_num; int x;
double a = 0; double b1 = 1; double d = 1;
double b[5000];
double c[5000];
//Îïðåäåëÿåì êîýôèöèåíòû
for(k=end;k>=begin;k--)
{
b[k]=k;
c[k]=Close[k];
}
for(x=begin-numPrognoz;x<end+numPrognoz+1;x++)
{
a = 0;
for(k=begin;k<=end;k++)
{
b1=1;d=1;
//Ïðîèçâåäåíèå îò 0 äî i-1 ýëåìåíòà
for(z=begin;z<k;z++)
{
b1=b1*(x-b[z]);
d=d*(b[k]-b[z]);
}
//Ïðîèçâåäåíèå îò i+1 äî numBars ýëåìåíòà
for(z=k+1;z<=end;z++)
{
b1=b1*(x-b[z]);
d=d*(b[k]-b[z]);
}
a=a+c[k]*((b1)/(d));
}
bar_num = x;
index_buffer[bar_num]=a;
}
ObjectSet("begin"+Inst,OBJPROP_TIME1,Time[begin]);
ObjectSet("end"+Inst,OBJPROP_TIME1,Time[end]);
//----
return(0);
}
//+------------------------------------------------------------------+
Comments