PriceTrender2KbarShift_sw
Download scriptThe PriceTrender2 tool is designed to provide traders with a multi-layered visual analysis of market trends by synthesizing data from different timeframes. Rather than looking at the immediate, noisy fluctuations of the current price, this script focuses on smoothing out market movements to identify the underlying direction of the asset.
Core Functionality
The primary logic of the script revolves around three distinct data streams plotted in a separate window. It identifies these by pulling information from a higher timeframe (customizable by the user) and projecting it onto the current chart. This allows you to see "the big picture" without losing sight of your current trading session.
How the Logic Works:
-
Dynamic Price Selection: The tool is highly flexible in how it defines "price." Instead of only looking at where a candle closed, the logic allows you to choose between several different data points, including the opening price, the highest peak, the lowest valley, or various mathematical averages of these four points (such as the median or mean price).
-
Dual Moving Average Analysis: The script calculates two separate moving averages simultaneously. By using two different lengths—one typically longer and one shorter—the tool helps visualize momentum:
- Primary Trend: A longer-term average that establishes the broad direction of the market.
- Secondary Trend: A shorter-term average that captures more immediate price shifts.
-
Timeframe Synchronization: A key feature of this script is its ability to "shift" data. It looks back at a specific timeframe (for example, hourly data) and maps those trends onto your current chart. This ensures that the lines you see are representative of significant structural moves rather than minor, insignificant price ticks.
Visual Summary
By combining these three elements—the selected price point, the long-term trend, and the short-term trend—the indicator provides a cohesive visual map. It helps traders distinguish between temporary market "noise" and sustained momentum, making it easier to identify when a trend is strengthening, weakening, 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 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;
limit=MathMax(limit,TimeFrame/Period());
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