PriceTrender
Download scriptThe PriceTrender script is a specialized technical analysis tool designed to help traders visualize market dynamics by comparing actual price data against calculated moving averages across different timeframes.
Core Functionality
At its heart, the indicator works by synchronizing two primary pieces of information: the price action and a smoothed trend line. Unlike standard indicators that only look at the current chart you are viewing, this tool is designed to "reach out" and pull data from other periods, allowing you to see how larger market trends influence the price you see right now.
How it Works
The logic follows a three-step process to generate its visual output:
-
Multi-Timeframe Alignment: The script identifies the specific point in time for every bar on your current chart and translates that exact moment into a corresponding point on a different, user-defined timeframe (such as moving from a 5-minute chart to a 60-minute chart). This ensures that the data being compared is chronologically accurate.
-
Customizable Price Selection: Instead of simply looking at the "closing price," the script allows you to choose exactly which part of the price candle you want to track. You can toggle between various metrics, including:
- The opening and closing prices.
- The highest and lowest points reached.
- Calculated averages like the midpoint (High/Low) or more complex weighted averages (such as the Typical Price or Median Price).
-
Trend Analysis: Simultaneously, the script calculates a Moving Average based on your preferred settings (length and type). By calculating this moving average on the larger timeframe while plotting it alongside the specific price data from the current timeframe, the tool provides a clear visual of whether the short-term price action is aligning with or diverging from the broader market trend.
Visual Output
The results are displayed in a separate window at the bottom of your trading platform as two distinct lines:
- Price Line: Represents the specific price point you selected (e.g., the High or Close) on the primary timeframe.
- Trend Line: Represents the moving average from the higher timeframe.
By observing the relationship between these two lines, traders can more easily identify whether the current price momentum is supported by the larger trend or if a potential reversal may be occurring.
//+------------------------------------------------------------------+
//| PriceTrender.mq4 |
//| Kalenzo |
//| bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link "bartlomiej.gorski@gmail.com"
#property indicator_buffers 2
#property indicator_color1 DodgerBlue
#property indicator_color2 Gold
extern int TimeFrame = 60,
Price = 0,
MaType = 0,
MaPrice = 0,
MaLength = 24;
double price[],trend[];
#property indicator_separate_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
SetIndexBuffer(0,price);
SetIndexBuffer(1,trend);
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
SetIndexStyle(1,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,MaLength,0,MaType,MaPrice,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