Trend

This tool is designed to help traders visualize and identify market trends by analyzing price action through two distinct mathematical lenses. Rather than showing a single line, it processes historical data to create a dynamic visual representation of market momentum and positioning.

Core Functionality

The script operates by calculating the relationship between current market prices and specific technical thresholds. It focuses on three main components:

1. Price Source Customization The tool allows you to define exactly which part of the price action it should "watch." You can choose to have the logic follow the closing price, the opening price, or even the extreme highs and lows of each candle. This flexibility ensures that the trend identification remains relevant regardless of whether you prefer a conservative or aggressive trading style.

2. Band Analysis (Trend Direction) The logic utilizes a "Bands" calculation to determine the primary trend. By comparing the current price against these calculated bands, the tool determines the distance and direction of price movement. It can be configured to focus on different components of these bands—such as the main average, the upper boundaries, or the lower boundaries—allowing you to see how far the market has stretched away from its "norm."

3. Power Dynamics (Momentum Tracking) Simultaneously, the script calculates the "Power" behind the move. It evaluates both "Bullish" and "Bearish" forces over a specific period of time. By aggregating these forces, the tool provides a clearer picture of who is currently in control of the market—the buyers or the sellers—and the strength with which they are pushing the price.

Visual Representation

The final output is displayed as two separate lines in a dedicated window at the bottom of your chart:

  • The Primary Indicator: Represents the variance between the current price and the established band.
  • The Secondary Indicator: Represents the combined power of market momentum, providing a counter-balance to the trend data.

By observing these two metrics together, users can better understand not just where the market is going, but how much force is behind that movement, helping to identify potential trend continuations or shifts in sentiment.

Indicators Used
Bollinger bands indicatorBears Power indicatorBulls Power indicator
Miscellaneous
Implements a curve of type %1
15 Views
0 Downloads
0 Favorites
Trend
//+------------------------------------------------------------------+
//|                                                        Trend.mq4 |
//|                                                                  |
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
//---- input parameters
extern int Bands_Mode_0_2=0;  // =0-2 MODE_MAIN, MODE_LOW, MODE_HIGH
extern int Power_Price_0_6=0; // =0-6 PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED
extern int Price_Type_0_3=0;  // =0-3 PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW
extern int Bands_Period=20;
extern int Bands_Deviation=2;
extern int Power_Period=13;
extern int CountBars=300;
//---- buffers
double value[];
double value2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//   string short_name;
//---- indicator line
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(0,value);
   SetIndexBuffer(1,value2);
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Trend                                                         |
//+------------------------------------------------------------------+
int start()
  {
   SetIndexDrawBegin(0,Bars-CountBars+Bands_Period+1);
   SetIndexDrawBegin(1,Bars-CountBars+Bands_Period+1);
   int i,CurrentBar,Bands_Mode,counted_bars=IndicatorCounted();
   double Power_Price,CurrentPrice;
//----
   if(Bars<=Bands_Period) return(0);
//---- initial zero
   if(counted_bars<Bands_Period)
   {
      for(i=1;i<=Bands_Period;i++) value[Bars-i]=0.0;
      for(i=1;i<=Bands_Period;i++) value2[Bars-i]=0.0;
   }
//----
   i=CountBars-Bands_Period-1;
   if(counted_bars>=Bands_Period) i=CountBars-counted_bars-1;

     
if (Bands_Mode_0_2==1) Bands_Mode=MODE_LOW;
if (Bands_Mode_0_2==2) Bands_Mode=MODE_HIGH;
if (Bands_Mode_0_2==0) Bands_Mode=MODE_MAIN;

if (Power_Price_0_6==1) Power_Price=PRICE_OPEN;
if (Power_Price_0_6==2) Power_Price=PRICE_HIGH;
if (Power_Price_0_6==3) Power_Price=PRICE_LOW;
if (Power_Price_0_6==4) Power_Price=PRICE_MEDIAN;
if (Power_Price_0_6==5) Power_Price=PRICE_TYPICAL;
if (Power_Price_0_6==6) Power_Price=PRICE_WEIGHTED;
if (Power_Price_0_6==6) Power_Price=PRICE_CLOSE;

for (i=CountBars-1; i>=0; i--)
{  
  if (Price_Type_0_3==1) CurrentPrice=Open[i];
  
  if (Price_Type_0_3==2) CurrentPrice=High[i];

  if (Price_Type_0_3==3) CurrentPrice=Low[i];
  if (Price_Type_0_3==0) CurrentPrice=Close[i]; 
     
  value[i]=CurrentPrice-iBands(NULL,0,Bands_Period,Bands_Deviation,0,Bands_Mode,Power_Price,i);
  value2[i]=-(iBearsPower(NULL,0,Power_Period,Power_Price,i)+iBullsPower(NULL,0,Power_Period,Power_Price,i)); 

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

Comments