Bezier_orig

Download script
Author: Copyright � 2007, MetaQuotes Software Corp.
Bezier_orig

This tool is designed to create a smooth, flowing trend line on your trading chart by applying advanced mathematical smoothing to price action. Unlike standard moving averages that can appear jagged or lag significantly behind market movement, this indicator uses a sophisticated "Bezier" approach to visualize price trends more fluidly.

How it Works

The core logic of the script focuses on calculating a weighted average of recent price data. Instead of simply averaging the last few candles, it treats the price history as a series of points and applies a mathematical formula to "bend" the line between them. This creates a curved trajectory that better represents the organic flow of the market rather than a series of disconnected steps.

Key Features and Customization

To help you tailor the visual output to your specific trading style, the script includes several adjustable parameters:

  • Period: This determines how many past candles the indicator looks at to calculate the curve. A higher number will result in a smoother, broader trend line, while a lower number will make it react more quickly to immediate price changes.
  • T-Value (Smoothing Factor): This acts as a weight. It allows you to control the "tension" of the curve, influencing how much influence the most recent data has compared to older data in the calculation.
  • Shift: This allows you to move the resulting line forward or backward on your chart to align it with your specific visual needs.
  • Price Source: The indicator is highly versatile because it can be told which specific price point to follow. You can choose to base the curve on:
    • Standard prices (Open, High, Low, Close).
    • Calculated mid-points (like the average of the High and Low).
    • A secondary Moving Average for an even more filtered perspective.

Visual Output

The result is a continuous, fluid line drawn directly on your main chart window. By filtering out the "noise" of minor price fluctuations, it helps traders identify the underlying momentum of the market, making it easier to see the direction of the trend at a glance.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
9 Views
0 Downloads
0 Favorites
Bezier_orig
//+------------------------------------------------------------------+
//|                                                       Bezier.mq4 |
//|                      Copyright © 2007, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2007, MetaQuotes Software Corp."
#property link      "Lizhniyk E"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Aqua

//---- input parameters
extern int period=8;
extern double t=0.5;
extern int shift=0;
extern int  Price=0;
double Ext[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Ext);
   SetIndexLabel(0,"Bezier("+period+","+t+")");
   SetIndexShift(0,shift);
   SetIndexDrawBegin(0,period);
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted(); 
//----

 for(int j=0;j<Bars-counted_bars;j++)
 {
 double r=0;
   for(int i=period;i>=0;i--)
    {
    r+=pr(Price,j+i) * 
     (fact(period)/(fact(i)*fact(period-i))) * 
      MathPow(t,i) * 
       MathPow(1-t,period-i);
    }
  Ext[j]=r;
  }  
//----
   return(0);
  }
//+------------------------------------------------------------------+
double fact(int value)
{
double res=1;
for(double j=2;j<value+1;j++)
 {
 res*=j;
 } 
return (res); 
}

double pr(int Price,int n)
{
switch (Price)
 {
 case 0: {return(Close[n]);break;} 
 case 1: {return(Open[n]);break;}
 case 2: {return(High[n]);break;}
 case 3: {return(Low[n]);break;}
 case 4: {return((High[n]+Low[n])/2);break;}
 case 5: {return((High[n]+Low[n]+Close[n])/3);break;}
 case 6: {return((High[n]+Low[n]+Close[n]+Close[n])/4);break;}
 case 7: {return(iMA(Symbol(),0,4,0,0,0,n));break;}
 }
}

Comments