ParabolicM
Download scriptThis script is designed to function as a specialized technical indicator for trading platforms. Its primary purpose is to identify and visualize trend reversals by calculating a dynamic "Parabolic" value that follows price movements.
Core Logic Overview
The logic operates by tracking the momentum of the market to determine whether the current price action is trending upwards (bullish) or downwards (bearish). Rather than using a simple moving average, it uses a recursive calculation—meaning each new position depends on the previous one—to create a smooth, curving line that reacts to significant price changes.
Key Functional Components
1. Trend Identification and Direction The script constantly evaluates the relationship between current prices (the highs and lows of specific candles) and the previous calculated value. It maintains a "state" of the trend:
- Long Trend: When the market shows strength, the indicator tracks the movement upward.
- Short Trend: When the market shows weakness, the indicator tracks the movement downward.
2. Dynamic Adjustment (The Parabolic Effect) The script uses two primary settings to control its behavior:
- Step: This determines how quickly the indicator accelerates as the price moves in a specific direction. As the trend continues, the "Step" allows the line to curve more aggressively toward the current price.
- Maximum: This acts as a safety ceiling or limit on the acceleration. It prevents the indicator from becoming too vertical or overly sensitive, ensuring it remains grounded in the actual market data.
3. Reversal Detection The "intelligence" of the script lies in its ability to detect when a trend has exhausted itself. The logic monitors for specific "breakout" events:
- If the price penetrates significantly past the current trailing value in the opposite direction, the script triggers a reversal.
- Once a reversal is detected, the script resets its internal variables (like the starting point and the high/low benchmarks) and flips its direction.
4. Visual Output Instead of drawing a continuous line across the chart, this specific implementation is designed to place visual markers (arrows) at key reversal points. This helps traders see exactly where the logic decided the trend shifted from upward to downward, or vice versa.
Summary for the User
In plain terms, this script acts like a "smart" trailing line. It follows the price closely during strong moves, accelerating as the move gets stronger, but it is programmed to "flip" its direction immediately when the price breaks back against the trend. By looking at the markers provided by this script, you can identify potential turning points where the momentum of the market has shifted from one extreme to another.
//+------------------------------------------------------------------+
//| Parabolic.mq4 |
//| Copyright © 2004, MetaQuotes Software Corp. |
//| http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net/"
//----
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Lime
//---- input parameters
extern double Step=0.02;
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;
double up, down;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexStyle(0,DRAW_ARROW);
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;
if (Close[i]>=Open[i])
{
price_low=Open[i];
price_high=Close[i];
} else
{
price_low=Close[i];
price_high=Open[i];
}
if (Close[i+1]>=Open[i+1])
{
down=Open[i+1];
up=Close[i+1];
} else
{
down=Close[i+1];
up=Open[i+1];
}
if(last_low>price_low) last_low=price_low;
if(last_high<price_high) last_high=price_high;
if(price_high>up && price_low>down) break;
if(price_high<up && price_low<down) { dirlong=false; break; }
i--;
}
//---- initial zero
int k=i;
while(k<Bars)
{
SarBuffer[k]=0.0;
k++;
}
//---- check further
if(dirlong) { SarBuffer[i]=down; ep=price_high; }
else { SarBuffer[i]=up; ep=price_low; }
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)
{
if (Close[i]>=Open[i])
{
price_low=Open[i];
price_high=Close[i];
} else
{
price_low=Close[i];
price_high=Open[i];
}
if (Close[i+1]>=Open[i+1])
{
down=Open[i+1];
up=Close[i+1];
} else
{
down=Close[i+1];
up=Open[i+1];
}
//--- 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<up && i==Bars-2) sar=SarBuffer[i+1];
//----
price=down;
if(sar>price) sar=price;
price=down;
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<down && i==Bars-2) sar=SarBuffer[i+1];
//----
price=up;
if(sar<price) sar=price;
price=up;
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