P&F_v2

This script is a technical analysis tool designed to visualize market structure by identifying and highlighting significant price movements. It focuses on "Price and Frond" logic, which helps traders see the underlying trends by filtering out minor price fluctuations (noise) and focusing on substantial shifts in momentum.

Core Functionality

The primary purpose of this script is to map out the prevailing trend of a financial asset. It does this by calculating high and low boundaries and tracking when the price moves significantly enough to be considered a "reversal" or a continuation of a trend.

Key Components of the Logic:

1. Trend Detection and Mapping The script scans the historical data to establish whether the market is moving in an upward or downward direction. It creates visual boundaries for these trends:

  • Upward Trends: Highlighted to show where price strength is increasing.
  • Downward Trends: Highlighted to show where price weakness is prevailing.

2. The "Box Size" and Reversal Thresholds To prevent the indicator from reacting to every tiny wiggle in the market, the script uses a specific set of rules:

  • Sensitivity: It uses a "Box Size" parameter to determine the minimum distance price must travel to trigger a change in trend status.
  • Reversal Confirmation: It looks for a specific "Reversal" amount. This means a trend only flips if the price breaks past a previous level by a significant margin, ensuring that only high-conviction moves are captured as trend changes.

3. Visual Signals (Arrows) Beyond just drawing lines to show the trend, the script provides proactive visual cues:

  • When the logic detects a definitive shift from a downward trend to an upward trend (or vice versa), it places visual arrows on the chart.
  • These arrows serve as immediate alerts for traders, signaling the exact moment the script identifies a potential entry point or a shift in market sentiment.

4. Dynamic Memory The script is designed to "remember" the previous state of the market. If the current price action does not meet the specific requirements to trigger a new trend or a reversal, the script maintains the previous trend data. This ensures that the lines on your chart remain continuous and stable rather than flickering between different values.

Summary for the User

In simple terms, this tool acts as a filter. It looks at the "big picture" of the price action, ignores the small distractions, and draws clear paths showing you which way the market is currently heading. When the market makes a strong enough move to change direction, the script updates the trend path and provides a visual arrow to alert you to the shift.

Miscellaneous
Implements a curve of type %1
5 Views
0 Downloads
0 Favorites
P&F_v2
//+--------------------------------------------------------------------------------------------+
//|   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 ShowBars = 500;

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

int init()
{
      
   IndicatorBuffers(5);
   
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
   SetIndexEmptyValue(0,0.0);
   SetIndexBuffer(0,UpTrend);
   
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
   SetIndexEmptyValue(1,0.0);
   SetIndexBuffer(1,DownTrend);
   
   SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,1);
   SetIndexArrow(2,233);
   SetIndexEmptyValue(2,0.0);
   SetIndexBuffer(2,UpSignal);
   
   SetIndexStyle(3,DRAW_ARROW,STYLE_SOLID,1);
   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--)
   {
      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]+(5*Point);
            }
            else
            if (High[i]-(BoxSize*Point) > Low[i])
            {
               DownTrend[i] = Low[i];
               UpTrend[i] = High[i];
               Trend[i] = 1;
               UpSignal[i] = Low[i]-(5*Point);
            }
            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]-(5*Point);
            }
            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]+(5*Point);
            }
            else
            {
               DownTrend[i] = DownTrend[i+1];
               UpTrend[i] = UpTrend[i+1];
               Trend[i] = Trend[i+1];
            }
         }
      }
   }           

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

Comments