Parabolic-close
Download scriptThis script is designed as a specialized technical indicator for the MetaTrader platform, specifically engineered to track price momentum and identify potential trend reversals. Unlike standard indicators that might simply lag behind price movement, this logic focuses on calculating a dynamic "reversal point" based on a parabolic acceleration model.
Core Logic and Behavior
1. Dynamic Trend Tracking The indicator monitors the direction of market price movement to determine if the current trend is bullish (upward) or bearish (downward). It calculates a specific value—similar to a Parabolic Stop and Reverse (SAR)—that follows the price closely. This value acts as a moving boundary; as long as the price stays on one side of this boundary, the current trend is considered intact.
2. Acceleration Mechanism A key feature of this script is its ability to "accelerate" the calculation. It uses two primary variables:
- Step: This determines the increment of acceleration.
- Maximum: This acts as a ceiling, ensuring that the acceleration does not increase indefinitely beyond a set threshold.
If the price reaches new highs (in an uptrend) or new lows (in a downtrend), the calculation becomes more sensitive. The indicator "speeds up" its response to the market by increasing the acceleration factor until it hits the predefined maximum. This ensures that the indicator reacts quickly during strong, sustained movements but remains stable during choppy markets.
3. Reversal Detection The script is constantly looking for a breach of its own calculated boundary.
- In an uptrend, if the price drops below the calculated reversal level, the logic triggers a "flip," switching the indicator to a bearish state and resetting the acceleration parameters.
- In a downtrend, if the price climbs above the reversal level, it flips to a bullish state and resets accordingly.
4. Visual Output The result is plotted on your chart as a continuous line (or section). By observing where this line moves in relation to the candles, traders can visually identify "flip zones"—points where the momentum has shifted significantly enough to warrant a change in trend perspective.
Summary for Traders
Essentially, this tool automates the math of identifying when a trend is losing steam. It identifies the moment the price "gives back" enough territory to suggest that the current move is exhausted. By utilizing parabolic acceleration, it attempts to stay as tight to the price action as possible during volatile moves while providing clear visual cues for potential entry or exit points based on trend reversals.
//+------------------------------------------------------------------+
//| Parabolic-close.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Blue
#property indicator_width1 2
//---- input parameters
extern double Step=0.005;
extern double Maximum=0.2;
//---- buffers
double SarBuffer[];
//----
int save_lastreverse;
bool save_dirlong;
double save_start;
double save_last_high;
double save_last_low;
double save_ep;
double save_sar;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_SECTION);
SetIndexArrow(0,159);
SetIndexBuffer(0,SarBuffer);
//----
return(0);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void SaveLastReverse(int last,int dir,double start,double low,double high,double ep,double sar)
{
save_lastreverse=last;
save_dirlong=dir;
save_start=start;
save_last_low=low;
save_last_high=high;
save_ep=ep;
save_sar=sar;
}
//+------------------------------------------------------------------+
//| Parabolic Sell And Reverse system |
//+------------------------------------------------------------------+
int start()
{
static bool first=true;
bool dirlong;
double start,last_high,last_low;
double ep,sar,price_low,price_high,price;
int i,counted_bars=IndicatorCounted();
//----
if(Bars<3) return(0);
//---- initial settings
i=Bars-2;
if(counted_bars==0 || first)
{
first=false;
dirlong=true;
start=Step;
last_high=-10000000.0;
last_low=10000000.0;
while(i>0)
{
save_lastreverse=i;
price_low=Close[i];
if(last_low>price_low) last_low=price_low;
price_high=Close[i];
if(last_high<price_high) last_high=price_high;
if(price_high>Close[i+1] && price_low>Close[i+1]) break;
if(price_high<Close[i+1] && price_low<Close[i+1]) { dirlong=false; break; }
i--;
}
//---- initial zero
int k=i;
while(k<Bars)
{
SarBuffer[k]=0.0;
k++;
}
//---- check further
if(dirlong) { SarBuffer[i]=Close[i+1]; ep=Close[i]; }
else { SarBuffer[i]=Close[i+1]; ep=Close[i]; }
i--;
}
else
{
i=save_lastreverse;
start=save_start;
dirlong=save_dirlong;
last_high=save_last_high;
last_low=save_last_low;
ep=save_ep;
sar=save_sar;
}
//----
while(i>=0)
{
price_low=Close[i];
price_high=Close[i];
//--- check for reverse
if(dirlong && price_low<SarBuffer[i+1])
{
SaveLastReverse(i,true,start,price_low,last_high,ep,sar);
start=Step; dirlong=false;
ep=price_low; last_low=price_low;
SarBuffer[i]=last_high;
i--;
continue;
}
if(!dirlong && price_high>SarBuffer[i+1])
{
SaveLastReverse(i,false,start,last_low,price_high,ep,sar);
start=Step; dirlong=true;
ep=price_high; last_high=price_high;
SarBuffer[i]=last_low;
i--;
continue;
}
//---
price=SarBuffer[i+1];
sar=price+start*(ep-price);
if(dirlong)
{
if(ep<price_high && (start+Step)<=Maximum) start+=Step;
if(price_high<Close[i+1] && i==Bars-2) sar=SarBuffer[i+1];
price=Close[i+1];
if(sar>price) sar=price;
price=Close[i+2];
if(sar>price) sar=price;
if(sar>price_low)
{
SaveLastReverse(i,true,start,price_low,last_high,ep,sar);
start=Step; dirlong=false; ep=price_low;
last_low=price_low;
SarBuffer[i]=last_high;
i--;
continue;
}
if(ep<price_high) { last_high=price_high; ep=price_high; }
}
else
{
if(ep>price_low && (start+Step)<=Maximum) start+=Step;
if(price_low<Close[i+1] && i==Bars-2) sar=SarBuffer[i+1];
price=Close[i+1];
if(sar<price) sar=price;
price=Close[i+2];
if(sar<price) sar=price;
if(sar<price_high)
{
SaveLastReverse(i,false,start,last_low,price_high,ep,sar);
start=Step; dirlong=true; ep=price_high;
last_high=price_high;
SarBuffer[i]=last_low;
i--;
continue;
}
if(ep>price_low) { last_low=price_low; ep=price_low; }
}
SarBuffer[i]=sar;
i--;
}
// sar=SarBuffer[0];
// price=iSAR(NULL,0,Step,Maximum,0);
// if(sar!=price) Print("custom=",sar," SAR=",price," counted=",counted_bars);
// if(sar==price) Print("custom=",sar," SAR=",price," counted=",counted_bars);
//----
return(0);
}
//+------------------------------------------------------------------+
Comments