Trend_v3
Download scriptThis tool is designed to analyze market trends by calculating and visualizing two distinct types of price movements in a separate window on your trading platform. It focuses on identifying the relationship between current price action and established volatility boundaries, as well as measuring overall market momentum.
Core Functionality
The script processes historical price data to generate two different visual indicators:
1. Volatility Boundary Analysis (Blue Line) This component measures the distance between the current market price and specific "bands." By adjusting the settings, you can choose whether the tool compares the price against the main trend line, the upper limit, or the lower limit of a moving range. It calculates how far the price has deviated from these boundaries, providing a visual representation of overextended movements or breakouts.
2. Momentum and Power Balance (Red Line) The second component tracks the "Power" of the market by aggregating the strength of both buying (bullish) and selling (bearish) pressures. It combines these forces into a single value to show the net momentum of the price action. This helps in identifying whether the prevailing trend is gaining strength or losing steam based on the collective weight of the current market participants.
Customization Options
The logic allows for high flexibility through several user-defined parameters:
- Price Reference: You can choose which specific price point the tool should "watch" (e.g., the exact price at which a candle closed, the highest and lowest points reached during a period, or various weighted averages).
- Sensitivity Settings: Users can modify the look-back periods for both the volatility bands and the power calculations. Increasing these periods will result in a smoother, slower trend analysis, while decreasing them will make the indicator react more quickly to sudden market fluctuations.
- Deviation Control: The tool includes a setting to adjust how far the price must stray from the norm to be significant, allowing for a more tailored view of market volatility.
Summary of Use
By displaying these two metrics side-by-side, the script helps traders see both the "stretch" of the market (how far it has moved relative to its recent history) and its "strength" (the underlying momentum driving that movement). This dual perspective is intended to help identify potential trend exhaustion or the initiation of new market cycles.
//+------------------------------------------------------------------+
//| Trend.mq4 |
//| |
//| Ramdass - Conversion only |
//+------------------------------------------------------------------+
#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