PriceTrender2KbarShift_sw_v1

Download script
Author: Kalenzo
PriceTrender2KbarShift_sw_v1

This tool is designed to provide a visual representation of market trends by analyzing price data across different timeframes. Instead of looking at the standard price action on your current chart, it "reaches out" to a higher timeframe to gather more significant data, helping to filter out minor market noise and highlight broader movements.

Core Logic and Functionality

Multi-Timeframe Data Integration The primary strength of this script is its ability to bridge different time periods. It automatically calculates the corresponding historical data from a user-defined timeframe (such as an hourly view) and maps it onto your current viewing chart. This allows you to see how the "big picture" is moving while you are focusing on smaller, immediate price fluctuations.

Customizable Price Reference The script does not simply rely on one type of price. It offers a flexible system where you can choose exactly which part of a candle's movement should be used for its calculations. You can choose to base the logic on:

  • Specific points like the Opening, Closing, High, or Low prices.
  • Average values, such as the midpoint of a candle or more complex averages involving all four price points (Open, High, Low, and Close).

Dual Trend Smoothing To make the data easier to interpret, the script processes the selected price data through two different moving averages simultaneously.

  1. Primary Trend: A longer-term calculation that identifies the general direction of the market.
  2. Secondary Trend: A shorter-term calculation that reacts more quickly to recent changes.

Visual Output

By comparing these three distinct lines—the processed price and the two different moving averages—users can better identify trend reversals, momentum shifts, and periods of consolidation. Because the script operates in a separate window, it provides a clean, dedicated space for trend analysis that doesn't clutter your main trading candles.

Price Data Components
Series array that contains close prices for each barSeries array that contains open prices of each barSeries array that contains the highest prices of each barSeries array that contains the lowest prices of each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
PriceTrender2KbarShift_sw_v1
//+------------------------------------------------------------------+
//|                                                PriceTrender2.mq4 |
//|                                                          Kalenzo |
//|                                      bartlomiej.gorski@gmail.com |
//+------------------------------------------------------------------+
#property copyright "Kalenzo"
#property link      "bartlomiej.gorski@gmail.com"
#property indicator_buffers 3
#property indicator_separate_window
#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[];
//+------------------------------------------------------------------+
//| 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