Cronex_T_MA_Parabolic
Download scriptThis script is a specialized technical analysis tool designed to track and visualize price trends by combining two distinct types of moving averages: a standard Moving Average (MA) and a Parabolic SAR (Stop and Reverse) logic.
Core Operational Logic
The primary goal of this tool is to determine the "momentum" of a market—identifying whether the price is currently in an upward trend or a downward trend, and pinpointing the exact moment when that trend shifts. It achieves this through three distinct layers of calculation:
1. Trend Baseline (Moving Average) The script first calculates a baseline using a Moving Average. This serves as the smoothed "foundation" for the price. By smoothing out minor fluctuations, it allows the script to focus on the broader direction of the market rather than getting distracted by temporary noise.
2. Dynamic Trailing Logic (Parabolic SAR) The core engine of the script is a Parabolic SAR calculation. Unlike a static average, this logic "trails" the price.
- In an uptrend, it tracks a specific price level that follows behind the movement. If the price pushes higher, the trailing point moves up with it at a specific speed (the "Step").
- In a downtrend, it tracks a point from above. If the price drops lower, the trailing point moves down accordingly.
- The Reversal: The script is constantly looking for a "collision." If the price crosses over this trailing point, the logic assumes the trend has exhausted itself. It then instantly flips its direction (from buy to sell or vice versa), resets its starting points, and begins tracking the new trend from the opposite side.
3. Momentum Visualization (Difference Buffers) Finally, the script calculates the distance between the Moving Average and the Parabolic SAR point. This difference is used to generate a histogram (visual bars):
- Green Bars: Represent instances where the gap between the average and the SAR point is expanding or behaving in an upward manner.
- Red Bars: Represent instances where the gap is contracting or shifting downward.
How it behaves on a chart
For a user, this means the tool provides a dynamic visual of market sentiment. Instead of just showing you where the price was, it tries to predict where the "stop" point is for the current trend. When the histogram colors shift or the trailing points flip sides, it signals a potential change in market regime—moving from a period of growth to a period of decline, or vice versa.
//+------------------------------------------------------------------+
//| Ma-Parabolic_st2.mq4 |
//| Copyright © 2008, MetaQuotes Software Corp. |
//| Copyright © 2008, Ëóêàøóê Â.Ã. aka lukas1. |
//| Copyright © 20010, Cronex |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes"
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red
//---- input parameters
extern int Ma=13;
extern int method=3;
extern int app_price=0;
extern double Step=0.02;
extern double Maximum=0.04;
//---- buffers
double SarBuffer[];
double MaBuffer[];
double DVBuffUP[];
double DVBuffDN[];
//----
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
IndicatorBuffers(4);
IndicatorDigits(Digits);
string SS=DoubleToStr(Step,4);
string MM=DoubleToStr(Maximum,4);
SetIndexBuffer(0,DVBuffUP);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(1,DVBuffDN);
SetIndexStyle(1,DRAW_HISTOGRAM);
// SetIndexLabel(1,"period= "+Ma);
// SetIndexStyle(1,DRAW_NONE);
SetIndexBuffer(2,MaBuffer);
// SetIndexDrawBegin(0, 4/Step+Ma);
// SetIndexLabel(2,"Step= "+SS+", Max= "+MM);
// SetIndexStyle(2,DRAW_NONE);
// SetIndexArrow(2,159);
SetIndexBuffer(3,SarBuffer);
// SetIndexDrawBegin(2, 4/Step);
//----
//----
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--;
}
for(j=Bars-4;j>=0;j--)
{
if(MaBuffer[j]-SarBuffer[j]>MaBuffer[j+1]-SarBuffer[j+1])DVBuffUP[j] = MaBuffer[j]-SarBuffer[j];
if(MaBuffer[j]-SarBuffer[j]<MaBuffer[j+1]-SarBuffer[j+1])DVBuffDN[j] = MaBuffer[j]-SarBuffer[j];
}
//----
return(0);
}
//+------------------------------------------------------------------+
Comments