Error 61 occurs even though no % sign in the codes / file's / symbol's name

As I would like to retrieve the current numbers of position held, therefore I believe I need to use the custom backtest mode and I read that I have to add the statement at the top of my codes:

SetOption("UseCustomBacktestProc", True );

I then tried to press on the backtest button, the following error was generated even though I found there is no % specifier in the code snippet or file's or symbol's name:

Error 61.
The number of format specifier(s) (%) does not match the number of arguments passed.

Would someone know why this might happen? Thank you so much.

Error 61 (1)
Error 61 (2)

Just adding that line does not add custom backtest code on its own via magic.
You have to write/add actual custom backtest code in addition.
If you have done that then as usual to be reproduced by others you have to add fully reproducible code without missing variables.


You do not need to custom backtest code to retrieve number of positions.
They are stored in ~~~EQUITY symbol already.


Those printf lines are from "Profit Table" AFL of Report Charts folder.
There are probably NaN (not a number) returned in Chg and x.

1 Like

Thanks fxshrat. Let me try follow your advice first. I did add my original backtest logic codes below that code statement and I just found weird why it would generate the error by just adding one more line as my original codes are generating the backtest result appropriately. Sorry I am new to the custom backtest mode.

And as I would like to make use of the last bar's numbers of opened positions and the positions' symbol names to determine whether I would exit 1 of the 10 positions and buy a new position in the next bar, I believe I will still need to use CBT?

Again...

There isn't any custom backtest code in post #1!
Forum is not guessing game.
You have to follow forum rules if asking questions.

My response with info about open positions is response to your generalizing statement about retrieving open positions. It still stands as it is... to just retrieve open positions array you do not need CBT. Period.

If you want to do something more then you have to be specific.
But you weren't specific so we are in a loop again (-> how to ask good question)...

Besides your thread subject is about Error 61..
Where it comes from and what would be cause has been answered.

1 Like

Your code produces NULL in given Year change (probably because code does not make a single trade in a whole year).

To address that you can change lines 126-129 in 3. Profit Table.afl from:

        if ( x >= 0 )
            printf( "<b>%.1f%%</b></td>", x );
        else
            printf( "<font color='880000'><b>%.1f%%</b></font></td>", x );

to:

      if( NOT IsNull( x ) )
      {
        if ( x >= 0 )
            printf( "<b>%.1f%%</b></td>", x );
        else
            printf( "<font color='880000'><b>%.1f%%</b></font></td>", x ); 
      }
     else
          printf( "<b>N/A</b></td>" );

1 Like

Thank you Tomasz. I amended the codes and saved and then re-run the codes again and it still produces the same error messages as below:

image
image

This is my newly amended codes according to your advice:
image

  1. Use AFL Editor to edit AFL codes, not Notepad. Notepad may incorrectly save files as .txt (change extension).

  2. When posting the formula, please make sure that you use Code Tags (using </> code button) as explained here: How to use this site.

Using code button

Code tags are required so formulas can be properly displayed and copied without errors.

2 Likes

If you still get the error despite of having modified via AFL editor then also check for NaN.

if ( NOT IsNull( x ) AND NOT IsNan(x) ) 
{
        if ( x >= 0 )
            printf( "<b>%.1f%%</b></td>", x );
        else
            printf( "<font color='880000'><b>%.1f%%</b></font></td>", x ); 
} 
else 
          printf( "<b>N/A</b></td>" );

See example here

x = 0/0;

if ( NOT IsNull( x ) AND NOT IsNan(x) ) {
	printf( "%g", x);
} else
	printf( "x is Null or Nan.");

if x would be Null then AFAICS printf does not return error:

x = BeginValue(Ref(Day(),-1));

printf( "%g", x);

But it does if not a number:

x = 0 / 0;

printf( "%g", x);

Besides you got error for Chg variable too so you may have to modifiy there too.

1 Like

Thank you and Tomasz. I have successfully cleared the bugs by adding the codes for checking not null and not nan for both x and chg.

That is not what I see on my end. I can see printf correctly prints -1.#IND which means "indefinite".

UPDATE: Actually there is a difference between 32-bit version and 64-bit version. For some reason, 64-bit produces an error, while 32-bit version (that I checked first) produces NO error, and correctly outputs -1.#IND.
Apparently Microsoft VC6 and 2019 compilers produce mutually incompatible code.

Yes, the error message occurs on AB 64-bit.

34

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