P&F_v2_alerts

Download script
P&F_v2_alerts

Overview

This script is a custom technical analysis tool designed to identify and visualize market trends based on "Price and Figure" (P&F) logic. Rather than simply looking at moving averages or standard momentum, this tool focuses on tracking the structural highs and lows of price action to determine whether the market is currently in an upward or downward phase. It automatically plots these trend boundaries and provides visual and audible signals when the market sentiment shifts.

Core Logic & Functionality

1. Dynamic Trend Tracking The script continuously scans recent price data to establish "trend boundaries." It monitors the highest and lowest points reached during specific periods. By comparing the current price action against these established boundaries, the tool can distinguish between a continuation of the current trend and the beginning of a new one.

2. Reversal Detection A key feature of this logic is its ability to filter out "market noise." Instead of reacting to every minor price fluctuation, the script requires a specific threshold—a "Reversal" value—to be met before it confirms a change in trend direction. This ensures that the signals provided are significant and not just small pullbacks or temporary spikes.

3. Intelligent Signal Generation When the tool detects a confirmed shift in momentum, it generates two types of actions:

  • Visual Indicators: It places specific markers (arrows) on your chart to highlight exactly where an upward or downward trend has been initiated.
  • Dynamic Range Calculation: The script calculates a "Range" based on the average volatility of the most recent price bars. This value is used to offset signals, helping to place them in a clear, visible area on the chart.

4. Automated Notifications To ensure traders can react quickly without constantly staring at the screen, the script includes a comprehensive alert system. When a significant trend reversal occurs, the tool can perform several actions simultaneously:

  • Trigger an On-Screen Alert (Pop-up message).
  • Play a specific Sound File to provide an immediate audio cue.
  • Send an Email Notification (optional) for traders who need to be notified even when they are away from their computers.

Key Parameters for Customization

Users can fine-tune the script's behavior to match their specific trading style:

  • BoxSize & Reversal: These allow you to control how sensitive the tool is to trend changes (e.g., making it more "strict" to avoid false signals or "loose" to catch early movements).
  • ShowBars: This allows you to limit how much historical data the indicator processes on your screen, helping to keep the chart clean.
  • Alert Settings: You can easily toggle sounds, pop-ups, and emails on or off depending on your preference.
Miscellaneous
Implements a curve of type %1It plays sound alerts
18 Views
0 Downloads
0 Favorites
P&F_v2_alerts
//+--------------------------------------------------------------------------------------------+
//|   P&F_v2.mq4
//+--------------------------------------------------------------------------------------------+
#property indicator_chart_window

#property indicator_buffers 5
#property indicator_color1 Blue
#property indicator_color2 Blue
#property indicator_color3 Green
#property indicator_color4 Crimson
#property indicator_color5 EMPTY

extern int BoxSize = 20;
extern int Reversal = 3;

extern int     arrWidth= 0;
extern double  arrDistance= 0.5;

extern int ShowBars = 500;


extern bool    SoundAlert  = true;  
extern bool    BoxAlert    = true;
extern bool    EmailAlert  = false;
extern int     AlertOnBar  = 0;
extern string  soundfile   = "ok.wav";//alert alert2 ok.wav   ...etc

bool   UpTrendAlert=false, DownTrendAlert=false;
datetime alerttag;


double UpTrend[];
double DownTrend[];
double UpSignal[];
double DownSignal[];
double Trend[];

int init()
{
      
   IndicatorBuffers(5);
   
   SetIndexStyle(0,DRAW_LINE);
   SetIndexEmptyValue(0,0.0);
   SetIndexBuffer(0,UpTrend);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexEmptyValue(1,0.0);
   SetIndexBuffer(1,DownTrend);
   
   SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,arrWidth);
   SetIndexArrow(2,233);
   SetIndexEmptyValue(2,0.0);
   SetIndexBuffer(2,UpSignal);
   
   SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,arrWidth);
   SetIndexArrow(3,234);
   SetIndexEmptyValue(3,0.0);
   SetIndexBuffer(3,DownSignal);
   
   SetIndexStyle(4,DRAW_NONE);
   SetIndexEmptyValue(4,0.0);
   SetIndexBuffer(4,Trend);
   
   return(0);
}

int deinit()
{
   return(0);
}

int start()
{
   
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1); //---- check for possible errors
   if(counted_bars>0) counted_bars--; //---- last counted bar will be recounted
   
   for (int i=Bars-counted_bars;i>=0;i--)
   {

      double   Range = 0.0;
      for (int counter=i ;counter<=i+9;counter++) 
               Range += MathAbs(High[counter]-Low[counter]);
               Range /= 10;
               Range=Range*arrDistance;




      if (ShowBars == 0 || (ShowBars > 0 && i <= ShowBars))
      {
         if (Trend[i+1] == 0)
         {
            if (Low[i]+(BoxSize*Point) < High[i])
            {
               DownTrend[i] = Low[i];
               UpTrend[i] = High[i];
               Trend[i] = -1;
               DownSignal[i] = High[i]+Range;
            }
            else
            if (High[i]-(BoxSize*Point) > Low[i])
            {
               DownTrend[i] = Low[i];
               UpTrend[i] = High[i];
               Trend[i] = 1;
               UpSignal[i] = Low[i]-Range;
            }
            else
            {
               DownTrend[i] = DownTrend[i+1];
               UpTrend[i] = UpTrend[i+1];
               Trend[i] = Trend[i+1];
            }
         }
         else
         if (Trend[i+1] == -1)
         {
            if (Low[i]+(BoxSize*Point) < DownTrend[i+1])
            {
               DownTrend[i] = Low[i];
               UpTrend[i] = UpTrend[i+1];
               Trend[i] = Trend[i+1];
            }
            else
            if (High[i] > DownTrend[i+1]+((BoxSize*Point)*Reversal))
            {
               UpTrend[i] = High[i];
               DownTrend[i] = Low[i];
               Trend[i] = 1;
               UpSignal[i] = Low[i]-Range;
            }
            else
            {
               DownTrend[i] = DownTrend[i+1];
               UpTrend[i] = UpTrend[i+1];
               Trend[i] = Trend[i+1];
            }
         }
         else
         if (Trend[i+1] == 1)
         {
            if (High[i]-(BoxSize*Point) > UpTrend[i+1])
            {
                DownTrend[i] = DownTrend[i+1];
                UpTrend[i] = High[i];
                Trend[i] = Trend[i+1];
            }
            else
            if (Low[i] < UpTrend[i+1]-((BoxSize*Point)*Reversal))
            {
               UpTrend[i] = High[i];
               DownTrend[i] = Low[i];
               Trend[i] = -1;
               DownSignal[i] = High[i]+Range;
            }
            else
            {
               DownTrend[i] = DownTrend[i+1];
               UpTrend[i] = UpTrend[i+1];
               Trend[i] = Trend[i+1];
            }
         }
      }
              



//----
   string Message;
	Message = " "+Symbol()+" M"+Period()+" P&F:";
   int b=AlertOnBar;
   if ( UpSignal[b+1]==0.0  && UpSignal[b]!=0.0 && Volume[0]>1 && !UpTrendAlert && alerttag!=Time[0])
	  {
	  if ( BoxAlert )   Alert (Message," signal UP");  
	  if ( SoundAlert ) PlaySound(soundfile);
	  if ( EmailAlert ) SendMail ("From P&F",Message);
	  UpTrendAlert=true; DownTrendAlert=false; alerttag =Time[0];
	  } 
	 	  
	if ( DownSignal[b+1]==0.0 && DownSignal[b]!=0.0 && Volume[0]>1 && !DownTrendAlert && alerttag!=Time[0])
	  {
	  if ( BoxAlert )   Alert (Message," signal DOWN");  
	  if ( SoundAlert ) PlaySound(soundfile);
	  if ( EmailAlert ) SendMail ("From P&F",Message);
	  DownTrendAlert=true; UpTrendAlert=false; alerttag=Time[0];
	  } 	         
//----



   }

   return(0);
}
//+------------------------------------------------------------------+

Comments