Author: Copyright 2018, MetaQuotes Software Corp.

This script is a custom technical analysis indicator designed for the MetaTrader 5 platform. Its primary purpose is to measure and visualize "Asymmetric Trend Pressure," which helps traders understand the underlying momentum of a market by weighing upward price movements against downward price movements differently.

Core Logic Overview

The indicator operates by scanning historical price data over a specific number of periods to determine how much "pressure" is being exerted in either direction. Unlike standard moving averages that simply smooth out price, this logic categorizes individual price candles into distinct types to calculate a net pressure value.

How the Calculation Works

To arrive at the final reading, the script performs the following steps:

  • Data Categorization: For every candle within a set window (the "Period"), the script checks if the closing price is higher or lower than the opening price.

    • If the price closed higher, it is treated as Upward Pressure.
    • If the price closed lower, it is treated as Downward Pressure.
  • Asymmetric Weighted Sums: The script does not treat all upward moves equally. It uses two different user-defined limits (Periods) to collect data:

    • It sums up the price differences for a specific number of "Up" candles (e.g., the first 14 instances).
    • It simultaneously sums up the price differences for a different number of "Down" candles (e.g., the first 10 instances).
    • By using different limits for up and down moves, the indicator can highlight if one direction is more dominant or persistent than the other over a specific timeframe.
  • Net Pressure Calculation: After calculating the average intensity for both upward and downward pressure, the script subtracts the downward average from the upward average. The resulting figure represents the "Net Pressure."

Visual Output

The script provides three distinct visual components on the chart:

  1. ATP (Main Line): This is the primary indicator line. It shows the net balance of the trend pressure. A positive value suggests bullish pressure, while a negative value suggests bearish pressure.
  2. Up/Down Lines (Optional): Depending on your settings, you can choose to display separate lines for the individual upward and downward pressure components. This allows you to see the "raw" strength of each side before they are subtracted from one another.

Practical Use

Essentially, this tool allows a visitor to see the "tug-of-war" between buyers and sellers. By looking at the net pressure line, you can identify whether the current trend is being driven by strong, consistent moves or if the market is in a state of equilibrium where both sides are exerting equal force.

Price Data Components
12 Views
0 Downloads
0 Favorites
ATP
ÿþ//+------------------------------------------------------------------+

//|                                                          ATP.mq5 |

//|                        Copyright 2018, MetaQuotes Software Corp. |

//|                                                 https://mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2018, MetaQuotes Software Corp."

#property link      "https://mql5.com"

#property version   "1.00"

#property indicator_separate_window

#property indicator_buffers 3

#property indicator_plots   3

//--- plot ATP

#property indicator_label1  "ATP"

#property indicator_type1   DRAW_LINE

#property indicator_color1  clrDodgerBlue

#property indicator_style1  STYLE_SOLID

#property indicator_width1  1

//--- plot UP

#property indicator_label2  "Up"

#property indicator_type2   DRAW_LINE

#property indicator_color2  clrLimeGreen

#property indicator_style2  STYLE_SOLID

#property indicator_width2  1

//--- plot DN

#property indicator_label3  "Down"

#property indicator_type3   DRAW_LINE

#property indicator_color3  clrRed

#property indicator_style3  STYLE_SOLID

#property indicator_width3  1

//--- enums

enum ENUM_INPUT_YES_NO

  {

   INPUT_YES   =  1, // Yes

   INPUT_NO    =  0  // No

  };

//--- input parameters

input uint              InpPeriodUP =  14;         // Period Up

input uint              InpPeriodDN =  10;         // Period Down

input uint              InpPeriod   =  24;         // Period

input ENUM_INPUT_YES_NO InpShowUpDn =  INPUT_NO;   // Show lines Up and Down

//--- indicator buffers

double         BufferATP[];

double         BufferUP[];

double         BufferDN[];

//--- global variables

int            period_up;

int            period_dn;

int            period;

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- setting global variables

   period=int(InpPeriod<1 ? 1 : InpPeriod);

   period_up=int(InpPeriodUP<1 ? 1 : InpPeriodUP);

   period_dn=int(InpPeriodDN<1 ? 1 : InpPeriodDN);

//--- indicator buffers mapping

   SetIndexBuffer(0,BufferATP,INDICATOR_DATA);

   SetIndexBuffer(1,BufferUP,INDICATOR_DATA);

   SetIndexBuffer(2,BufferDN,INDICATOR_DATA);

//--- settings indicators parameters

   IndicatorSetInteger(INDICATOR_DIGITS,Digits());

   IndicatorSetString(INDICATOR_SHORTNAME,"Asymmetric Trend Pressure("+(string)period+")");

//--- setting buffer arrays as timeseries

   ArraySetAsSeries(BufferATP,true);

   ArraySetAsSeries(BufferDN,true);

   ArraySetAsSeries(BufferUP,true);

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {

//--- @>25@:0 =0 <8=8<0;L=>5 :>;8G5AB2> 10@>2 4;O @0AGQB0

   if(rates_total<period) return 0;

//--- @>25@:0 8 @0AGQB :>;8G5AB20 ?@>AG8BK205<KE 10@>2

   int limit=rates_total-prev_calculated;

   if(limit>1)

     {

      limit=rates_total-period-1;

      ArrayInitialize(BufferATP,EMPTY_VALUE);

      ArrayInitialize(BufferDN,EMPTY_VALUE);

      ArrayInitialize(BufferUP,EMPTY_VALUE);

     }

//--- #AB0=>2:0 8=45:A0F88 <0AA82>2 :0: B09<A5@89

   ArraySetAsSeries(open,true);

   ArraySetAsSeries(close,true);

//---  0AGQB 8=48:0B>@0

   for(int i=limit; i>=0; i--)

     {

      double summ_up=0,summ_dn=0;

      int n=0,count_up=0,count_dn=0;

      while(n<period)

        {

         if(close[i+n]>open[i+n] && count_up<period_up)

           {

            count_up++;

            summ_up+=close[i+n]-open[i+n];

           }

         else if(close[i+n]<open[i+n] && count_dn<period_dn)

           {

            count_dn++;

            summ_dn+=open[i+n]-close[i+n];

           }

         n++;

        }

      if(InpShowUpDn)

        {

         BufferUP[i]=summ_up/period_up;

         BufferDN[i]=summ_dn/period_dn;

        }

      else

         BufferUP[i]=BufferDN[i]=EMPTY_VALUE;

      BufferATP[i]=summ_up/period_up-summ_dn/period_dn;

     }

//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

Comments