MTF_PriceChannel3

Download script
MTF_PriceChannel3

This tool is designed to provide traders with a visual representation of price boundaries based on historical data from different timeframes. Essentially, it allows you to view the "big picture" market structure directly on your current chart, helping you identify support and resistance levels without having to switch between different tabs or windows.

Core Functionality

The script identifies three distinct price lines on your chart:

  • Upper Channel: Represents the highest price reached within a specific lookback period.
  • Lower Channel: Represents the lowest price reached within that same period.
  • Middle Channel: Calculates the exact midpoint between the upper and lower boundaries, serving as a neutral equilibrium line.

How the Logic Works

The script operates using a "Multi-Timeframe" logic. Instead of just looking at the current candles you see on your screen, it pulls data from a higher timeframe (such as Daily, Weekly, or Hourly charts) based on your settings.

  1. Data Synchronization: The tool looks at the higher timeframe data and aligns it with the current chart's timeline. It ensures that the price levels displayed are accurate to the specific point in time you are currently viewing.
  2. Range Scanning: You can define a "Range" (the number of candles to look back). The script scans this many candles on the higher timeframe to find the absolute highest and lowest points.
  3. Dynamic Calculation: As new price data arrives, the script constantly updates these three lines. If the market creates a new high or low within your specified range, the channels shift automatically to reflect the new reality.
  4. Visual Filtering: To keep your chart clean, the logic includes a safeguard: it will only display the information if the timeframe you've selected is larger than (or equal to) the one you are currently viewing. This prevents "noisy" data from smaller timeframes from cluttering a larger perspective.

Practical Application

By using this script, you can see where the "major" market players have established price boundaries. For example, even if you are trading on a small 15-minute chart, this tool can project the boundaries of the Daily range, allowing you to see how close the current price is to significant historical highs and lows.

Miscellaneous
Implements a curve of type %1
10 Views
0 Downloads
0 Favorites
MTF_PriceChannel3
//+------------------------------------------------------------------+
//| PriceChannel3_mtf.mq4                                                   |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 DodgerBlue
#property indicator_color3 DodgerBlue

extern int Range=6;
extern int TimeFrame=1440;
extern int Shift=0;

double UpBuffer[];
double DnBuffer[];
double MdBuffer[];

int i;  //ñ÷åò÷èê
string PeriodName;  //õðàíèò èìÿ òàéìôðåéìà

int init()
{
string short_name;

SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,UpBuffer);
 SetIndexShift(0, Shift);
SetIndexLabel(0,"Up Channel ("+Range+")");
SetIndexDrawBegin(0,0);

SetIndexStyle(1,DRAW_LINE);
SetIndexBuffer(1,DnBuffer);
 SetIndexShift(1, Shift);
SetIndexLabel(1,"Down Channel ("+Range+")");
SetIndexDrawBegin(1,0);

SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,MdBuffer);
 SetIndexShift(2, Shift);
SetIndexLabel(2,"Middle Channel");
SetIndexDrawBegin(2,0);

IndicatorShortName(short_name);

switch(TimeFrame) // ïðèñâîåíèå çíà÷åíèÿ TimeFrame â çàâèñèìîñòè îò âûáðàííîãî â ïàðàìåòðàõ
  {
  case 1    : TimeFrame=PERIOD_M1;  break; //â òîì æå ïîðÿäêå, ÷òî è êíîïêè íà ïàíåëè
  case 5    : TimeFrame=PERIOD_M5;  break;
  case 15   : TimeFrame=PERIOD_M15; break;
  case 30   : TimeFrame=PERIOD_M30; break;
  case 60   : TimeFrame=PERIOD_H1;  break;
  case 240  : TimeFrame=PERIOD_H4;  break;
  case 1440 : TimeFrame=PERIOD_D1;  break;
  case 10080: TimeFrame=PERIOD_W1;  break;
  case 43200: TimeFrame=PERIOD_MN1; break;
  default   : TimeFrame=Period();   break;
  }

switch(TimeFrame) // ïîëó÷åíèå èìåíè òàéìôðåéìà
  {
  case PERIOD_M1    : PeriodName="M1";  break;
  case PERIOD_M5    : PeriodName="M5";  break;
  case PERIOD_M15   : PeriodName="M15"; break;
  case PERIOD_M30   : PeriodName="M30"; break;
  case PERIOD_H1    : PeriodName="H1";  break;
  case PERIOD_H4    : PeriodName="H4";  break;
  case PERIOD_D1    : PeriodName="D1";  break;
  case PERIOD_W1    : PeriodName="W1";  break;
  case PERIOD_MN1   : PeriodName="MN1"; break;
  }
short_name="PriceChannel("+PeriodName+","+Range+","+Shift+")";
return(0);
}

int start()
{
int i,counted_bars=IndicatorCounted();
//---- initial zero
   if(counted_bars<1)
      for(i=1;i<Bars;i++)
      {
         DnBuffer[i]=0.0;
         UpBuffer[i]=0.0;
         MdBuffer[i]=0.0;      
      }
//----
datetime TimeArray[];
double LowArray[],HighArray[];
int y=0;  //ñ÷åò÷èê áàðîâ äðóãîãî òàéìôðåéìà

if (TimeFrame<Period()) //íåëüçÿ ïðîðèñîâàòü èíäèêàòîð ìåíüøåãî òàéìôðåéìà íà áîëüøåì
  {
  SetIndexDrawBegin(0,Bars);  //î÷èñòêà îò ìóñîðà
  SetIndexDrawBegin(1,Bars);
  SetIndexDrawBegin(2,Bars);
  return(0);
  }
//ïîëó÷åíèå âðåìåíè íà÷àëà êàæäîãî áàðà ñ äðóãîãî òàéìôðåéìà
ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame);
//ïîëó÷åíèå âñåõ Low îòòóäà æå
ArrayCopySeries(LowArray,MODE_LOW,Symbol(),TimeFrame);
//àíàëîãè÷íî High
ArrayCopySeries(HighArray,MODE_HIGH,Symbol(),TimeFrame);

for(i=0,y=0;i<Bars-counted_bars;i++)
  {
  //åñëè âðåìÿ íà÷àëà áàðà íàøåãî òàéìôðåéìà ìåíüøå âðåìåíè íà÷àëà áàðà äðóãîãî òàéìôðåéìà, 
  //òî ïåðåõîäèì ê ñëåäóþùåìó áàðó íà äðóãîì òàéìôðåéìå (îòñ÷åò â îáðàòíîì ïîðÿäêå)
  if (Time[i]<TimeArray[y]) y++;
  //|âûáèðàåò áàð ñ ìèíèìàëüíûì/ìàêñèìàëüíûì çíà÷åíèåì ñ äðóãîãî òàéìôðåéìà,
  DnBuffer[i]=LowArray[Lowest(NULL,TimeFrame,MODE_LOW,Range,y)];
  //|è ïî íîìåðó áàðà âûòàñêèâàåò ñîîòâåòñòâóþùåå çíà÷åíèå èç ìàññèâîâ
  UpBuffer[i]=HighArray[Highest(NULL,TimeFrame,MODE_HIGH,Range,y)];
  //|LowArray è HighArray
  MdBuffer[i]=(UpBuffer[i]+DnBuffer[i])/2;
  }
Comment("PriceChannel on timeframe ", PeriodName, " with the period ", Range);
return(0);
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- 
   Comment("");
//----
   return(0);
  }

Comments