Ma_Parabolic_st2.1
Download scriptThis script is a custom technical analysis tool designed for trading platforms to help visualize market trends and potential reversal points. It combines two distinct mathematical concepts—a Moving Average and a Parabolic SAR (Stop and Reverse) logic—to provide a dynamic way of tracking price momentum.
Core Functionality
The indicator works by monitoring the relationship between a smoothed average of the price and a calculated "trailing" point. Here is the breakdown of its internal logic:
1. Trend Smoothing (Moving Average) The tool begins by calculating a Moving Average (MA). Instead of looking at the raw, erratic price movements of the market, it uses this average to identify the general direction of the trend. This acts as the "baseline" for the rest of the calculations.
2. Dynamic Trailing Logic (Parabolic SAR) The most unique feature of this script is how it calculates its signals. It uses a "Step" and "Maximum" logic, similar to a Parabolic SAR:
- Acceleration: As the price moves in a consistent direction (up or down), the indicator increases its sensitivity. It "accelerates" by adding a small step to its calculation to stay tight to the current price action.
- The Ceiling: To prevent the calculation from becoming too erratic or moving too far away from the data, it has a "Maximum" limit. This ensures the acceleration stays within a reasonable professional boundary.
3. Reversal Detection The script is programmed to switch between "Long" (upward) and "Short" (downward) modes automatically:
- In an Upward Trend: It looks for instances where the moving average falls below the trailing calculation. When this happens, the script signals a potential trend reversal, resets its acceleration, and switches to a downward tracking mode.
- In a Downward Trend: It monitors for the moving average to rise above the trailing calculation. Once triggered, it signals a move back toward an upward trend and resets accordingly.
Visual Representation
For the user, this logic results in two distinct visual elements on the chart:
- A Moving Average Line: This provides a smooth visual of the current price path.
- Signal Arrows: These indicate exactly where the mathematical conditions for a trend reversal have been met, marking the transition from one market direction to another.
In summary, this tool filters out market noise by smoothing the price data and then applies an accelerating trailing calculation that reacts quickly to momentum shifts while maintaining a stabilized "ceiling" to avoid false triggers.
//+------------------------------------------------------------------+
//| Ma-Parabolic_st2.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| Copyright © 2008, Ëóêàøóê Â.Ã. aka lukas1. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes + lukas1"
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Orchid
#property indicator_color2 Maroon
//---- input parameters
extern int Ma=14;
extern int method=3;
extern int app_price=0;
extern double Step=0.02;
extern double Maximum=0.04;
//---- buffers
double SarBuffer[];
double MaBuffer[];
//----
static bool first=false;
bool dirlong;
double start,last_high,last_low;
double ep,sar,price_low,price_high;
int i,j;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorDigits(Digits);
string SS=DoubleToStr(Step,4);
string MM=DoubleToStr(Maximum,4);
SetIndexLabel(0,"Step= "+SS+", Max= "+MM);
SetIndexStyle(0,DRAW_ARROW);
SetIndexArrow(0,159);
SetIndexBuffer(0,SarBuffer);
int draw_bars=4/Step;
if(draw_bars>Bars-100) draw_bars=Bars-100;
SetIndexDrawBegin(0, draw_bars);
//----
SetIndexLabel(1,"period= "+Ma);
SetIndexStyle(1,DRAW_LINE,0,2);
SetIndexBuffer(1,MaBuffer);
SetIndexDrawBegin(0, draw_bars);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Parabolic Sell And Reverse system |
//+------------------------------------------------------------------+
int start()
{
if(Bars<5) return(0);
dirlong=true;
start=Step;
//--------------------------------------------+
for(j=Bars-4;j>=0;j--)
MaBuffer[j] = iMA(Symbol(),0,Ma,0,method,app_price,j);
int i=Bars-4;
while(i>=0)
{
price_low=MaBuffer[i]-Point;
price_high=MaBuffer[i]+Point;
//sar ðàâåí öåíà ïðåäûäóùåãî áàðà ïëþñ øàã óìíîæèòü íà
//(ñòàðàÿ öåíà ìèíóñ çíà÷åíèå SarBuffer ïðåäûäóùåãî áàðà)
sar=SarBuffer[i+1]+start*(ep-SarBuffer[i+1]);
//----
if(dirlong)//öåïî÷êà ââåðõ
{
if(ep<price_high && (start+Step)<=Maximum) start+=Step;
if(sar>=price_low)//åñëè óñëîâèÿ äëÿ ïåðåêëþ÷åíèÿ íàñòóïèëè
{
start=Step;
dirlong=false;
ep=price_low;//óñòàíàâëèâàåì ïîñëåäíþþ öåíó = ìèíèìóì
last_low=price_low;
if(MaBuffer[i]+Point<last_high) SarBuffer[i]=last_high;
else SarBuffer[i]=MaBuffer[i]+Point;
i--;
continue;
}
else
{
if(ep<price_low && (start+Step)<=Maximum) start+=Step;
//è ïåðåñ÷èòûâàåì last_high è ep äëÿ ðàñ÷åòà ñëåäóþùåé òî÷êè ìàêñèìóìà
if(ep<price_high) { last_high=price_high; ep=price_high; }
}
}
//----
else//öåïî÷êà âíèç
{
if(ep>price_low && (start+Step)<=Maximum) start+=Step;
if(sar<=price_high)//åñëè íàñòóïèëè óñëîâèÿ ïåðåêëþ÷åíèÿ
{
start=Step;
dirlong=true;
ep=price_high;//óñòàíàâëèâàåì ïîñëåäíþþ öåíó = ìàêñèìóì
last_high=price_high;
if(MaBuffer[i]-Point>last_low) SarBuffer[i]=last_low;
else SarBuffer[i]=MaBuffer[i]-Point;
i--;
continue;
}
else
{
if(ep>price_high && (start+Step)<=Maximum) start+=Step;
//åñëè óñëîâèÿ äëÿ ïåðåêëþ÷åíèÿ íå íàñòóïèëè
//òî ïåðåñ÷èòûâàåì last_low è ep äëÿ ðàñ÷åòà ñëåäóþùåé òî÷êè ìèíèìóìà
if(ep>price_low){last_low=price_low;ep=price_low;}
}
}
SarBuffer[i]=sar;
i--;
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments