Author: Copyright � 2004, MetaQuotes Software Corp.
i_Trend_v4

This tool is designed to analyze market trends by calculating and displaying two distinct visual components in a separate window below your main price chart. It aims to provide clarity on momentum and price positioning by processing historical data into readable lines.

Core Logic Overview

The script functions by examining two different sets of mathematical calculations simultaneously:

1. Price Band Positioning The first component focuses on where the current market price sits in relation to specific "Bands." Instead of just looking at a single price point, it evaluates how far the price has deviated from an average range.

  • Customization: You can choose whether the script tracks the main body of the price movement, the highs, or the lows.
  • Visual Output: This generates a line that helps represent the "stretch" or position of the current market relative to its recent history.

2. Power Momentum Dynamics The second component measures "Power"—specifically identifying the strength of "Bulls" (buyers) versus "Bears" (sellers).

  • Dynamic Calculation: It looks at specific price types (such as Open, High, Low, or Close) over a set period to determine which side of the market has more aggressive momentum.
  • Visual Output: By combining these power metrics into a single negative calculation, it produces a visual representation of the prevailing market force.

How It Works for the User

  • Data Processing: The script scans through a large volume of historical bars (up to 20,000) to ensure that the trends it identifies are based on significant data rather than just a few moments of price action.
  • Visual Representation: The result is displayed as two distinct lines—one in Green and one in Red. These lines allow you to see at a glance how price bands and market power are interacting.
  • Flexibility: Because the logic allows for different "Modes" (such as choosing between Median, Typical, or Weighted prices), the tool can be adjusted to suit different trading styles, whether you prefer focusing on extreme price points or the general average of the market.

In summary, this script acts as a dual-filter: one filter tracks the position of the price within its current range, while the other tracks the intensity of the movement driving that price.

Indicators Used
Bollinger bands indicatorBears Power indicatorBulls Power indicator
Miscellaneous
Implements a curve of type %1
11 Views
0 Downloads
0 Favorites
i_Trend_v4
//+------------------------------------------------------------------+
//|                                                       iTrend.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2004, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 LimeGreen
#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=20000;
//---- 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=Bars-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