VolumesHist2.3
Download scriptThis tool is designed to visualize historical trading activity by reconstructing a "Volume Profile" based on specific price movements over a set period of time. Instead of simply looking at how much volume was traded in total, the logic aims to identify exactly at which price levels that volume occurred.
How the Logic Works:
1. Defining the Analysis Window The script looks back at a specific number of historical candles (the timeframe defined by the user). It first identifies the highest and lowest prices reached during this period to create a vertical boundaries for the analysis. This ensures the resulting data is contained within a relevant price range.
2. Analyzing Candle Dynamics Rather than treating every candle as a uniform block, the logic breaks down each individual candle into its high, low, open, and close points. It specifically looks at whether a candle was "bullish" (closing higher than it opened) or "bearish" (closing lower than it opened).
3. Volume Distribution Calculation For every candle within the period, the script calculates how much of that candle's volume belongs to specific price zones. It distributes the volume proportionally:
- If a candle moved from Price A to Price B, the logic assigns a portion of that candle's total volume to every price point between A and B.
- By doing this for every single candle in the lookback period, it builds a cumulative "history" of where the most trading activity actually took place.
4. Scaling and Visualization Once the script has calculated the total volume for every price level, it identifies the highest volume point (the "Point of Control"). It then scales all other data points relative to this maximum.
The final output is rendered on your chart as a horizontal histogram (volume profile). This allows you to see "zones" of high interest—areas where price spent significant time and volume was concentrated—helping you identify potential support, resistance, or areas of historical equilibrium.
// Îáú¸ì ðàñ÷èòûâàòñÿ îò Low äî High. Ñ÷èòàåòñÿ ÷òî â "õâîñòèêàõ" ñîñðåäîòî÷åí äâîéíîé îáú¸ì (òóäà-ñþäà)
#property indicator_chart_window
extern int Period_ind = 240; // 3000 - 10000
int Amplitude = 100;
double Hist[];
datetime OpenTime = 0;
datetime CountTime = 0;
int init()
{
ObjectCreate("Line_Goriz", OBJ_VLINE, 0, Time[Period_ind], 0);
ObjectSet("Line_Goriz", OBJPROP_COLOR, Red);
return(0);
}
int start()
{
if (OpenTime != Open[0])
{
ObjectSet( "Line_Goriz", OBJPROP_TIME1, Time[Period_ind]);
OpenTime = Open[0];
double max = High[iHighest( NULL , 0, MODE_HIGH, Period_ind, 0)];
double min = Low[ iLowest( NULL , 0, MODE_LOW, Period_ind, 0)];
int items = MathRound((max - min) / Point);
ArrayResize(Hist, items);
ArrayInitialize(Hist, 0);
int n;
for (int i = 1; i <= Period_ind; i++)
{
double t1 = Low[i], t2 = Open[i], t3 = Close[i], t4 = High[i];
if (t2 > t3) {t3 = Open[i]; t2 = Close[i];}
double znamen = 2*(t4 - t1) - t3 + t2;
if (znamen != 0.0)
{
for (double Price_i = t1; Price_i <= t4; Price_i += Point)
{
n = MathRound((Price_i - min) / Point);
if (t1 <= Price_i && Price_i < t2)
{
Hist[n] += MathRound(Volume[i]*2*(t2-t1)/znamen);
}
if (t2 <= Price_i && Price_i <= t3)
{
Hist[n] += MathRound(Volume[i]*(t3-t2)/znamen);
}
if (t3 < Price_i && Price_i <= t4)
{
Hist[n] += MathRound(Volume[i]*2*(t4-t3)/znamen);
}
}
}
}
for (i = 0; i < 3000; i++) ObjectDelete("VH"+i);
int MaxVolume = Hist[ArrayMaximum(Hist)];
for (i = 0; i <= items; i++)
{
if (MaxVolume != 0) Hist[i] = MathRound(Amplitude * Hist[i] / MaxVolume );
if (Hist[i] > 0)
{
int time_i = Period_ind-Hist[i];
ObjectCreate("VH"+i, OBJ_RECTANGLE, 0, Time[Period_ind], min + i*Point, Time[time_i], min + (i+1)*Point);
ObjectSet("VH"+i, OBJPROP_STYLE, DRAW_HISTOGRAM);
ObjectSet("VH"+i, OBJPROP_COLOR, Red);
ObjectSet("VH"+i, OBJPROP_BACK, true);
}
}
}
return(0);
}
int deinit()
{
for (int i = 0; i < 3000; i++) ObjectDelete("VH"+i);
ObjectDelete("Line_Goriz");
return(0);
}
Comments