AddToComposite - Problem with field "V"

I am having trouble reading ATC fields "V" and "1" at several places in my code. The other fields work OK.

I am creating data for number of issues greater than their Moving Average and storing in ATCs.
Iam doing this for sectors, Industry groups and Industries ... same issue with all.

    MA200     = MA( Close, 200 );
    MA100     = MA( Close, 100 );
    MA50	  = MA( Close,  50 );
    MA20	  = MA( Close,  20 );
    PB200     = Close > MA200;
    PB100     = Close > MA100;
    PB50      = Close > MA50;
    PB20      = Close > MA20;
    PBavg	  = (PB200 + PB100 + PB50) / 3;
    ATCname   = "~Ind-" + Industry + "-PBull";
	//
    AddToComposite( Close, ATCname, "C", atcFlagDefaults );     		// Normalization not required.
    AddToComposite( PB200, ATCname, "H", atcFlagDefaults );				// PB100
    AddToComposite( PB100, ATCname, "O", atcFlagDefaults );				// PB200
    AddToComposite( PB50,  ATCname, "L", atcFlagDefaults );				// PB50
    AddToComposite( PB20,  ATCname, "V", atcFlagDefaults );				// PB20
    AddToComposite( PBavg, ATCname, "1", atcFlagDefaults );				// PBaverage (200+100+50) / 3
    AddToComposite( issue_count, ATCname, "I", atcFlagDefaults );ype or paste code here

when I read the ATC using the code below, field "V" has seemingly random numbers

//File: ATCread Test
//Issue: Field "V"
//

Sector		= StrLeft(GICSID(0),2);

_N( ATCname          	= "~Sec-" + Sector + "-PBull" );
        Sec_PB200_0        	= Foreign( ATCname, "H" );					// Raw data
        Sec_PB100_0         = Foreign( ATCname, "O" );
        Sec_PB50_0        	= Foreign( ATCname, "L" );
        Sec_PB20_0          = Foreign( ATCname, "V" );
        Sec_PBavg_0         = Foreign( ATCname, "1" );					// PBavg (200 + 100 + 50) / 3
        Sec_PB_Count     	= Foreign( ATCname, "I" );
        Sec_PB200_1        	= Sec_PB200_0 / Sec_PB_Count * 100;			// Normalized to percentages
        Sec_PB100_1        	= Sec_PB100_0 / Sec_PB_Count * 100;
        Sec_PB50_1         	= Sec_PB50_0  / Sec_PB_Count * 100;
        Sec_PB20_1         	= Sec_PB20_0  / Sec_PB_Count * 100;
        Sec_PBavg_1        	= Sec_PBavg_0 / Sec_PB_Count * 100;
		//
        printf("PB20_0 - Sector " + sector + "  Count " + Sec_PB_Count + "  PB20_0 "  + Sec_PB20_0  + "  PB200_0 " + Sec_PB200_0 + "\n");
        printf("PB20_1 - Sector " + sector + "  Count " + Sec_PB_Count + "  PB20_1 "  + Sec_PB20_1  + "  PB200_0 " + Sec_PB200_1 + "\n");
        //printf("PB20   - Sector " + sector + "  Count " + Sec_PB_Count + "  PB20   "  + Sec_PB20    + "  PB200   " + Sec_PB200   + "\n");
        for (i=1; i <BarCount; i++)
        {
        _TRACE("Update Pbull-PB1 - i " + WriteVal(i,1.0) + "  COunt " + writeval(Sec_PB_Count,1.0) + "  PB20_0 " + writeval(Sec_PB20_0[i],1.0) + "  PB20_1 " + writeval(Sec_PB20_1[i],1.0));
        _TRACE("Update Pbull-PB2 - i " + WriteVal(i,1.0) + "  COunt " + writeval(Sec_PB_Count,1.0) + "  PB200_0 " + writeval(Sec_PB200_0[i],1.0) + "  PB200_1 " + writeval(Sec_PB200_1[i],1.0));

        }
        //
        //
		Plot(Sec_PB200_1,"Sec_PB200",coloryellow,styleThick);
		Plot(Sec_PB100_1,"Sec_PB100",colorblue,styleThick);
		Plot(Sec_PB50_1, "Sec_PB50", colorred,styleThick);
		Plot(Sec_PB20_1, "Sec_PB20", colorviolet,styleThick); 
		Plot(Sec_PBavg_1,"Sec_PBavg",colorwhite,styleThick); 
		Plot(50,"",colorblack,styleLine|stylenolabel); type or paste code here

The plot results below. The yellow, blue and red lines are OK. The purple line (field "V") is way above what it should be. The white line (field "1") is an average, also way too high.
image

What VERSION are you using?

Win 7
Amibroker 6.30.0

The problem described above shifted to another field, for a short period of time, in one of my indicators ... and after a couple of hours of no activity on computer .... it has cleared up.

Indicators now read ATC correctly.

This kind of issue is very troubling as erroneous results can happen that are not detectable.

Any suggestions?

A little more detail ...

  • The ATCs read by a different diagnostic routine seemed OK
  • Program reading ATC that showed problems had data where data should be null, such as:
    MA20 = MA(Close,20);
    PB20 = Close > MA20;
    AddtoComposite(PB20,"ATCname,"V");

The erroneous data in ATC started appearing before bar #20 ... before data for MA20 was possible.

Use Nz() function to convert Nulls to zero, before AddToComposite http://www.amibroker.com/f?nz

1 Like

I am getting some math errors .... doing same operation on same numbers at different place in array produces different results.

  • Program reads values of sector parameters from ATC - example: number of issues > than 20 bar moving average and number of issues in sector)
  • Converts them to percentile (value / number of issues x 100)
  • Results for similar starting values of both variables produce different results

Code below highlights item analyzed
image

Results for 3 bars at different point in array are shown below produced by printf():

bar # 531 variable PB 20 = 99. Conversion to percentile results to 60.7
image

bar # 3482 variable PB 20 = 99. Conversion to percentile results to 43
image

bar # 4683 variable PB 20 = 99. Conversion to percentile results to 38.4
image

There seems to be a trend in that the bars closer to start of array have large errors and error gets smaller toward the end of array

Print statement for above

		for (i=4683; i <4684; i++)
        {
        printf("PB20_0  - i " + WriteVal(i,1.0) + "  Sector " + sector + "  Count " + Sec_PB_Count + "  PB20_0 "   + WriteVal(Sec_PB20_0[i],1.1)   + "  PB20_1 "  + WriteVal(Sec_PB20_1[i],1.1) + "\n");
        printf("PB50_0  - i " + WriteVal(i,1.0) + "  Sector " + sector + "  Count " + Sec_PB_Count + "  PB50_0 "   + WriteVal(Sec_PB50_0[i],1.1)   + "  PB50_1 "  + WriteVal(Sec_PB50_1[i],1.1) + "\n");
        printf("PB100_0 - i " + WriteVal(i,1.0) + "  Sector " + sector + "  Count " + Sec_PB_Count + "  PB100_0 "  + WriteVal(Sec_PB100_0[i],1.1)  + "  PB100_1 " + WriteVal(Sec_PB100_1[i],1.1) + "\n");
		}type or paste code here

Learn to debug YOUR stuff yourself:

The program works 100% correctly.
There are no "math errors". Everything is done by hardware float point unit which is part of CPU. So it JUST WORKS. CPUs are deterministic and results are THE SAME as long as INPUT is the same. You get different results only if INPUT changes.

Any "issues" that you created yourself are just your lack of understanding of what is going on with your code and how functions work. And you can only help yourself by trying harder to understand what you wrote.
Use handy calculator, do the math in hand or in Excel and just make yourself aware of your own mistakes.