How to get VolumeProfile Node(s) values as Indicator Buffers.

 

Dear Fellows

I am trying to customize Volume Profile indicator https://www.mql5.com/en/code/47784 and make it EA Friendly to get signals for POC Price (png attached), HVN and LVN Prices.

Google search did not helped much and all the VP Indicators lack the Buffers. Is it really impossible to created indicator buffers for VP?

If not possible than how can I compare in the EA if current price at a certain VP Node?

As OBJ_RECTANGLE_LABEL is used in drawing the objects (Nodes), I can not use 'ObjectGetValueByTime()' or 'ObjectGetDouble()' methods

Or Gurus here can guide me some way to make it possible?

I am able to decode the 'Price' of a given node highlighted code, however failed to convert horizontal bars to vertical bar array!!!

        //+---------------------------------------------------------------------------------------------------------------------------+
        //| Point of Control (POC) is the maximum VP found in the Volume profile array
        //| Define the maximum length (inPixels) of VP bars (which is for POC) by considering the width of the chart and ratio input
        //+---------------------------------------------------------------------------------------------------------------------------+
                double POC = profile[ArrayMaximum(profile,0,WHOLE_ARRAY)];
                int    lengthPOCBar   = (int)(ratio * ChartGetInteger(_ChartID,CHART_WIDTH_IN_PIXELS));
        //+---------------------------------------------------------------------------------------------------------------------------+
        //| Find an appropriate VP Bar's height (inPixels) by considering the chart height and the number of VP bars
        //+---------------------------------------------------------------------------------------------------------------------------+
                double rangeVP     = vpMax - vpMin;
                double rangeChart  = ChartGetDouble(0,CHART_PRICE_MAX) - ChartGetDouble(0,CHART_PRICE_MIN);
                int              heightVPBar = (int)(ChartGetInteger(_ChartID,CHART_HEIGHT_IN_PIXELS) * (rangeVP / rangeChart) / ExtPrecision);
                
                if(POC == 0.0)                                                                                                                                                                                                                                                                                                                                                                                                                  return;
                // Delete all existing bars before drawing new ones
                ObjectsDeleteAll(_ChartID,"VPBar ",-1,-1);
        //+---------------------------------------------------------------------------------------------------------------------------+
        //| Draw VP bars one by one from the lowest price in the vpRange to the highest
        //+---------------------------------------------------------------------------------------------------------------------------+
                for(int n = 0; n < ExtPrecision; n++) {
                        // The length of each VP bar is calculated by its ratio to POC
                        int xd = (int)((profile[n] / POC) * lengthPOCBar);
                        int x_start = 0;
                        int y_start = 0;

                //+---------------------------------------------------------------------------------------------------------------------------+
                //| Set VP Nodes for XY Cordinates and Get Time and Price of each Node
                //| Finding the xy cordinates for drawing VP Bar(s) according to the end vline and min price in the vpRange
                //+---------------------------------------------------------------------------------------------------------------------------+
                        ChartTimePriceToXY(_ChartID,0,timeFinish,vpMin+(n+1) * vpRange,x_start,y_start);
                        // In case the end of VPs go beyond the visible chart
                        if(x_start + xd >= ChartGetInteger(_ChartID,CHART_WIDTH_IN_PIXELS))
                                xd = (int)ChartGetInteger(_ChartID,CHART_WIDTH_IN_PIXELS) - x_start;

                        // Get Time and Price value of given VPNode[n] using its XY Cordinates
                        int                      subWindow = 0;                         // [out] SubWindow value in ChartXYToTimePrice()
                        datetime nodeTime  = 0;                         // [out] Datetime value in ChartXYToTimePrice()
                        double   nodePrice = 0.00;              // [out] Price value in ChartXYToTimePrice()
                        ChartXYToTimePrice(_ChartID,x_start,y_start,subWindow,nodeTime,nodePrice); ... GOT THE NODE TIME / PRICE

                        // Draw rectangle lable to display VP bars, using RectLabelCreate function
                        // Will also be the color for Low Volume Nodes
                        RectLabelCreate("VPBar " + IntegerToString(n),x_start,y_start,xd,heightVPBar,PVBarsClr);

                        // Change the color of POC Bar
                        if(profile[n] == POC) {
                                ObjectSetInteger(_ChartID,"VPBar " + IntegerToString(n),OBJPROP_COLOR,POCBarClr);
                                ObjectSetInteger(_ChartID,"VPBar " + IntegerToString(n),OBJPROP_BGCOLOR,POCBarClr);
                                //PrintFormat("%s profile[%i] [%s][%.1f]",vMethod,n,TimeToString(nodeTime),nodePrice);
                        }
                        // Change the color of HVN (High Volume Node) Bar
                        if(profile[n] != POC && profile[n] >= (POC * HVNRatio)) {
                                ObjectSetInteger(_ChartID,"VPBar " + IntegerToString(n),OBJPROP_COLOR,HVNBarClr);
                                ObjectSetInteger(_ChartID,"VPBar " + IntegerToString(n),OBJPROP_BGCOLOR,HVNBarClr);
                                //PrintFormat("%s profile[%i] [%s][%.1f]",vMethod,n,TimeToString(nodeTime),nodePrice);
                                int idx = iBarShift(_Symbol,CurrentTF,TimeCurrent());
                                if(nodeTime > TimeCurrent())    BuffPOC[idx] = nodePrice;			... FAILED TO CONVERT THIS AS INDICATOR BUFFER!!!
                        }
                        //if(profile[n] != POC && profile[n] < (POC * HVNRatio))
                                //PrintFormat("%s profile[%i] [%s][%.1f]",vMethod,n,TimeToString(nodeTime),nodePrice);

Your guidance is highly appreciated in advance.

Regards.

Volume Profile
Volume Profile
  • www.mql5.com
This is an indicator for showing volume profile on the chart, using simple calculations and very fast execution.
Files:
 

try modifying like this example for buffers

// Define the buffer arrays
double BufferPOC[];
double BufferHVN[];

// Modify the existing code to store values in the buffers
void CalculateVP() {
    // ... Existing code ...

    for(int n = 0; n < ExtPrecision; n++) {
        // ... Existing code ...

        // Store values in the buffers
        int idx = iBarShift(_Symbol, CurrentTF, nodeTime);
        BufferPOC[idx] = (profile[n] == POC) ? nodePrice : EMPTY_VALUE;
        BufferHVN[idx] = (profile[n] != POC && profile[n] >= (POC * HVNRatio)) ? nodePrice : EMPTY_VALUE;

        // ... Existing code ...
    }
}

// Example usage in OnCalculate
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[]) {

    // Calculate VP
    CalculateVP();

    // ... Rest of the OnCalculate function ...
}
 
Rajesh Kumar Nait #:

try modifying like this example for buffers

Hi @Rajesh Kumar Nait

Thanks a lot for your reply. I did try your suggestion but it did not worked. May be I am lacking some skills to implement it.

Another issue indicator calculates VP OnChartEvent (moving VPBegin and VPEnd) lines.

Let me try options to remove use of OnChartEvent and than apply your suggestion.

Will revert back here, if failed to get solution.

Regards.