Amibroker Volume at Price System Help

#1
Hey Guys,

I am trying to develop a trading system using Volume at Price on 5 min which I can back test and optimize. As of right now the code basically finds the highest volume price of the day. When I use printf to display highest volume price it outputs it correctly, buy when I try to run AA using:

buy=iif(C==PreviouseDayHVP ,1,0);

it buys on some random number.

I checked setting in AA and all seems to be ok, 5min time interval, buy on close, delay=0.

I tried another test where I used printf to show me that the HVP on Jun 1 2009 was 23.19, which is correct, then ran AA with:

buy=iif(PreviouseDayHVP ==23.19,1,0);

no buys came up... leading me to conclude that printf and AA are calculating highestvolumeprice differently...




Thank you so much in advanced

here is the AFL:


for ( i = 1;i < 170;i++ )
{


VarSet( "a" + i, 0 );
}

//===========
Maxvolume = 1;

add = 0;

Hours = ( Hour() - 9 ) * 12;

Minutes = ( Minute() / 5 - 6 );

Barsinday = Minutes + Hours;

Lowestlow = Ref( LLV( C, ( 78 ) ), ( 77 - barsinday ) );

Lowestlow = Prec( Lowestlow, 2 );

price = 0;

Fromlow = ( barsinday / 100 );

Endofday = IIf( int( BarIndex() / 78 ) + 1 != int( ( BarIndex() + 1 ) / 78 ) + 1, 1, 0 );

//=====================================================================================

//Following Adds Volume At Price

Clear = IIf( int( BarIndex() / 78 ) + 1 != int( ( BarIndex() + 1 ) / 78 ) + 1, 1, 0 );

for ( i = 1;i < 78;i++ )
{


BarLength = ( Ref( H, -i ) - Ref( L, -i ) ) * 100 + 1;
FromLow = ( ( Ref( L, -i ) - Lowestlow ) * 100 );


b1 = int( fromlow + 1 );
b1 = IIf( b1 - int( b1 ) < .5, int( b1 ), int( b1 ) + 1 );
VarSet( "a" + b1, ( ( Ref( V, -i ) / barlength ) + VarGet( "a" + b1 ) )*Clear );

b2 = fromlow + 2;
b2 = IIf( b2 - int( b2 ) < .5, int( b2 ), int( b2 ) + 1 );
p1 = IIf( barlength >= 2, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b2 ) ) * Clear , VarGet( "a" + b2 ) );
VarSet( "a" + b2, p1 );

b3 = fromlow + 3;
b3 = IIf( b3 - int( b3 ) < .5, int( b3 ), int( b3 ) + 1 );
p2 = IIf( barlength >= 3, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b3 ) ) * Clear , VarGet( "a" + b3 ) );
VarSet( "a" + b3, p2 );

b4 = fromlow + 4;
b4 = IIf( b4 - int( b4 ) < .5, int( b4 ), int( b4 ) + 1 );
p3 = IIf( barlength >= 4, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b4 ) ) * Clear , VarGet( "a" + b4 ) );
VarSet( "a" + b4, p3 );

b5 = fromlow + 5;
b5 = IIf( b5 - int( b5 ) < .5, int( b5 ), int( b5 ) + 1 );
p4 = IIf( barlength >= 5, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b5 ) ) * Clear , VarGet( "a" + b5 ) );
VarSet( "a" + b5, p4 );

b6 = fromlow + 6;
b6 = IIf( b6 - int( b6 ) < .5, int( b6 ), int( b6 ) + 1 );
p5 = IIf( barlength >= 6, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b6 ) ) * Clear , VarGet( "a" + b6 ) );
VarSet( "a" + b6, p5 );

b7 = fromlow + 7;
b7 = IIf( b7 - int( b7 ) < .5, int( b7 ), int( b7 ) + 1 );
p6 = IIf( barlength >= 7, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b7 ) ) * Clear , VarGet( "a" + b7 ) );
VarSet( "a" + b7, p6 );

b8 = fromlow + 8;

b8 = IIf( b8 - int( b8 ) < .5, int( b8 ), int( b8 ) + 1 );
p7 = IIf( barlength >= 8, ( ( Ref( V, -i ) ) / Barlength ) + VarGet( "a" + b8 ) * Clear , VarGet( "a" + b8 ) );
VarSet( "a" + b8, p7 );

b9 = fromlow + 9;

b9 = IIf( b9 - int( b9 ) < .5, int( b9 ), int( b9 ) + 1 );
p8 = IIf( barlength >= 9, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b9 ) ) * Clear , VarGet( "a" + b9 ) );
VarSet( "a" + b9, p8 );

b10 = fromlow + 10;

b10 = IIf( b10 - int( b10 ) < .5, int( b10 ), int( b10 ) + 1 );
p9 = IIf( barlength >= 10, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b10 ) ) * Clear , VarGet( "a" + b10 ) );
VarSet( "a" + b10, p9 );

b11 = fromlow + 11;
b11 = IIf( b11 - int( b11 ) < .5, int( b11 ), int( b11 ) + 1 );
p10 = IIf( barlength >= 11, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b11 ) ) * Clear , VarGet( "a" + b11 ) );
VarSet( "a" + b11, p10 );

b12 = fromlow + 12;
b12 = IIf( b12 - int( b12 ) < .5, int( b12 ), int( b12 ) + 1 );
p11 = IIf( barlength >= 12, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b12 ) ) * Clear , VarGet( "a" + b12 ) );
VarSet( "a" + b12, p11 );

b13 = fromlow + 13;
b13 = IIf( b13 - int( b13 ) < .5, int( b13 ), int( b13 ) + 1 );
p12 = IIf( barlength >= 13, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b13 ) ) * Clear , VarGet( "a" + b13 ) );
VarSet( "a" + b13, p12 );

b14 = fromlow + 14;
b14 = IIf( b14 - int( b14 ) < .5, int( b14 ), int( b14 ) + 1 );
p13 = IIf( barlength >= 14, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b14 ) ) * Clear , VarGet( "a" + b14 ) );
VarSet( "a" + b14, p13 );

b15 = fromlow + 15;
b15 = IIf( b15 - int( b15 ) < .5, int( b15 ), int( b15 ) + 1 );
p14 = IIf( barlength >= 15, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b15 ) ) * Clear , VarGet( "a" + b15 ) );
VarSet( "a" + b15, p14 );

b16 = fromlow + 16;
b16 = IIf( b16 - int( b16 ) < .5, int( b16 ), int( b16 ) + 1 );
p15 = IIf( barlength >= 16, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b16 ) ) * Clear , VarGet( "a" + b16 ) );
VarSet( "a" + b16, p15 );

b17 = fromlow + 17;
b17 = IIf( b17 - int( b17 ) < .5, int( b17 ), int( b17 ) + 1 );
p16 = IIf( barlength >= 17, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b17 ) ) * Clear , VarGet( "a" + b17 ) );
VarSet( "a" + b17, p16 );

b18 = fromlow + 18;
b18 = IIf( b18 - int( b18 ) < .5, int( b18 ), int( b18 ) + 1 );
p17 = IIf( barlength >= 18, ( ( Ref( V, -i ) ) / Barlength ) + VarGet( "a" + b18 ) * Clear , VarGet( "a" + b18 ) );
VarSet( "a" + b18, p17 );

b19 = fromlow + 19;
b19 = IIf( b19 - int( b19 ) < .5, int( b19 ), int( b19 ) + 1 );
p18 = IIf( barlength >= 19, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b19 ) ) * Clear , VarGet( "a" + b19 ) );
VarSet( "a" + b19, p18 );

b20 = fromlow + 20;
b20 = IIf( b20 - int( b20 ) < .5, int( b20 ), int( b20 ) + 1 );
p19 = IIf( barlength >= 20, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b20 ) ) * Clear , VarGet( "a" + b20 ) );
VarSet( "a" + b20, p19 );

b21 = fromlow + 21;
b21 = IIf( b21 - int( b21 ) < .5, int( b21 ), int( b21 ) + 1 );
p20 = IIf( barlength >= 21, ( ( Ref( V, -i ) / Barlength ) + VarGet( "a" + b21 ) ) * Clear , VarGet( "a" + b21 ) );
VarSet( "a" + b21, p20 );

}


//Following finds largets Volume at price for the day
for ( i = 1;i < 151;i++ )
{
for ( x = 1;x < 151;x++ )
{

Add = IIf( VarGet( "a" + i ) > VarGet( "a" + x ) AND endofday == 1, add + 1, add );

if ( x == 150 )
{
Maxvolume = IIf( add == 148, VarGet( "a" + i ), Maxvolume );
price = IIf( add == 148 AND endofday == 1, Lowestlow + ( i - 1 ) / 100, price );

}

}

add = 0;
}

PreviouseDayHVP = Ref( price, -( 77 - ( 77 - ( barsinday + 1 ) ) ) );


printf( " %f=== %f %f %f %f %g ", a34, a1, a9, BarIndex(), price, PreviouseDayHVP );
Buy = IIf( PreviouseDayHVP == C, 1, 0 );
 
#2
Sorry I though I might simplify my above post. Does anyone know how to use AFL to find the highest volume price of the previous day? There is an indicator in Amibroker but I don't know how to use it to automatically generate signals.

So I could generate a buy signal for example:

buy=iif(c==PreviousDayHighestVolumePrice,1,0);

Thanks
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?