market profile_v1
Download scriptThis script is designed to visualize market activity by identifying and mapping out historical price action patterns, specifically focusing on "Market Profiles." It provides traders with a visual representation of where price has spent the most time during specific trading periods.
Core Functionality
Timeframe Compatibility The tool is designed to operate on intraday charts, specifically functioning within the 5-minute to 60-minute timeframe range. If applied to larger timeframes (like daily or weekly), the logic will not execute.
Historical Data Scanning The script automatically scans the price history starting from a user-defined date. It processes the data backward to identify distinct trading sessions. Once it identifies a completed period (such as a full day of trading), it analyzes the high and low price points reached during that time.
Price Density Analysis The primary logic involves scanning every price level between the daily high and the daily low. For each specific price point, the script calculates how many times the market traded at or through that level. This helps identify "Value Areas"—the price zones where the most transaction activity occurred.
Regional Session Breakdown A unique feature of this logic is its ability to categorize trading activity based on global time zones. It separates the volume of trades into three distinct regional blocks:
- Asia
- Europe
- America
The script tracks these sessions individually, allowing it to distinguish between the behavior of different global markets as they open and close throughout the day.
Visual Mapping Instead of just providing numbers, the script draws physical shapes on your chart:
- Volume Blocks: It creates visual rectangles for each regional session (Asia, Europe, and America), showing how much time/volume was spent at specific prices during those regions.
- The Median Point: The script calculates the "Mediana"—the price level with the highest concentration of activity—and marks it clearly on the chart to highlight where the market found the most balance or equilibrium.
Summary for the Trader
Essentially, this tool takes raw, chaotic price data and organizes it into a structured map. It tells you not just where the price went, but where the price stayed. By visualizing these "footprints" of regional trading sessions and identifying the median value, it helps traders see the balance between supply and demand across different global markets.
/*-----------------------------+
| |
| Shared by www.Aptrafx.com |
| |
+------------------------------*/
//+------------------------------------------------------------------+
//| MarketProfile.mq4 |
//| Copyright © 2006, Viatcheslav Suvorov|
//+------------------------------------------------------------------+
#property copyright "Viatcheslav Suvorov"
#property indicator_chart_window
extern datetime StartDate = D'';
extern bool lastdayStart = true;
extern int CountProfile = 2;
int fontsize=10;
int i,j;
double LastHigh,LastLow,CurPos;
bool signal;
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
ObjectsDeleteAll(0,OBJ_RECTANGLE);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
string short_name;
//---- name for DataWindow and indicator subwindow label
short_name="MarketProfile";
IndicatorShortName(short_name);
SetIndexLabel(0,short_name);
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
deinit();
double onetick;
double Mediana=0;
int MaxSize=0;
int MySize=0;
int MySizeEuropa=0;
int MySizeAzia=0;
int MySizeAmerica=0;
int BACK=0;
if (lastdayStart) StartDate=Time[0];
int x=Period();
if (x>60) return(-1);
if (x<5) return(-1);
BACK=0;
while (TimeDayOfYear(Time[BACK])>TimeDayOfYear(StartDate) || TimeYear(Time[BACK])!=TimeYear(StartDate) && (BACK<Bars)) {
BACK++;
if (BACK>=Bars) return(0);
}//while
onetick = 1/(MathPow(10,Digits));
i=BACK;
////
int cycles;
for (cycles=CountProfile;cycles>0;cycles--) {
signal=false;
LastHigh=High[i];
LastLow=Low[i];
while (!signal)
{
//if (i+1==Bars) signal=true;
if (High[i+1]>LastHigh) LastHigh=High[i+1];
if (Low[i+1]<LastLow) LastLow=Low[i+1];
MaxSize=0;
MySize=0;
if (TimeDay(Time[i])!=TimeDay(Time[i+1]))
{
signal=true;
CurPos=LastLow;
while (CurPos<=LastHigh){
MySizeAzia=0;
MySizeEuropa=0;
MySizeAmerica=0;
for (j=i;j>=BACK;j--) {
if ((High[j]>=CurPos) && (Low[j]<=CurPos)) {
MySize++;
if (TimeHour(Time[j])>=13) MySizeAmerica++; else
if ((TimeHour(Time[j])>=8) && (TimeHour(Time[j])<13)) MySizeEuropa++; else
MySizeAzia++;
}//if
}//for
if (MySizeAzia+MySizeEuropa+MySizeAmerica>MaxSize){
MaxSize=MySizeAzia+MySizeEuropa+MySizeAmerica;
Mediana=CurPos;
}
if (i-MySizeAzia>=0)
if(ObjectFind("rec"+"Azia"+TimeToStr(Time[i],TIME_DATE)+CurPos) == -1 && MySizeAzia!=0) {
ObjectCreate("rec"+"Azia"+TimeToStr(Time[i],TIME_DATE)+CurPos, OBJ_RECTANGLE, 0, Time[i], CurPos,Time[i-MySizeAzia],CurPos+onetick);
ObjectSet("rec"+"Azia"+TimeToStr(Time[i],TIME_DATE)+CurPos, OBJPROP_COLOR, Blue);
}//if
if(ObjectFind("rec"+"Europa"+TimeToStr(Time[i],TIME_DATE)+CurPos) == -1 && MySizeEuropa!=0) {
ObjectCreate("rec"+"Europa"+TimeToStr(Time[i],TIME_DATE)+CurPos, OBJ_RECTANGLE, 0, Time[i-MySizeAzia], CurPos,Time[i-MySizeAzia-MySizeEuropa],CurPos+onetick);
ObjectSet("rec"+"Europa"+TimeToStr(Time[i],TIME_DATE)+CurPos, OBJPROP_COLOR, Blue);
}//if
if(ObjectFind("rec"+"America"+TimeToStr(Time[i],TIME_DATE)+CurPos) == -1 && MySizeAmerica!=0) {
ObjectCreate("rec"+"America"+TimeToStr(Time[i],TIME_DATE)+CurPos, OBJ_RECTANGLE, 0, Time[i-MySizeAzia-MySizeEuropa], CurPos,Time[i-MySizeAzia-MySizeEuropa-MySizeAmerica],CurPos+onetick);
ObjectSet("rec"+"America"+TimeToStr(Time[i],TIME_DATE)+CurPos, OBJPROP_COLOR, Blue);
}//if
CurPos=CurPos+onetick;
}//while
ObjectCreate("mediana"+TimeToStr(Time[i],TIME_DATE), OBJ_RECTANGLE, 0, Time[i], Mediana,Time[i+10],Mediana+onetick);
ObjectSet("mediana"+TimeToStr(Time[i],TIME_DATE), OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("mediana"+TimeToStr(Time[i],TIME_DATE), OBJPROP_COLOR,White);
BACK=i+1;
}//if
i++;
if (i>=Bars) return(0);
}//while
}//for
//----
return(0);
}
//+------------------------------------------------------------------+
Comments