Ways for Finding Developing Value Area and POC in the Volume Profile

Hi All,

I would like to see the developing value area and the developing point of control in the volume profile.
Before Implementing i would like to get the opinion from the experts who used/created it , i learnt and learning many from this forum, i hope i learn this too .

Below is the Code provided in the Example of PriceVolDistribuition Function().

bi = BarIndex(); 
 fvb = FirstVisibleValue( bi ); 
 lvb = LastVisibleValue( bi ); 

 mx = PriceVolDistribution( H, L, V, 100, False, fvb, lvb ); 

GfxSetCoordsMode( 1 ); 

GfxSelectPen( colorRed ); 

 bins = MxGetSize( mx, 0 ); 
for( i = 0; i < bins; i++ ) 
 { 
 price = mx[ i ][ 0 ]; // price level 
 relvolume = mx[ i ][ 1 ]; // relative volume 0..1 
 relbar = relvolume * (lvb-fvb+1); 
 GfxMoveTo( fvb, price ); 
 GfxLineTo( fvb + relbar, price ); 
 } 

Here what i am planning is in the PriceVolDistribution() , i need to put another loop like below ....

for (i=fvb+1;i<lvb;i++)
 mx = PriceVolDistribution( H, L, V, 100, False, fvb, i); 
 mat_sort = MxSortRows( mx0, False, 1 );
 MaxVolume = mat_sort[0][1];

Here is the Value Area Finding AFL from the experts of this Forum ,

So I have pass the the matrix from the above to the following value area code to calculate VAH and VAL for every bar Right ?

/// Value Area Calcluation Starts here


                mxTimeBinIdx = poc_idx;
                totTime = TotalMxVol;
                tmx = mx0;

// mxTimeBinIdx - This is POC Bin's Index
                // bins - This is Total Bin Size
                //mx - This is Matrix for which the value area needs to be calculated
                // totTime - The Entire Total Volume

                mxih = mxil = mxTimeBinIdx;
                // mxih is the index number for Value Area High , initally it is set to POC's Index Number
                // mxil is the index number for Value Area Low, initally it is set to POC's Index Number

                tvol = tmx[mxTimeBinIdx][1]; // tvol represents the POC Volume

                for( j = 0; j < bins; j++ ) // Looping all the Bins
                {
                    if( mxih + 1 < bins AND mxil - 1 >= 0 ) // Checking whether VAH index is less than the  Bin and
                    {
                        relvolumeh = tmx[mxih + 1][1]; // High Volume
                        relvolumel = tmx[mxil - 1][1];// Low Volume

                        if( relvolumeh > relvolumel ) //
                        {
                            mxih = mxih + 1;
                            tvol = tvol + relvolumeh;
                        }
                        else
                            if( relvolumeh < relvolumel )
                            {
                                mxil = mxil - 1;
                                tvol = tvol + relvolumel;
                            }
                            else
                                if( relvolumeh == relvolumel )
                                {
                                    mxih = mxih + 1;
                                    mxil = mxil - 1;
                                    tvol = tvol + relvolumeh + relvolumel;
                                }
                    }
                    else
                        if( mxih + 1 >= bins AND mxil - 1 >= 0 )
                        {
                            relvolumel = tmx[mxil - 1][1];
                            mxil = mxil - 1;
                            tvol = tvol + relvolumel;
                        }
                        else
                            if( mxih + 1 < bins AND mxil - 1 < 0 )
                            {
                                relvolumeh = tmx[mxih + 1][1];
                                mxih = mxih + 1;
                                tvol = tvol + relvolumeh;
                            }

                    if( ( tvol / totTime ) >= volumeValueArea )
                    {
                        vp_vd_in_va = tvol;
                        break;
                    }
                }


/// Value Area Calculation Stops here

Note : The Code Shown here are from AmiBroker Help / Forum , Thanks to those mentors.

i feel it is bit time consuming and looping a lot ?
Is there any other ways ? to do this efficiently...

Thanks in Advance,
Kaeswar

Hi all,

Thanks Gemini 2.5 Pro assisted me, So Query is resolved.
Anyhow thanks

Good to hear. Maybe consider posting solution here so others might in the future benefit from it.

1 Like

Sure Tomasz, posting the afl down here

prev_vah=0;
prev_val=0;
prev_poc=0;
            // START: ADDED DEVELOPING PROFILE LOGIC
            if( Developing_Profile == 1 )
            {
                for( i = fvb; i <= lvb; i++ )
                {
                    // Calculate the volume profile up to the current bar 'i'
                    mx_dev = PriceVolDistribution( priceH, L, For_Vol, bins, absolute = True, fvb, i );
                    bins_dev = MxGetSize( mx_dev, 0 );

                    if( bins_dev > 1 )
                    {
                        // Find the developing POC
                        mat_sort_dev = MxSortRows( mx_dev, False, 1 );
                        dev_poc_price = mat_sort_dev[0][0];
                        dev_total_vol = MxSum( MxGetBlock( mx_dev, 0, bins_dev - 1, 1, 1, asArray = False ) );
                        dev_poc_vol = mat_sort_dev[0][1];

                        // Calculate the developing VA
                        dev_mxih = -1;
                        dev_mxil = -1;

                        // Find POC index for the developing profile
                        dev_poc_idx = -1;

                        for( k = 0; k < bins_dev; k++ )
                        {
                            if( mx_dev[k][0] == dev_poc_price )
                            {
                                dev_poc_idx = k;
                                break;
                            }
                        }

                        // Ensure a valid POC index was found
                        if( dev_poc_idx != -1 )
                        {
                            dev_tvol = mx_dev[dev_poc_idx][1];
                            dev_mxih = dev_mxil = dev_poc_idx;

                            for( j = 0; j < bins_dev; j++ )
                            {
                                if( ( dev_tvol / dev_total_vol ) >= volumeValueArea )
                                {
                                    break;
                                }

                                if( dev_mxih + 1 < bins_dev AND dev_mxil - 1 >= 0 )
                                {
                                    dev_relvolumeh = mx_dev[dev_mxih + 1][1];
                                    dev_relvolumel = mx_dev[dev_mxil - 1][1];

                                    if( dev_relvolumeh > dev_relvolumel )
                                    {
                                        dev_mxih = dev_mxih + 1;
                                        dev_tvol = dev_tvol + dev_relvolumeh;
                                    }
                                    else
                                        if( dev_relvolumeh < dev_relvolumel )
                                        {
                                            dev_mxil = dev_mxil - 1;
                                            dev_tvol = dev_tvol + dev_relvolumel;
                                        }
                                        else
                                            if( dev_relvolumeh == dev_relvolumel )
                                            {
                                                dev_mxih = dev_mxih + 1;
                                                dev_mxil = dev_mxil - 1;
                                                dev_tvol = dev_tvol + dev_relvolumeh + dev_relvolumel;
                                            }
                                }
                                else
                                    if( dev_mxih + 1 >= bins_dev AND dev_mxil - 1 >= 0 )
                                    {
                                        dev_relvolumel = mx_dev[dev_mxil - 1][1];
                                        dev_mxil = dev_mxil - 1;
                                        dev_tvol = dev_tvol + dev_relvolumel;
                                    }
                                    else
                                        if( dev_mxih + 1 < bins_dev AND dev_mxil - 1 < 0 )
                                        {
                                            dev_relvolumeh = mx_dev[dev_mxih + 1][1];
                                            dev_mxih = dev_mxih + 1;
                                            dev_tvol = dev_tvol + dev_relvolumeh;
                                        }
                            }

                            // Plot the developing lines on the chart for the current bar 'i'
                            GfxSetCoordsMode( 1 );
                            GfxSelectPen( Dev_VA_Color, 2, 0 );

                            GfxMoveTo( i, prev_vah);
							GfxLineTo( i+1 , mx_dev[dev_mxih][0] );
                            
                            //GfxMoveTo( i, mx_dev[dev_mxih][0] );
                            //GfxLineTo( i + 1, mx_dev[dev_mxih][0] );
                            

							GfxMoveTo( i, prev_val );
                            GfxLineTo( i+1 , mx_dev[dev_mxil][0] );
                            
                            //GfxMoveTo( i, mx_dev[dev_mxil][0] );
                            //GfxLineTo( i + 1, mx_dev[dev_mxil][0] );

                            GfxSelectPen( Dev_POC_Color, 2, 0 );
                            
                            GfxMoveTo( i, prev_poc );
                            GfxLineTo( i+1 , dev_poc_price );
                            
							prev_vah=mx_dev[dev_mxih][0];
                            prev_val=mx_dev[dev_mxil][0];
                            prev_poc=dev_poc_price;

                        }
                    }
                }
            }

            // END: ADDED DEVELOPING PROFILE LOGIC

The Charming part is, it added the paramaters too as like in my existing afl ....

    // START: ADDED PARAMETERS FOR DEVELOPING PROFILE
    Developing_Profile = ParamToggle( "Developing Profile", "Off|On", 1 );
    Dev_VA_Color = ParamColor( "Developing VA Color", colorViolet );
    Dev_POC_Color = ParamColor( "Developing POC Color", colorRed );
    // END: ADDED PARAMETERS

5 Likes

Thanks for sharing

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.