PriceTrend_001
Download scriptThe PriceTrender2 tool is designed to provide a visual representation of market trends by analyzing price data across different timeframes. Its primary purpose is to help traders identify the underlying direction of the market by smoothing out short-term "noise" and highlighting broader movements.
Core Functionality
The script operates based on three main components that are displayed as separate lines on your chart:
1. Price Source Selection The tool allows you to choose exactly which part of the price action you want to monitor. Instead of being limited to just the closing price, you can configure it to track:
- The standard Opening, Closing, High, or Low prices.
- Mathematical averages of these points (such as a midpoint between the high and low, or a full average of all four primary price points).
2. Multi-Timeframe Analysis One of the key features of this script is its ability to "look ahead" into different timeframes. It synchronizes data from a higher time period (like an hourly chart) onto your current view. This allows you to see the trend of a larger market cycle even if you are currently trading on a much faster, smaller timeframe.
3. Dual Moving Average Trend Tracking The script calculates two distinct moving averages simultaneously to define the trend:
- Primary Trend: A longer-term average (defaulting to 21 periods) that identifies the general direction of the market.
- Secondary Trend: A shorter-term average (defaulting to 8 periods) that captures more immediate price shifts.
How it Works in Practice
The logic follows a continuous loop: for every candle on your current chart, the script automatically calculates the specific price point you selected from the higher timeframe and then applies the two moving averages to that data.
By viewing these three lines together, traders can observe how the current price interacts with the broader market trend. When these lines align or cross, it provides a visual cue regarding whether the market is gaining momentum, consolidating, or potentially reversing.
//+------------------------------------------------------------------+
//| 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 Crimson
extern int TimeFrame = 60,
Price = 0,
Ma1Type = 0,
Ma1Price = 0,
Ma1Length = 21,
Ma2Type = 0,
Ma2Price = 0,
Ma2Length = 8;
double price[],trend[],trend2[];
#property indicator_separate_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
IndicatorShortName("PT");
//---- 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