iTrend_hist
Download scriptOverview
The iTrend indicator is a custom visual tool designed for the MetaTrader platform to help traders identify market direction and momentum. Instead of appearing directly on the price chart, it occupies a separate window at the bottom, providing a clear, simplified histogram that highlights whether the current trend is favoring buyers or sellers.
How the Logic Works
The script functions by analyzing two distinct mathematical components of the market: volatility (via Bollinger Bands) and momentum (via Bull/Bear Power). It combines these two perspectives to generate a binary "signal" represented by colored bars.
1. Trend Positioning (The Blue Component)
The tool first calculates the relationship between the current market price and a set of moving averages known as Bollinger Bands.
- It looks at where the price sits relative to the "middle" of the band, the upper boundary, or the lower boundary (depending on user settings).
- If the price is trading above this calculated threshold, it identifies a positive trend state.
- If the price is below this threshold, it identifies a negative trend state.
2. Momentum Strength (The Red Component)
Simultaneously, the script calculates "Power" metrics. It measures the strength of the buyers (Bulls) versus the sellers (Bears) over a specific period.
- This determines the underlying "pressure" in the market.
- By aggregating these forces, the tool creates a secondary value that indicates whether the momentum is pushing upward or downward.
3. Final Visualization
The script takes these two complex calculations and simplifies them into a clean, readable histogram:
- Blue Histogram: Represents the trend position. It acts as a "True/False" indicator—showing a value of 1 when the price is in a favorable position and 0 when it is not.
- Red Histogram: Represents the momentum shift. It provides a corresponding opposite signal to visualize the strength of the move.
User Customization
The logic is highly flexible, allowing you to refine how the indicator "sees" the market without changing the underlying math:
- Price Types: You can choose which price point the script focuses on (e.g., the Closing price, the High of the day, or the Open).
- Sensitivity: Users can adjust periods and deviations to make the indicator more responsive to quick price swings or more "smoothed out" to capture long-term trends.
Summary for the Trader
Essentially, this tool filters out the "noise" of the market. By looking at the histogram in the bottom window, you are seeing a simplified summary of where the price is sitting relative to its historical average and which side (buyers or sellers) currently holds the most power.
//+------------------------------------------------------------------+
//| iTrend_hist.mq4 |
//| tonyc2a@yahoo.com |
//| |
//+------------------------------------------------------------------+
#property copyright "tonyc2a@yahoo.com"
#property link ""
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_minimum -1
#property indicator_maximum 1
//---- input parameters
extern double iBandsDeviation=2;
extern int iBandsMode0_2=0; // 0-2: MODE_MAIN, MODE_LOW, MODE_HIGH
extern int iBandsPrice0_6=0; // 0-6: PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED
extern int iBandsPeriod=20; // 20
extern int iPowerPrice0_6=0; // 0-6: PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW,PRICE_MEDIAN,PRICE_TYPICAL,PRICE_WEIGHTED
extern int iPowerPeriod=13; // 13
extern int iPriceType0_3=0; // 0-3: PRICE_CLOSE,PRICE_OPEN,PRICE_HIGH,PRICE_LOW
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_HISTOGRAM);
SetIndexBuffer(0,ExtMapBuffer1);
SetIndexLabel(0,"Blue");
SetIndexStyle(1,DRAW_HISTOGRAM);
SetIndexBuffer(1,ExtMapBuffer2);
SetIndexLabel(1,"Red");
//----
IndicatorShortName("iTrend");
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- TODO: add your code here
//+----Processes user parameters-------------------------------------+
double BandsMode,BandsPrice,PowerPrice;
switch(iBandsMode0_2){
case 1: BandsMode=MODE_LOWER;
case 2: BandsMode=MODE_UPPER;
default: BandsMode=MODE_MAIN;
} //end switch
switch(iBandsPrice0_6){
case 1: BandsPrice=PRICE_OPEN;
case 2: BandsPrice=PRICE_HIGH;
case 3: BandsPrice=PRICE_LOW;
case 4: BandsPrice=PRICE_MEDIAN;
case 5: BandsPrice=PRICE_TYPICAL;
case 6: BandsPrice=PRICE_WEIGHTED;
default: BandsPrice=PRICE_CLOSE;
} //end switch
switch(iPowerPrice0_6){
case 1: PowerPrice=PRICE_OPEN;
case 2: PowerPrice=PRICE_HIGH;
case 3: PowerPrice=PRICE_LOW;
case 4: PowerPrice=PRICE_MEDIAN;
case 5: PowerPrice=PRICE_TYPICAL;
case 6: PowerPrice=PRICE_WEIGHTED;
default: PowerPrice=PRICE_CLOSE;
} //end switch
//+------------------------------------------------------------------+
//+----Main Section--------------------------------------------------+
double CurrentPrice, value1, value2, x, y;
for(int i=0;i<=Bars;i++){
switch(iPriceType0_3){
case 1: CurrentPrice=Open[i];
case 2: CurrentPrice=High[i];
case 3: CurrentPrice=Low[i];
default: CurrentPrice=Close[i];
} //end switch
x=CurrentPrice-iBands(Symbol(),Period(),iBandsPeriod,iBandsDeviation,0,BandsPrice,BandsMode,i);
y=-(iBullsPower(Symbol(),Period(),iPowerPeriod,PowerPrice,i) + iBearsPower(Symbol(),Period(),iPowerPeriod,PowerPrice,i));
if(x<0) value1=0;
if(x>0) value1=1;
if(y<0) value2=0;
if(y>0) value2=-1;
ExtMapBuffer1[i]=value1;
ExtMapBuffer2[i]=value2;
} //end for
//+------------------------------------------------------------------+
//ObjectCreate("vl",OBJ_VLINE,WindowFind("iTrend"),Time[-1],Close[0]);
//----
return(0);
}
//+------------------------------------------------------------------+
Comments