Sector volume - custom calculation formula

@fxshrat

I'm using your afl for getting sector total volume. After using the afl I come up with another custom calculations which I'm using presently with another AFL. In place of sector total volume I'm using my custom calculation-1 in the afl, which is giving good results as per my calculation.

I have used my custom calculation-1 in Nz() which is working fine. But when I'm using custom calculation-3 the results are not coming as expected. It will displaying some other irrelevant numbers, I can't even identify what are those numbers? I think my input sequence of the formula is wrong in Nz(). I thought that, when the customer calculation-1 is working fine, then custom calculation-3 formula also works. But it is not? Definitely, I'm doing wrong which I can't identify with my limited programing knowledge. Can you please help me in this regard.

//custom calculation 1 
dp=(Aux1*Aux2)/10000000;
dp1=dp/100;

//custom calculation 2 
//FiveDAvg = MA(dp1, 5);
DVAVG = (Ref(dp1, -1))+(Ref(dp1, -2))+(Ref(dp1, -3))+(Ref(dp1, -4))+
(Ref(dp1, -5));
fivedAvg=DVAVG/5;

//custom calculation 3
Five5DAvg = dp1/FiveDavg*100;


_SECTION_BEGIN("fxshrt afl");
wl_number = 62;// set your watchlist number here
ticker_list = CategoryGetSymbols(categoryWatchlist, wl_number );

NF50basket = 0;
is_null = 0;
for (i = 0; (ticker = StrExtract(ticker_list, i)) != ""; i++) {
	SetForeign(ticker);
		NF50basket += Nz((Aux1*Aux2)/10000000)/100;// Nz converts Null to zero
		//is_null += IsNull(V);// Are there symbols returning Null (no data?)
	RestorePriceArrays();
}

// print sum of symbols returning Null (having no data)
printf("Sum of symbols returning Null: %g", is_null);

Plot( NF50basket, "sect.vol", colorGreen, styleLine, Null, Null, 0, 0, -60 );
_SECTION_END();


Filter=C;

AddColumn(NF50basket, "sect.vol", 1.2);

I have modified the above Nz() with the following :

//Original line with custom calculation 1 --- which is working fine

NF50basket += Nz((Aux1*Aux2)/10000000)/100;// Nz converts Null to zero

//Modified line with custom calculation 3 - I think this input may be wrong in Nz()

NF50basket += Nz(five5DAvg);// Nz converts Null to zero

Thank you for sparing your precious time on this.

@fxshrat ....got the solution. please ignore my query. Thanks.

Got an idea from one of the post from @beppe. Thanks @beppe.

1 Like

The code you posted in #1 is not "my" code.

The code example(s) I posted are these ones here

So those look different than what you have there.


Instead of beppe idea (whatever that means) you should use StaticVarAdd without looping (as posted in thread of upper link) instead of iterating symbol list via AFL.

/// create composite via Analysis -> Scan
/// Set watchlist at "Apply to" -> "Filter"
/// derived from 
/// @link https://www.amibroker.com/guide/afl/staticvaradd.html
dp1 = Aux1*Aux2/1e9;
fivedAvg = Ref(MA(dp1, 5),-1);
Five5DAvg = SafeDivide(dp1,FiveDavg)*100;

if ( Status( "action" ) == actionScan ) {
	Buy = Sell = Short = Cover = 0;
	if ( Status( "stocknum" ) == 0 ) {
		//remove any earlier composite values
		StaticVarRemove( "~NF50basket" );
	}
	StaticVarAdd( "~NF50basket", Nz(Five5DAvg), True, 0);
}

// To plot in chart pane
NF50basket = StaticVarGet( "~NF50basket" );
Plot( NF50basket, "NF50basket", colorGreen, styleHistogram, Null, Null, 0, 0, -60 );

BTW, why are you doing this?

If you can do this:

fivedAvg = Ref(MA(dp1, 5),-1);

That one is not proper Filter assigment. Filter expects true/false. Price usually is always greater zero.
So this Filter = 1; will achieve same thing.


BTW, Your second post is pointless to anyone and for sure not a solution.

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