Error 61 Issues

I have been struggling with this issue for a couple of months now and have read everything I can on Error 61 and format specifiers. Still no luck resolving the issue which has been frustrating since this is such a heavily covered topic in the forum.

Basically I have three different spreadsheets that I use to bring data into Amibroker so that I can display the information in the interpretation window. In most situations it works fine but occasionally, I have a ticker that throws the Error 61 and when it does, I of course can't generate the correct output to the interpretation window nor am I able to get a chart of that ticker. The out put should look like this:

Screen Shot 2022-10-29 at 12.40.13 PM

The code to generate this output is:

_SECTION_BEGIN("IBD Interpretation");
//Designed by @rocketpower with modifcations by @MCassICT

EnableTextOutput (0);

// determine parameters
EMA10		= EMA(C,10);
EMA20		= EMA(C,20);
SMA200 		= MA(C, 200);
SMA150 		= MA(C, 150);
SMA050 		= MA(C,  50);
High52pct 	= HHV(C, 253);
Low52pct	= LLV(C, 253);
SMAV50		= MA(V,50);
RS          = StaticVarGet(Name() + "_RS");
_10up		= ((C - EMA10)/ C )*100;
_20up		= ((C - EMA20)/ C )*100;
_50up		= ((C - SMA050)/ C )*100;
_CTop		= ((C - SMA200)/ C )*100;
_CCHL		= ((H - L)/ H )*100;

Period_Lookback = Param("Period Lookback", 50, 3, 200, 1, 0);
period = Min(Period_Lookback,BarCount-1);
baseline = 1.00;
up = ROC(C,1)>0;
dn = NOT up;
upvol = Sum(up*V,period);
downvol = Sum(dn*V,period);
Up_Down_Ratio = SafeDivide(upvol,downvol);

//Stockbee  Anticipation Scan

AverageClose7 = MA(C, 7);
AverageClose65 = MA(C, 65);
VBar1 = Ref(V, -1);
VBar2 = Ref(V, -2);
VBar3 = Ref(V, -3);
DailyPerCentChange = (O - C)/ O *100;
TI65 = AverageClose7/AverageClose65;


//Stockbee MDT

MDT21 = C / MA(C,21);
MDT63 = C / MA(C,63);
MDT126 = C / MA(C,126);



//Index Parameters
IndexSP500 = Foreign("SPY", "C");
SP500MA50 = MA (IndexSP500 , 50);
SP500MA200 = MA (IndexSP500 , 200);
SP500Uptrend = SP500MA50 > SP500MA200 AND IndexSP500 > SP500MA200;


// Non nego MTP2019 p52
x1a = C  	 > SMA150 OR IsEmpty(SMA150);
x1b = C 	 > SMA200 OR IsEmpty(SMA200);
x2  = SMA150 > SMA200 OR IsEmpty(SMA200);
x3  = SMA200 > Ref(SMA200, -20) OR IsEmpty(SMA200);
x4a = SMA050 > SMA150 OR IsEmpty(SMA150);
x4b = SMA050 > SMA200 OR IsEmpty(SMA200);
x5  = C   	 > Low52pct*1.25;
x6  = C      > High52pct*0.75;
//x7  = RS     > 70;


UptrendStage = x1a AND x1b AND x2 AND x3 AND x4a AND x4b AND x5 AND x6;// AND x7;


EnableTextOutput (0);
printf(EncodeColor(colorBlack));

printf("<b>Last Earnings		Next Earnings</b>"	   + "\n");
printf(StaticVarGetText (Name() + "_LastEarningsDate") 		+ 		"              	                "		+	StaticVarGetText(Name() + "_NextEarningsDate")		+ "\n");

printf(EncodeColor(colorBlack));

_IPODate = ("IPODate:				" +StaticVarGet(Name()	+	"_IPODate")	+ "\n");
//_IPODate = StrReplace(_IPODate, "/", "//");
_PercentInsider = ("Insider Ownership:		" 				+ StaticVarGetText(Name() 	+ "_PercentInsider") 		+ "\n");
_PercentInsider = StrReplace(_PercentInsider, "%", "%%");
_PercentInstitutional = ("Institutional Ownership:		" 				+ StaticVarGetText(Name() 	+ "_PercentInstitutional") 		+ "\n");
_PercentInstitutional = StrReplace(_PercentInstitutional, "%", "%%");
_NumFunds = ("Number of Funds:		" +StaticVarGet(Name()	+	"_NumFunds")	+ "\n");
_Market_Cap = ("Market Cap:			" +StaticVarGet(Name()	+	"_Market_Cap")	+ "\n");
_Float = ("Float:				" +StaticVarGet(Name()	+	"_Float")	+ "\n");
_SharesOut = ("Shares Outstanding:		" +StaticVarGet(Name()	+	"_SharesOut")	+ "\n");
printf(_IPODate);
printf(_PercentInsider);
printf(_PercentInstitutional);
printf(_NumFunds);
printf(_Market_Cap);
printf(_Float);
printf(_SharesOut);




printf("--------------------<b>Trend</b>-----------------------"     + "\n");


EnableTextOutput (0);

//Earnings Surprise parameter data from BarChart.com

_LQESurprise = ("Recent Surprise:			"	    + StaticVarGet(Name() 	+	"_LQESurprise")	+ "\n");
_LQESurprise = StrReplace(_LQESurprise, "%", "%%");
_SecondQESurprise = ("Surprise 2 Qtrs Ago:		"		+ StaticVarGet(Name() 	+ "_SecondQESurprise") 	+ "\n");
_SecondQESurprise = StrReplace(_SecondQESurprise, "%", "%%");
_ThirdQESurprise = ("Surprise 3 Qtrs Ago:		"		+ StaticVarGet(Name() 	+ "_ThirdQESurprise") 	+ "\n");
_ThirdQESurprise = StrReplace(_ThirdQESurprise, "%", "%%");
_FourthQESurprise = ("Surprise 4 Qtrs Ago:		"		+ StaticVarGet(Name() 	+ "_FourthQESurprise") 	+ "\n\n");
_FourthQESurprise = StrReplace(_FourthQESurprise, "%", "%%");

_CR = ("Composite Rating:		" +StaticVarGet(Name()	+	"_CR")	+ "\n");
_EPS = ("EPS Rating:			" +StaticVarGet(Name()	+	"_EPS")	+ "\n");
_RS = ("RS Rating:			" +StaticVarGet(Name()	+	"_RS")	+ "\n\n");
_IGRS = ("Ind Grp RS Rating:			" +StaticVarGet(Name()	+	"_IGRS")	+ "\n");
_SMR = ("SMR Rating:			" +StaticVarGet(Name()	+	"_SMR")	+ "\n");
_AD = ("Acc/Dis Rating:			" +StaticVarGet(Name()	+	"_AD")	+ "\n");
_SPON = ("Sponsorship Rating:		" +StaticVarGet(Name()	+	"_SPON")	+ "\n\n");
_IndGrpRnk = ("Industry Grp Rank:		" +StaticVarGet(Name()	+	"_IndGrpRnk")	+ "\n");
_PE = ("P/E Ratio:			" +StaticVarGet(Name()	+	"_PE")	+ "\n\n");
_LQEPS = ("Last Qtr EPS Growth:		"		+ StaticVarGet(Name() 	+ "_LQEPS") 	+ "%%\n");
_CQEPSEst = ("Curr Qtr EPS Est Growth:		"	+ StaticVarGet(Name() 	+ "_CQEPSEst") 	+ "%%\n");
_CYEPSEst = ("Curr Year EPS Est Growth:		"	+ StaticVarGet(Name() 	+ "_CYEPSEst") 	+ "%%\n");
_LQSales = ("Last Qtr Sales Growth:		"		+ StaticVarGet(Name() 	+ "_LQSales") 	+ "%%\n\n");

_EarningsSalesHead = ("		<b>EPS	        Sales Growth</b>"	   + "\n");	
_Q1 = ("Recent: " + " 		 "  				+StaticVarGetText (Name() + 	"_RecentEPS") 		+ 		"              	"	+	StaticVarGetText(Name() + "_SalesQ")		+ "\n");
_Q1 = StrReplace(_Q1, "%", "%%" );
_Q2 = ("2 Qtr Ago:"	+ "	"	   			+StaticVarGetText (Name() + 	"_2QtrEPS") 		+ 		"	        	"	+	StaticVarGetText(Name() + "_SalesQ1")		+ "\n");
_Q2 = StrReplace(_Q2, "%", "%%" );
_Q3 = ("3 Qtr Ago:" + "	"	   			+StaticVarGetText (Name() + 	"_3QtrEPS") 		+ 		"  	                 "	+	StaticVarGetText(Name() + "_SalesQ2")		+ "\n");
_Q3 = StrReplace(_Q3, "%", "%%" );
_Q4 = ("4 Qtr Ago:" + "	"	   			+StaticVarGetText (Name() + 	"_4QtrEPS") 		+ 		"      	                "	+	StaticVarGetText(Name() + "_SalesQ3")		+ "\n");
_Q4 = StrReplace(_Q4, "%", "%%" );
_52wHigh = ("52 Week High:" + "			" +StaticVarGetText (Name() +	"_52wHigh")	+ "\n");
_52wLow = ("52 Week Low:" + "			" +StaticVarGetText (Name() +	"_52wLow")	+ "\n");

EnableTextOutput (1);
WriteIf (SP500Uptrend, EncodeColor ( colorGreen ) + "<b>Overal Market is Bullish</b>", EncodeColor ( colorRed ) + "<b>Overall Market is Bearish</b>");
WriteIf (UptrendStage, EncodeColor ( colorGreen ) + "<b>Stock is in a Stage 2 Uptrend</b>", EncodeColor ( colorRed ) + "<b>Stock in not Stage 2 Uptrending</b>");
WriteIf (_CTop < 70 , EncodeColor ( colorGreen ) + "Price is" + NumToStr (_CTop) + "% "  + "in relation to the 200 MA", EncodeColor ( colorRed )  + "<b>Price is" + NumToStr (_CTop) + "%"  +  " in relation to the 200 MA" );
printf("                                                          "     + "\n");

printf("<b>MDT21	  MDT63	      MDT126	TI65</b>" + "\n");
TestTrend = StrFormat("   %.2f	     %.2f 	          %.2f 	%.2f", MDT21, MDT63, MDT126, TI65 );
printf("\n");


EnableTextOutput (2);
printf(EncodeColor(colorBlack));
printf("ADR:	"		+ ADR20	+	"%%" + "	" + 	"ATR:	"		+ ATR20	+	"%%" +	"\n\n");

printf("Current Candle H/L Range:		"		+ _CCHL + "%%" +	"\n");
printf("Up/Down Ratio:		" + 	StrFormat("	%.2f",Up_Down_Ratio) + "\n\n");
printf(_52wHigh);
printf(_52wLow);
printf("-----------------<b>IBD eTables</b>------------------"     + "\n");
printf("<b>CR    EPS    RS  	      IND   SMR   A/D   Spon	</b>" + "\n");
printf(" "+ staticvargettext (Name() + "_CR") + "     " + staticvargettext (Name() + "_EPS") + "      " + staticvargettext (Name() + "_RS") + "     	        " + staticvargettext (Name() + "_IGRS") + "         " + staticvargettext (Name() + "_SMR") + "        " + staticvargettext (Name() + "_AD") + "         " + staticvargettext (Name() + "_SPON") + "\n\n");

printf(_IndGrpRnk);
printf(_PE);


printf("----<b>Quarterly Sales Growth and Earnings</b>-----"     + "\n");
printf(_EarningsSalesHead);	
printf(_Q1);
printf(_Q2);
printf(_Q3);
printf(_Q4);
printf("\n");
printf(_LQEPS);
printf(_CQEPSEst);
printf(_CYEPSEst);
printf(_LQSales);

printf("----<b>Weighted Alpha and Earnings Surprises</b>-----"     + "\n");

printf("Weighted Alpha:			" 	+ StaticVarGet(Name() 	+ "_WeightedAlpha") + "\n");
printf(_LQESurprise);
printf(_SecondQESurprise);
printf(_ThirdQESurprise);
printf(_FourthQESurprise);



_SECTION_END();

The data is coming from these spreadsheets and I have highlighted one of the tickers that is causing an issue:

Screen Shot 2022-10-29 at 12.36.46 PM

Screen Shot 2022-10-29 at 12.38.40 PM

Screen Shot 2022-10-29 at 12.39.39 PM

The output that I am currently getting is this:

Screen Shot 2022-10-29 at 12.34.10 PM

Screen Shot 2022-10-29 at 12.33.42 PM

The error in this instance is calling out an issue in the line that outputs FLOAT but on other occasions for some tickers, it might call it out because of the 52weekhigh, so I am not sure what is going on here. I have checked the spreadsheets and compared the working tickers against the ones that are throwing the error and I am not seeing any format differences. Any ideas anyone might have would be appreciated. As for how often this is happening I cant really say but I would estimate that for every watchlist I make of 20-30 names, there are always 1-2 tickers causing a problem. I look forward to hearing any ideas you might have.

@MCassICT, the error indicates that the output string contains a formatting identifier and there is no corresponding data to print. (In your case, when there are no errors, the string should not contain them but just be simple strings).
I would double-check the code that imports (and creates the static variables) from the spreadsheets (are you saving them in .csv or importing directly from Excel via vbscript / ole?).
In the first case, examine the exported .csv files when you get the error. Are there any unexpected sequences of % characters on the offending ticker?

6 Likes

Please read what was is written in KB already

And check the output of the static variables via _Trace.

2 Likes

Well it looks like I solved it. Thanks for your help @beppe and @fxshrat . As I was scrolling through charts this morning the same thing happened with RIVN but instead of float it was on the 52weekhigh, like I mentioned previously. I hadnt had a chance to run through things with TRACE yet but went ahead and opened the spreadsheet providing that data and just quickly changed the cell format to NUMBER, saved it, and then pulled it back into Amibroker. Just that simple change took care of the problem. Thanks again.

Recently I ran in a similar problem, not directly related to @MCassICT issue, with an easy solution that I will explain here below.

If some of your charts define the Title as per the way described in this KB article, i.e.

_N(Title = StrFormat("{{NAME}} - " + FullName() +
   " - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +
   WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

you will get an "Error 61" in case FullName() returns a string that contains a % sign, like it may happen with corporate notes like this one, quoted on Nasdaq (AAIN):

Arlington Asset Investment Corp 6.000% Senior Notes Due 2026

To fix the issue, simply change the Title assignment as follows:

_N(Title = StrFormat("{{NAME}} - %s - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +
   WriteVal( V, 1.0 ) +" {{VALUES}}", FullName(), O, H, L, C, SelectedValue( ROC( C, 1 )) ));
1 Like

As usual this is all not required at all.
As you just need to use {{FULLNAME}}.

_N(Title = StrFormat("{{NAME}} - {{FULLNAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol %g {{VALUES}}", 
					O, H, L, C, SelectedValue( ROC( C, 1 )), V ));

... And no Error 61.

2 Likes

First string in StrFormat is a formatting sequence. If you ever need to print a string you should use %s as formatting sequence and string to be printed as subsequent argument.

1 Like