Non-ASCII chars in formula cause AFL code Error code 32

TDay = abs(C-O) <= (C*SmallBodyMaxSize) OR (abs(O-C)<=((H-L)*0.1));
YDay = abs(Ref ( C, -1)-Ref(O,-1)) <= Ref ( C, -1) *SmallBodyMaxSize 
	OR 
		abs (Ref ( O, -1)-Ref(C,-1)) <= (Ref ( H, -1 ) – Ref ( L, -1 ) )*0.1;

The above statement generates "error 32 unexpected $end. Is there a semicolon missing at the end of the previous line?"
I just cannot see the cause of the error. Would appreciate help to identify.

Syntax Error, Unexpected $end usually means that you have unbalanced parenthesis or curly brace.

In your code however, you were the victim of weird encoding. You have pasted this code from somewhere (maybe Word) that uses invalid codes and this single character is NOT minus sign, even if it looks like minus, it is char code 0x96 (beyond normal ASCII) it looks like minus but it is not. It is dash.

abs (Ref ( O, -1)-Ref(C,-1)) <= (Ref ( H, -1 ) – Ref ( L, -1 ) )*0.1;
-----------------------------------------------^ THIS IS NOT MINUS!

Some non-text editors change minus sign for dash and that causes problems. Avoid using non-text editors.

It is easy to get lost when you type spaghetti code. Really you are using braces when they are NOT needed.
AFL has smart precedence rules that work fine and you don't need to type

somevalue = ( C > O ) AND ( H > Ref( H, - 1 ) );

AND has lower precedence than comparisons and you can just write

somevalue = C > O AND H > Ref( H, - 1 );

I have simplified your code to:

SmallBodyMaxSize = 0; // added by me since you did not include def in your post

TDay = abs( C - O ) <= C*SmallBodyMaxSize OR abs( O - C ) <= ( H - L ) * 0.1;
YDay = abs( Ref( C - O, -1 ) ) <= Ref( C, -1 ) * SmallBodyMaxSize
       OR
       abs( Ref( O - C, -1 ) ) <= Ref( H - L, -1 ) * 0.1;

Repetive statements like abs( C - O ) can be replaced by meaningful variable names making code much more readable. Also note that YDay variable code is really not necessary as it repeats the calculation just one day back. So use Ref() instead of re-doing all calcs.

SmallBodyMaxSize = 0; // added by me since you did not include def in your post

BodySize = abs( C - O ); // abs( C - O ) is really the same as abs( O - C )
TDay = BodySize <= C*SmallBodyMaxSize OR BodySize <= (H - L)* 0.1;
YDay = Ref( TDay, -1 ); // much simpler!
1 Like

Many thanks Tomasz for your prompt reply which I will closely examine and learn.

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