VolumesHist
Download scriptThis tool is designed to provide a visual representation of trading activity by analyzing historical volume data across a specific timeframe. Rather than showing standard price action, it focuses on identifying "Volume Profiles," which help traders see at which specific price levels the most significant buying and selling activity has occurred.
How the Logic Works
1. Data Collection and Analysis The script begins by looking back at a large historical window of data (defined by the user in minutes). It scans this period to identify the highest and lowest prices reached. By establishing these boundaries, the tool creates a "grid" of price levels.
2. Volume Distribution Instead of just looking at the total volume for a day or an hour, the script calculates how much volume occurred at every specific price point within that high-to-low range. It essentially "stacks" the volume: if many trades happened at a certain price, that level is assigned a higher value; if very few trades happened there, the value remains low.
3. Dynamic Scaling To ensure the visual information is readable and fits perfectly on your chart, the script automatically calculates the maximum volume recorded during the period. It then scales all other volume levels proportionally against this maximum. This ensures that the most active price zones stand out clearly without overwhelming the display.
4. Visual Representation The final result is rendered as a histogram-style background on your chart. Each bar represents a price level, and its width is determined by the amount of trading volume at that specific spot.
Key Features for the User
- Historical Depth: It processes thousands of minutes of data to ensure the profile reflects significant historical trends rather than just recent fluctuations.
- Visual Clarity: The bars are drawn in the background of the chart, allowing you to see "support" and "resistance" zones (areas of high activity) without cluttering your primary price candles.
- Automatic Refresh: The tool is designed to update its calculations based on new data, ensuring that as time progresses, the volume distribution remains relevant to current market conditions.
//+------------------------------------------------------------------+
//| Volumes Hist.mq4 |
//| Copyright © Vadim Shumilov (DrShumiloff) |
//| shumiloff@mail.ru |
//| ICQ 84796634 |
//+------------------------------------------------------------------+
#property copyright "Vadim Shumilov (DrShumiloff)"
#property link "shumiloff@mail.ru"
//----
#property indicator_chart_window
extern int MinutesCount = 5000; // 3000 - 10000 ;
extern int Amplitude = 20; // 10 .. 100
extern int RefreshPeriod = 1; // 1 .. 60
extern color HistColor = SteelBlue;
extern double PricePoint = 0.0002;
// For the next versions
// extern int Method = 0; // 0 - SMA, 1 - EMA, 2 - SMMA, 3 - LWMA, 4 - LRMA
// extern int VolumePeriod = 21;
double Hist[];
datetime OpenTime = 0;
int init()
{
return(0);
}
int deinit()
{
DeleteObjects();
return(0);
}
int DeleteObjects()
{
for (int i = 0; i< 3000; i++) ObjectDelete("VH"+i);
}
int DrawLine(int n, double price, int vol, int max)
{
vol = MathRound(Amplitude * vol / max );
if (vol > 0)
{
int first = WindowFirstVisibleBar();
datetime dt1 = iTime(NULL, Period(), first);
datetime dt2 = iTime(NULL, Period(), first-vol);
ObjectCreate("VH"+n, OBJ_RECTANGLE, 0, dt1, price, dt2, price+PricePoint);
ObjectSet("VH"+n, OBJPROP_STYLE, DRAW_HISTOGRAM);
ObjectSet("VH"+n, OBJPROP_COLOR, HistColor);
ObjectSet("VH"+n, OBJPROP_BACK, true);
}
return (0);
}
int start()
{
if (OpenTime != iOpen(Symbol(), PERIOD_M1, 0))
{
OpenTime = iOpen(Symbol(), PERIOD_M1, 0);
int n, MaxVolume;
double max = iHigh(Symbol(), PERIOD_M1, iHighest(Symbol(), PERIOD_M1, MODE_HIGH, MinutesCount, 0));
double min = iLow(Symbol(), PERIOD_M1, iLowest(Symbol(), PERIOD_M1, MODE_LOW, MinutesCount, 0));
int items = MathRound((max - min) / PricePoint);
if (max == 0)
{
Alert("There is no minutes data. Please download M1.");
return (0);
}
ArrayResize(Hist, items);
ArrayInitialize(Hist, 0);
for (int i = 1; i <= MinutesCount; i++)
{
n = MathRound((iClose(Symbol(), PERIOD_M1, i) - min) / PricePoint);
Hist[n] += iVolume(Symbol(), PERIOD_M1, i);
}
MaxVolume = Hist[ArrayMaximum(Hist)];
DeleteObjects();
for (i = 0; i <= items; i++)
{
DrawLine(i, min + i*PricePoint, Hist[i], MaxVolume);
}
}
return(0);
}
Comments