Ma_Parabolic_Alert_2

Download script
Author: Copyright � 2007
Ma_Parabolic_Alert_2

This script functions as a technical analysis tool designed to identify trend reversals and market momentum. It combines two core components: a Moving Average (MA) and a Parabolic SAR-style calculation to generate visual signals and alerts on a trading chart.

Core Logic Overview

The indicator works by tracking the price action relative to a smoothed average of previous prices. Instead of simply looking at where the price is now, it attempts to predict where a "reversal" might occur by calculating a trailing line that follows the price at a specific distance.

How the System Operates

1. Data Smoothing (The Moving Average) The script begins by calculating a Moving Average based on parameters you choose (such as the time period, the calculation mode, and the specific price point like "Close" or "High"). This serves as the foundational baseline for all subsequent calculations, filtering out minor market noise to focus on the broader trend.

2. The Parabolic Trailing Logic The script calculates a dynamic trailing line (similar to a Parabolic Stop and Reverse). Here is how that logic behaves:

  • Trend Following: When the price moves in a specific direction, the script adjusts a "step" value. As the trend strengthens, this step increases, causing the trailing line to move closer to the price.
  • Dynamic Acceleration: The system includes a "Maximum" limit to ensure that while the trailing line speeds up during strong trends, it doesn't become too erratic.
  • Reversal Detection: The logic constantly monitors the relationship between the current price and this trailing line. If the price crosses over the trailing line in a specific direction (e.g., dropping below a high trailing line or rising above a low one), the script identifies this as a "Reverse" signal.

3. Signal Generation and Alerts Once a reversal is detected by the logic:

  • Visual Cues: The indicator places marks (arrows/lines) on the chart to show where the trend switched from upward to downward, or vice versa.
  • Smart Filtering: To prevent "false alarms" caused by price flickering within a single candle, the script uses a verification system. It ensures it only triggers a signal once per new bar of time.
  • Notifications: If the conditions for a reversal are met—specifically when the closing price confirms a move past the trailing line—the script will trigger an audible and visual alert on your platform, notifying you of a potential "BUY" or "SELL" opportunity.

Summary for the User

Essentially, this tool acts as a "trend hunter." It smooths out the market data to see the true direction, calculates a dynamic "safety line" that follows that trend, and alerts you the moment the price breaks through that line, suggesting that the momentum may have shifted in the opposite direction.

Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1It issuies visual alerts to the screen
10 Views
0 Downloads
0 Favorites
Ma_Parabolic_Alert_2
//+------------------------------------------------------------------+
//|                                                 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