Ma_Parabolic_Alert_2_v1

Download script
Author: Copyright � 2007
Ma_Parabolic_Alert_2_v1

This script is a technical analysis tool designed to identify potential trend reversals and market direction on a trading chart. It combines two distinct mathematical concepts—Moving Averages and Parabolic Trends—to provide visual signals for traders.

Core Logic and Functionality

The indicator operates by layering two different types of data analysis:

1. The Foundation: Moving Average Smoothing Before generating signals, the script calculates a "Moving Average" (MA). This is a method of smoothing out price fluctuations to reveal the underlying trend. Depending on your settings, it can calculate this based on various methods (like Simple, Exponential, or Weighted averages) and different price points (such as the closing price, high, or low). This serves as the primary data source for the rest of the calculations.

2. The Dynamic Engine: Parabolic Trailing The script then applies a "Parabolic" logic to that Moving Average. Instead of just showing a flat line, it creates a dynamic tracking value (similar to a Parabolic SAR).

  • Trend Acceleration: As the price moves consistently in one direction, the script calculates a "Step." If the momentum continues, this step increases, making the indicator more sensitive to changes.
  • Dynamic Adjustment: The logic continuously monitors whether the price is hitting new highs or lows. It adjusts its tracking point based on these extremes to ensure it stays aligned with the current market strength.

3. Signal Generation (The Reversal System) The main goal of the script is to detect when the trend "breaks."

  • Buy Signals: When the price moves significantly above the calculated parabolic line, the script identifies a bullish shift. It will then trigger a visual arrow on the chart and can be set to provide an audible alert.
  • Sell Signals: Conversely, if the price drops significantly below the parabolic line, it detects a bearish shift, triggering a sell signal and a corresponding alert.

User Experience Summary

For someone watching the live chart, this script acts as an automated "trend watcher." It filters out minor market noise using the Moving Average, calculates the strength of the current move using Parabolic logic, and places visual markers on the screen whenever it detects that the price has moved far enough in the opposite direction to suggest a potential trend reversal.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
17 Views
0 Downloads
0 Favorites
Ma_Parabolic_Alert_2_v1
//+------------------------------------------------------------------+
//|                                                 Ma_Parabolic.mq4 |
//|                                         Copyright © 2007         |
//+------------------------------------------------------------------+
// Olker,  kroufr.ru
#property copyright "Copyright © 2007"
#property link      ""
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 Red
//---- input parameters
extern int MA      =24; // Period MA
extern int MA_Mode =2;  // 0=sma, 1=ema, 2=smma, 3=lwma
extern int MA_Price=0;  // 0-CLOSE,1-OPEN,2-HIGH,3-LOW,4-MEDIAN,5-TYPICAL,6-WEIGHTED
extern double    Step=0.02;
extern double    Maximum=0.08;
extern bool Alert_Sound=true;
//---- buffers
double SarBuffer[];
double MaBuffer[];
//----
int    save_lastreverse;
bool   save_dirlong;
double save_start;
double save_last_high;
double save_last_low;
double save_ep;
double save_sar;
//---- Íîìåð áàðà, ïî êîòîðîìó áóäåò èñêàòüñÿ ñèãíàë
#define SIGNAL_BAR 1
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexArrow(0,159);
   SetIndexBuffer(0,SarBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,MaBuffer);
//----
   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();
//----
   for(i=0; i<Bars-MA-2; i++)
      MaBuffer[i]=iMA(NULL,0,MA,0,MA_Mode,MA_Price,i);
//---- 
   if(Bars<0) return(0);
//---- initial settings
   i=Bars-2;
   if(counted_bars==0 || first)
     {
      first=true;
      dirlong=true;
      start=Step;//start=0.002
      last_high=-10000000.0;
      last_low=10000000.0;
      while(i>0)
        {
         save_lastreverse=i;
         price_low=MaBuffer[i];
         if(last_low>price_low)   last_low=price_low;
         price_high=MaBuffer[i];
         if(last_high<price_high) last_high=price_high;
         if(price_high>MaBuffer[i+1] && price_low>MaBuffer[i+1]) break;
         if(price_high<MaBuffer[i+1] && price_low<MaBuffer[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]=MaBuffer[i+1]; ep=MaBuffer[i]; }
      else        { SarBuffer[i]=MaBuffer[i+1]; ep=MaBuffer[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=MaBuffer[i];
      price_high=MaBuffer[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<MaBuffer[i+1] && i==Bars-2)  sar=SarBuffer[i+1];
         price=MaBuffer[i+1];
         if(sar>price) sar=price;
         price=MaBuffer[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<MaBuffer[i+1] && i==Bars-2)  sar=SarBuffer[i+1];
         price=MaBuffer[i+1];
         if(sar<price) sar=price;
         price=MaBuffer[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--;
     }
//---- âðåìÿ ïîñëåäíåãî áàðà è íàïðàâëåíèå ïîñëåäíåãî ñèãíàëà
   static int PrevSignal=0, PrevTime=0;
//---- Åñëè áàðîì äëÿ àíàëèçà âûáðàí íå 0-é, íàì íåò ñìûñëà ïðîâåðÿòü ñèãíàë
//---- íåñêîëüêî ðàç. Åñëè íå íà÷àëñÿ íîâûé áàð, âûõîäèì.
   if(SIGNAL_BAR > 0 && Time[0]<=PrevTime)
      return(0);
//---- Îòìå÷àåì, ÷òî ýòîò áàð ïðîâåðåí
   PrevTime=Time[0];
//---- Åñëè ïðåäûäóùèé ñèãíàë áûë ÑÅËË èëè ýòî ïåðâûé çàïóñê (PrevSignal=0)
   if(PrevSignal<=0)
     {
      if(Close[SIGNAL_BAR] - SarBuffer[SIGNAL_BAR] > 0)
        {
         PrevSignal=1;
         if (Alert_Sound)Alert("Ma_Parabolic(", Symbol(), ", ", Period(), ")  -  BUY");
        }
     }
   if(PrevSignal>=0)
     {
      if(SarBuffer[SIGNAL_BAR] - Close[SIGNAL_BAR] > 0)
        {
         PrevSignal=-1;
         if (Alert_Sound)Alert("Ma_Parabolic(", Symbol(), ", ", Period(), ")  -  SELL");
        }
     }
//----
   return(0);
  }
//+------------------------------------------------------------------+

Comments