AmiBroker AFL for Volume Delta and Cumulative Volume Delta Indiactors

#1
These two AFL code is inspired by the "Volume Delta" and "Cumulative Volume Delta" indicator from TradingView's Pine Script, and it has been carefully checked to be error-free. However, despite its correctness, the code does not produce any visual output when run. I am sharing this code here to seek assistance in identifying and resolving the issue, so that everyone can benefit from the "Volume Delta" and "Cumulative Volume Delta" indicator on the AmiBroker platform. Your help and expertise would be greatly appreciated. Thank you and best regards.

_SECTION_BEGIN( "Volume Delta" );
TimeFrameSet( in1Second );
//Function to get Up and Down Volume
function upAndDownVolume()
{
posVol = 0;
negVol = 0;

for( i = 1; i < BarCount; i++ )
{
isBuyVolume = True;

if( Close > Open )
isBuyVolume = True;
else
if( Close < Open )
isBuyVolume = False;
else
if( Close > Close[i - 1] )
isBuyVolume = True;
else
if( Close < Close[i - 1] )
isBuyVolume = False;

if( isBuyVolume )
posVol += Volume;
else
negVol += -Volume;
}

return posVol + negVol;
}

TimeFrameRestore();

vd = upAndDownVolume();

TimeFrameSet( in1Second );
// Function to calculate cumulative volume
function getcumvol( arr )
{
arr = 0;
cumVolume = 0;

for( i = 1; i < arr; i++ )
{
cumVolume += arr;
}

return cumVolume;
}

// Function to calculate high or max cumulative volume
function getmaxvol( arr )
{
arr = 0;
cumVolume = 0;
maxVolume = 0;

for( i = 1; i < arr; i++ )
{
cumVolume = arr;
maxVolume += Max( maxVolume, cumVolume );
}

return maxVolume;
}

// Function to calculate low or min cumulative volume
function getminvol( arr )
{
arr = 0;
cumVolume = 0;
minVolume = 0;

for( i = 1; i < arr; i++ )
{
cumVolume = arr;
minVolume += IIf( i == 0, cumVolume, Min( minVolume, cumVolume ) );
}

return minVolume;
}

cumvol = getcumvol( upAndDownVolume() );
maxvol = getmaxvol( upAndDownVolume() );
minvol = getminvol( upAndDownVolume() );
TimeFrameRestore();

col = IIf( cumvol > 0, colorTeal, colorRed );

PlotGrid( 0, colorBlack, 9, 2, True );
PlotOHLC( 0, maxvol, minvol, cumvol, "Volume Delta", color = col, styleCandle | styleOwnScale | styleNoLabel );
_SECTION_END();

..............................................................................................................................................................................
..............................................................................................................................................................................

_SECTION_BEGIN( "Cumulative Volume Delta_Final" );
/*This AFL code is inspired by the "Cumulative Volume Delta" indicator from TradingView's Pine Script, and it has been carefully checked to be error-free.
However, despite its correctness, the code does not produce any visual output when run. I am sharing this code here to seek assistance in identifying
and resolving the issue, so that everyone can benefit from the "Cumulative Volume Delta" indicator on the AmiBroker platform. Your help and expertise would
be greatly appreciated. Thank you and best regards.*/

TimeFrameSet( in1Second );
//Function to get Up and Down Volume
function upAndDownVolume()
{
posVol = 0;
negVol = 0;

for( i = 1; i < BarCount; i++ )
{
isBuyVolume = True;

if( Close > Open )
isBuyVolume = True;
else
if( Close < Open )
isBuyVolume = False;
else
if( Close > Close[i - 1] )
isBuyVolume = True;
else
if( Close < Close[i - 1] )
isBuyVolume = False;

if( isBuyVolume )
posVol += Volume;
else
negVol += -Volume;
}

return posVol + negVol;
}

TimeFrameRestore();

vd = upAndDownVolume();

TimeFrameSet( in1Second );
// Function to calculate cumulative volume
function getcumvol( arr )
{
arr = 0;
cumVolume = 0;

for( i = 1; i < arr; i++ )
{
cumVolume += arr;
}

return cumVolume;
}

// Function to calculate high or max cumulative volume
function getmaxvol( arr )
{
arr = 0;
cumVolume = 0;
maxVolume = 0;

for( i = 1; i < arr; i++ )
{
cumVolume = arr;
maxVolume += Max( maxVolume, cumVolume );
}

return maxVolume;
}

// Function to calculate low or min cumulative volume
function getminvol( arr )
{
arr = 0;
cumVolume = 0;
minVolume = 0;

for( i = 1; i < arr; i++ )
{
cumVolume = arr;
minVolume += IIf( i == 0, cumVolume, Min( minVolume, cumVolume ) );
}

return minVolume;
}

cumvol = getcumvol( upAndDownVolume() );
maxvol = getmaxvol( upAndDownVolume() );
minvol = getminvol( upAndDownVolume() );
TimeFrameRestore();

//anchorChange = (BarIndex() == 0);

dn = Day();
firstB = dn != Ref( dn, -1 );// first flag
anchorChange = BarsSince(firstB);

cumulLastVolume = 0;
cumulOpenVolume = IIf( anchorChange, 0, Ref( cumulLastVolume, -1 ) );
cumulMaxVolume = cumulOpenVolume + maxvol;
cumulMinVolume = cumulOpenVolume + minvol;
cumulLastVolume = cumulOpenVolume + cumvol;

col = IIf( cumvol > 0, colorTeal, colorRed );

PlotGrid( 0, colorBlack, 9, 2, True );
PlotOHLC( cumulOpenVolume, cumulMaxVolume, cumulMinVolume, cumulLastVolume, "Cumulative Volume Delta", color = col, styleCandle | styleOwnScale | styleNoLabel );
_SECTION_END();


Thank you and regards.
 

Similar threads