dailypoc_valuearea.mq5
Сообщите нам, если считаете, что материал размещён без разрешения.
Сообщить о материале
Обращение по товару «dailypoc_valuearea.mq5» отправится на рассмотрение. Укажите контакт для ответа и опишите причину.
О программе
DailyPOC_ValueArea — индикатор MetaTrader 5, который рассчитывает и отображает уровни Point of Control (POC), Value Area High (VAH) и Value Area Low (VAL) для каждого торгового дня. На основе объёма баров за день строится профиль, из которого определяется POC (строка с наибольшим объёмом) и зона Value Area, охватывающая заданный процент дневного объёма. Результаты отображаются в виде горизонтальных линий на графике цены.
Индикатор поддерживает настройку количества отображаемых дней, часа начала торговой сессии, высоты профиля в пунктах и процента Value Area. Доступен выбор типа объёма (тиковый или реальный), а также возможность заливки зоны Value Area прямоугольником, продления линий текущего дня вправо и отображения ценовых меток.
Логика работы: при поступлении новых баров объёмы распределяются по ценовым корзинам профиля, затем вычисляются POC и границы Value Area. Линии и прямоугольники создаются как графические объекты на графике. При формировании нового дня предыдущий завершается и отрисовывается без продления, а текущий день отображается с учётом формирующегося бара.
Настройки программы
| Настройка | Описание |
|---|---|
| InpDays | Количество дней для отображения (1 или более) |
| InpSessionStartHour | Час начала торговой сессии по серверному времени (0-23) |
| InpBinPoints | Высота строки профиля в пунктах (1 или более) |
| InpValueAreaPercent | Процент объёма для зоны Value Area (1-100) |
| InpVolume | Тип объёма для построения профиля (тиковый или реальный) |
| InpFillValueArea | Заливка зоны Value Area прямоугольником |
| InpExtendToday | Продление линий текущего дня вправо |
| InpShowLabels | Отображение ценовых меток уровней текущего дня |
| InpPOCColor | Цвет линии POC |
| InpVAColor | Цвет линий VAH / VAL |
| InpFillColor | Цвет прямоугольника зоны Value Area |
| InpPOCWidth | Толщина линии POC (1-5) |
Поиск по коду файла
#property version "1.00"
#property description "Point of Control (POC) and Value Area lines for every day."
#property description "A volume profile is built from the volume of the bars of each day;"
#property description "POC, Value Area High (VAH) and Value Area Low (VAL) are drawn as lines."
#property indicator_chart_window
#property indicator_buffers 0
#property indicator_plots 0
input group "Profile"
input int InpDays = 5; // Number of days to display (1 or more)
input int InpSessionStartHour = 0; // Day start hour, server time (0-23)
input int InpBinPoints = 10; // Profile row height in points (1 or more)
input double InpValueAreaPercent = 70.0; // Value Area, % of the day volume (1-100)
input ENUM_APPLIED_VOLUME InpVolume = VOLUME_TICK; // Volume used for the profile (tick or real)
input group "Display"
input bool InpFillValueArea = false; // Fill the Value Area with a rectangle
input bool InpExtendToday = true; // Extend the lines of the current day to the right
input bool InpShowLabels = true; // Show price labels of the current day levels
input color InpPOCColor = clrDarkOrange; // POC line color
input color InpVAColor = clrDodgerBlue; // VAH / VAL line color
input color InpFillColor = clrLightSteelBlue; // Value Area rectangle color
input int InpPOCWidth = 2; // POC line width (1-5)
const int HIST_SIZE = 20000; // number of rows in the profile array
const int HIST_HALF = 10000; // rows below the day's first price (profile is centered on it)
double g_hist[]; // profile of the current day (volume per row)
long g_base = 0; // absolute grid index of row 0
int g_lo = 0; // lowest row that contains volume
int g_hi = -1; // highest row that contains volume
long g_dayKey = -1; // key of the day being accumulated (-1 = none)
datetime g_dayStart = 0; // time of the first bar of that day
datetime g_dayLast = 0; // time of the last closed bar added to that day
int g_histBar = 0; // all bars with index below this are already in the profile
double g_bin = 0.0; // row height in price units
long g_offset = 0; // day start offset from 00:00, seconds
string g_prefix = ""; // prefix of all chart objects created by this instance
long g_keys[]; // keys of the days that currently have objects on the chart
bool g_clipWarned = false; // the "price out of profile range" message was printed
long DayKey(const datetime t)
{
return(((long)t - g_offset) / 86400);
}
int HistIndex(const double price)
{
long idx = (long)MathFloor(price / g_bin) - g_base;
if(idx < 0 || idx >= HIST_SIZE)
{
if(!g_clipWarned)
{
Print("Price is outside of the profile range; increase InpBinPoints.");
g_clipWarned = true;
}
idx = (idx < 0) ? 0 : HIST_SIZE - 1;
}
return((int)idx);
}
void AddVolume(const double lowPrice, const double highPrice, const double vol,
const double sign, int &lo, int &hi)
{
int rowLow = HistIndex(lowPrice);
int rowHigh = HistIndex(highPrice);
double share = sign * vol / (double)(rowHigh - rowLow + 1);
for(int k = rowLow; k <= rowHigh; k++)
g_hist[k] += share;
if(rowLow < lo)
lo = rowLow;
if(rowHigh > hi)
hi = rowHigh;
}
bool CalcLevels(const int lo, const int hi, double &poc, double &vah, double &val)
{
double total = 0.0;
double maxVol = -1.0;
int pocRow = lo;
double middle = 0.5 * (double)(lo + hi);
for(int k = lo; k <= hi; k++)
{
double v = g_hist[k];
total += v;
if(v > maxVol || (v == maxVol && MathAbs((double)k - middle) < MathAbs((double)pocRow - middle)))
{
maxVol = v;
pocRow = k;
}
}
if(total <= 0.0)
return(false);
double target = total * InpValueAreaPercent / 100.0;
double acc = maxVol;
int up = pocRow;
int down = pocRow;
while(acc < target && (up < hi || down > lo))
{
double sumUp = 0.0, sumDown = 0.0;
int stepUp = 0, stepDown = 0;
if(up < hi)
{
stepUp = (up + 2 <= hi) ? 2 : 1;
for(int s = 1; s <= stepUp; s++)
sumUp += g_hist[up + s];
}
if(down > lo)
{
stepDown = (down - 2 >= lo) ? 2 : 1;
for(int s = 1; s <= stepDown; s++)
sumDown += g_hist[down - s];
}
if(stepDown == 0 || (stepUp > 0 && sumUp >= sumDown))
{
acc += sumUp;
up += stepUp;
}
else
{
acc += sumDown;
down -= stepDown;
}
}
poc = NormalizeDouble(((double)(g_base + pocRow) + 0.5) * g_bin, _Digits);
vah = NormalizeDouble(((double)(g_base + up) + 1.0) * g_bin, _Digits);
val = NormalizeDouble((double)(g_base + down) * g_bin, _Digits);
return(true);
}
void SetLine(const string name, const datetime t1, const datetime t2, const double price,
const color clr, const ENUM_LINE_STYLE style, const int width,
const bool rayRight, const string tip)
{
if(ObjectFind(0, name) < 0)
{
if(!ObjectCreate(0, name, OBJ_TREND, 0, t1, price, t2, price))
return;
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, name, OBJPROP_RAY_LEFT, false);
}
ObjectSetInteger(0, name, OBJPROP_TIME, 0, t1);
ObjectSetDouble(0, name, OBJPROP_PRICE, 0, price);
ObjectSetInteger(0, name, OBJPROP_TIME, 1, t2);
ObjectSetDouble(0, name, OBJPROP_PRICE, 1, price);
ObjectSetInteger(0, name, OBJPROP_COLOR, clr);
ObjectSetInteger(0, name, OBJPROP_STYLE, style);
ObjectSetInteger(0, name, OBJPROP_WIDTH, width);
ObjectSetInteger(0, name, OBJPROP_RAY_RIGHT, rayRight);
ObjectSetString(0, name, OBJPROP_TOOLTIP, tip);
}
void SetBox(const string name, const datetime t1, const datetime t2,
const double priceHigh, const double priceLow)
{
if(ObjectFind(0, name) < 0)
{
if(!ObjectCreate(0, name, OBJ_RECTANGLE, 0, t1, priceHigh, t2, priceLow))
return;
ObjectSetInteger(0, name, OBJPROP_SELECTABLE, false);
ObjectSetInteger(0, name, OBJPROP_HIDDEN, true);
ObjectSetInteger(0, name, OBJPROP_FILL, true);
ObjectSetInteger(0, name, OBJPROP_BACK, true);
}
ObjectSetInteger(0, name, OBJПоказано первые 50% кода (символов: 9599)