PriceTrender2
Download scriptThis tool is designed to provide traders with a visual representation of market movement by smoothing out price data and identifying underlying trends. It operates by analyzing specific price points and comparing them against moving averages to help clarify the direction of the market.
Core Functionality
The script functions by processing historical data across a user-defined timeframe. It looks at the "price" of an asset and calculates three distinct visual components simultaneously:
- Price Reference: The tool first identifies which specific type of price point you want to track. Depending on your settings, it can focus on the closing price, opening price, the highest or lowest points reached during a period, or various mathematical averages (such as the midpoint between highs and lows).
- Primary Trend Analysis: It calculates a long-term moving average based on a specific number of historical periods. This helps filter out minor "market noise" to show the broader direction in which the price is heading.
- Secondary Trend Analysis: It simultaneously calculates a shorter-term moving average. By comparing this faster-moving trend against the longer one, the tool helps highlight shifts in momentum and potential changes in market behavior.
How it Works for the User
When you apply this script to your chart, it performs the following logic automatically:
- Time Synchronization: The tool intelligently aligns the data from your current chart with the specific timeframe you have chosen in the settings, ensuring that the trend lines remain accurate even if you switch views.
- Dynamic Calculation: It loops through the available price history to calculate the values for all three components (Price, Trend 1, and Trend 2) for every bar on your screen.
- Visual Output: The result is a clear, three-line visual display in a separate window. This allows you to see the relationship between the actual market price and the two different moving averages at a glance.
By observing how these three lines interact—specifically how the short-term trend reacts to the long-term trend relative to the price—you can gain a clearer perspective on market momentum and potential trend reversals.
//+------------------------------------------------------------------+
//| PriceTrender2.mq4 |
//| Kalenzo |
//| bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link "bartlomiej.gorski@gmail.com"
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 Gold
#property indicator_color3 Lime
extern int TimeFrame = 60,
Price = 0,
Ma1Type = 0,
Ma1Price = 0,
Ma1Length = 24,
Ma2Type = 0,
Ma2Price = 0,
Ma2Length = 5;
double price[],trend[],trend2[];
#property indicator_separate_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0,price);
SetIndexBuffer(1,trend);
SetIndexBuffer(2,trend2);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1);
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//----
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, bigshift;
int counted_bars=IndicatorCounted();
//----
if (counted_bars<0) return(-1);
if (counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
for (int i=limit; i>=0; i--)
{
bigshift = iBarShift(Symbol(),TimeFrame,Time[i]);
price[i] = getPrice(bigshift);
trend[i] = iMA(Symbol(),TimeFrame,Ma1Length,0,Ma1Type,Ma1Price,bigshift);
trend2[i] = iMA(Symbol(),TimeFrame,Ma2Length,0,Ma2Type,Ma2Price,bigshift);
}
//----
return(0);
}
//+------------------------------------------------------------------+
double getPrice(int shift)
{
switch(Price)
{
case 0 : return ( iClose(Symbol(),TimeFrame,shift) );
case 1 : return (iOpen(Symbol(),TimeFrame,shift));
case 2 : return (iHigh(Symbol(),TimeFrame,shift));
case 3 : return (iLow(Symbol(),TimeFrame,shift));
case 4 : return ((iLow(Symbol(),TimeFrame,shift)+iHigh(Symbol(),TimeFrame,shift))/2);
case 5 : return ((iClose(Symbol(),TimeFrame,shift)+iLow(Symbol(),TimeFrame,shift)+iHigh(Symbol(),TimeFrame,shift))/3);
case 6 : return ((iOpen(Symbol(),TimeFrame,shift)+iClose(Symbol(),TimeFrame,shift)+iLow(Symbol(),TimeFrame,shift)+iHigh(Symbol(),TimeFrame,shift))/4);
}
}
Comments