Ma_Parabolic_st2_2

Download script
Author: Copyright � 2008, MetaQuotes + lukas1
Ma_Parabolic_st2_2

This script is designed as a custom technical analysis tool for the MetaTrader platform. It combines two popular trading concepts—Moving Averages and Parabolic Reversals—to help traders visualize price momentum and identify potential trend reversals on a chart.

Core Logic Overview

The indicator functions by analyzing price movements through a smoothed "Moving Average" line while simultaneously calculating a dynamic "Parabolic" trailing value. Instead of looking at raw price alone, it uses the Moving Average as its primary foundation to filter out minor market noise.

Key Components

1. The Foundation (Moving Average) The script first generates a smooth line based on a user-defined period and calculation method. This acts as the "base" for all subsequent calculations, ensuring that the signals generated are based on established trends rather than erratic price spikes.

2. Dynamic Trend Tracking The logic is divided into two primary states: Long (Uptrend) and Short (Downtrend).

  • In an Uptrend: The script tracks the highest points reached by the Moving Average. It uses a "Step" system to adjust how aggressively it follows the price. If the price continues to move up, the indicator adjusts its sensitivity until it hits a predefined maximum limit.
  • In a Downtrend: Conversely, the script focuses on the lowest points. It tracks these minimums and adjusts its sensitivity as the price moves downward.

3. Reversal Detection (The "Sar" Logic) This is the core mechanism of the script. It calculates a specific value (similar to a Parabolic SAR) based on the distance between previous highs/lows and the current moving average.

  • The Switch: When the calculated Parabolic value crosses over the Moving Average in the opposite direction, the script recognizes this as a potential trend reversal.
  • Resetting: Once a reversal is detected (e.g., switching from an uptrend to a downtrend), the script "resets" its tracking points. It captures the new extreme high or low and flips its logic to begin tracking the new trend direction.

Visual Representation

On the trading chart, the logic provides two distinct visual aids:

  • A Trend Line: A smoothed line that shows the general direction of the market.
  • Signal Points: Specific markers (arrows) that appear when the internal logic detects a trend flip. These are designed to signal where the "Parabolic" value has breached the Moving Average, suggesting that the current momentum is exhausting and a move in the opposite direction may be beginning.

Summary of Operation

Essentially, the script asks: "Is the current price movement strong enough to maintain the existing trend based on our smoothed average?" If the price fails to maintain that strength and the trailing parabolic value "pierces" through the average, the indicator signals a reversal and begins tracking the new direction immediately.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
4 Views
1 Downloads
0 Favorites
Ma_Parabolic_st2_2
//+------------------------------------------------------------------+
//|                                             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 StepH=0.2;//äëÿ âåðõíèõ òî÷åê
extern double MaximumH=0.5;//

extern double StepL=0.02;//äëÿ íèæíèõ òî÷åê
extern double MaximumL=0.05;//

//---- 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);
   SetIndexLabel(0,NULL); 
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,159);
   SetIndexBuffer(0,SarBuffer);
   int draw_bars=4/MathMin(StepH,StepL);
   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);
   if(StepH >MaximumH) StepH = MaximumH;
   if(StepL >MaximumL) StepL = MaximumL;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Parabolic Sell And Reverse system                                |
//+------------------------------------------------------------------+
int start()
  {
   if(Bars<5) return(0);
   dirlong=true;
   start=MathMin(StepH,StepL);
//--------------------------------------------+
   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+StepL)<=MaximumL) start+=StepL;
         if(sar>=price_low)//åñëè óñëîâèÿ äëÿ ïåðåêëþ÷åíèÿ íàñòóïèëè
           {
            start=StepL; 
            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+StepL)<=MaximumL) start+=StepL;
            //è ïåðåñ÷èòûâàåì last_high è ep äëÿ ðàñ÷åòà ñëåäóþùåé òî÷êè ìàêñèìóìà
            if(ep<price_high) { last_high=price_high; ep=price_high; }
           }
        }
//----
      else//öåïî÷êà âíèç
        {
         if(ep>price_low && (start+StepH)<=MaximumH) start+=StepH;
         if(sar<=price_high)//åñëè íàñòóïèëè óñëîâèÿ ïåðåêëþ÷åíèÿ
           {
            start=StepH; 
            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+StepH)<=MaximumH) start+=StepH;
            //åñëè óñëîâèÿ äëÿ ïåðåêëþ÷åíèÿ íå íàñòóïèëè
            //òî ïåðåñ÷èòûâàåì last_low è ep äëÿ ðàñ÷åòà ñëåäóþùåé òî÷êè ìèíèìóìà
            if(ep>price_low){last_low=price_low;ep=price_low;}
           }
        }
      SarBuffer[i]=sar;
      i--;
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments