Syntax Error, Unexpected '}'

Here is my afl code:

SetTradeDelays(0, 0, 0, 0);
SetOption("InitialEquity", 1000000);
SetOption("ActivateStopsImmediately", True);
SetOption("AllowSameBarExit", True);
SetOption("MaxOpenPositions", 10);
SetOption("HoldMinBars", 1);
SetPositionSize(100000, spsValue);
RoundLotSize = 1;
TickSize = 0.05;

Buy = Short = Sell = Cover = 0;

stateVar = Name() + "_state";
isFirstDayBar = LastValue(DateNum() != Ref(DateNum(), -1));
if (isFirstDayBar == True) {
	_TRACEF("clearing state var for: %s at %g", Name(), TimeNum());
	StaticVarRemove(stateVar);
}

// Other strategy signals goes before here

shortLimitPrice = TickSize * round(shortLimitPrice / TickSize);
shortLimitPrice = Ref(shortLimitPrice, -1);
shortSig = Ref(shortSig, -1);

bi = LastValue(BarIndex());
if (shortSig[bi]) {
	state = StaticVarGet(stateVar);
	if (state == Null) {
		if (H[bi] >= shortLimitPrice[bi]) {
			StaticVarSet(stateVar, 1);
			Short[bi] = 1;
			ShortPrice[bi] = shortLimitPrice[bi]; // Add condition to enter on open if bigger
		}
	}
	else if (state == 1) {
		firstStopLossPrice = ShortPrice[bi] * (1 + stopLossPct/100);
		profitTarget = LastValue(Ref(C, -1));
		if (H[bi] > firstStopLossPrice) {
			Cover[bi] = 1;
			CoverPrice[bi] = firstStopLossPrice;
			StaticVarSet(stateVar, -1);
		}
		if (L[bi] <= profitTarget) {
			Cover[bi] = 1;
			CoverPrice[bi] = profitTarget;
			Short[bi] = 1;
			ShortPrice[bi] = profitTarget;
			StaticVarSet(stateVar, 2);
		}
	}
	else if (state == 2) {
		secondStopLossPrice = ShortPrice[bi] * (1 + stopLossPct/100);
		if (H[bi] > secondStopLossPrice) {
			Cover[bi] = 1;
			CoverPrice[bi] = secondStopLossPrice;
			StaticVarSet(stateVar, -1);
		}
		if (TimeNum()[bi] == 153000) {
			Cover[bi] = 1;
			CoverPrice[bi] = C;
			StaticVarSet(stateVar, 3);
		}
	}
}

I get error at line:
if (shortSig[bi]) {

The error is as follows:
Syntax error: Unexpected '}', is there semicolon missing at end of previous line?
image

Now I don't seem to be able to figure out this issue. As I don't see any errors which are apparent before this line. Your help will be appreciated.

Re-check your formula with AFL code editor. The first error is HIGHER / earlier in the code. In line 22 you are reading variable shortLimitPrice without initialization. These are real problems with your code:

image

But then line numbers in your screenshot tell me that you did NOT provide full formula in first place - don't do that. If you want help you must provide whole formula.

Here is the code with little modifications in the strategy part. Facing the same issue. But it is the complete code this time:

// My comment
SetTradeDelays(0, 0, 0, 0);
SetOption("InitialEquity", 1000000);
SetOption("ActivateStopsImmediately", True);
SetOption("AllowSameBarExit", True);
SetOption("MaxOpenPositions", 10);
SetOption("HoldMinBars", 1);
SetPositionSize(100000, spsValue);
RoundLotSize = 1;
TickSize = 0.05;

Buy = Short = Sell = Cover = 0;

// Auto Analysis runs every x sec on daily periodicity. Refresh state if new day begins.
stateVar = Name() + "_state";
refreshVar = Name() + "_refresh";
refreshSaved = StaticVarGetText(refreshVar);
// Assumes that timestamp setting is set to start of bar, so the signature doesn't change during the day.
refreshCurrent = NumToStr(LastValue(DateNum()), formatDateTime);

if (StrMatch(refreshSaved, refreshCurrent) == False) {
	_TRACEF("clearing: state var %s at %g", Name(), TimeNum());
	StaticVarRemove(stateVar);
	StaticVarSetText(refreshVar, refreshCurrent);
} else {
	_TRACEF("running during the day: state var %s at %g", Name(), TimeNum());
}


stopLossPct = 3;

adxLevel = Optimize("ADX_LEVEL", 25, 10, 40, 1);

HV10 = StDev(log(C / Ref(C, -1)), 10) * (252 ^ 0.5) * 100;

lmt = HV10 / 10;
lmt = IIf(lmt > 10, 10, IIf(lmt < 3, 3, lmt));
shortSig = C > 100;  // I have removed some of signal parameters but still facing the issues here
shortLimitPrice = C * (1 + lmt/100);
shortLimitPrice = TickSize * round(C / TickSize);
shortLimitPrice = Ref(shortLimitPrice, -1);
shortSig = Ref(shortSig, -1);

bi = LastValue(BarIndex());
if (shortSig[bi]) {
	state = StaticVarGet(stateVar);
	if (state == Null) {
		if (H[bi] >= shortLimitPrice[bi]) {
			StaticVarSet(stateVar, 1);
			Short[bi] = 1;
			ShortPrice[bi] = shortLimitPrice[bi]; // Add condition to enter on open if bigger
		}
	}
	else if (state == 1) {
		firstStopLossPrice = ShortPrice[bi] * (1 + stopLossPct/100);
		profitTarget = LastValue(Ref(C, -1));
		if (H[bi] > firstStopLossPrice) {
			Cover[bi] = 1;
			CoverPrice[bi] = firstStopLossPrice;
			StaticVarSet(stateVar, -1);
		}
		if (L[bi] <= profitTarget) {
			Cover[bi] = 1;
			CoverPrice[bi] = profitTarget;
			Short[bi] = 1;
			ShortPrice[bi] = profitTarget;
			StaticVarSet(stateVar, 2);
		}
	}
	else if (state == 2) {
		secondStopLossPrice = ShortPrice[bi] * (1 + stopLossPct/100);
		if (H[bi] > secondStopLossPrice) {
			Cover[bi] = 1;
			CoverPrice[bi] = secondStopLossPrice;
			StaticVarSet(stateVar, -1);
		}
		if (TimeNum()[bi] == 153000) {
			Cover[bi] = 1;
			CoverPrice[bi] = C;
			StaticVarSet(stateVar, 3);
		}
	}
}

image

@xterminator,

in line 77 of your previous post's code you have this one

if (TimeNum()[bi] == 153000) {// you are using subscript incorrectly here
			Cover[bi] = 1;
			CoverPrice[bi] = C;// you are assigning array to element
			StaticVarSet(stateVar, 3);
}

It is incorrect.

To remove error message modify to

tn = TimeNum();
if (tn[bi] == 153000) {// you were using subscript incorrectly here
			Cover[bi] = 1;
			CoverPrice[bi] = C[bi];// you were assigning array to element
			StaticVarSet(stateVar, 3);
}

So error message free (at least):

// My comment
SetTradeDelays(0, 0, 0, 0);
SetOption("InitialEquity", 1000000);
SetOption("ActivateStopsImmediately", True);
SetOption("AllowSameBarExit", True);
SetOption("MaxOpenPositions", 10);
SetOption("HoldMinBars", 1);
SetPositionSize(100000, spsValue);
RoundLotSize = 1;
TickSize = 0.05;

Buy = Short = Sell = Cover = 0;

// Auto Analysis runs every x sec on daily periodicity. Refresh state if new day begins.
stateVar = Name() + "_state";
refreshVar = Name() + "_refresh";
refreshSaved = StaticVarGetText(refreshVar);
// Assumes that timestamp setting is set to start of bar, so the signature doesn't change during the day.
refreshCurrent = NumToStr(LastValue(DateNum()), formatDateTime);

if (StrMatch(refreshSaved, refreshCurrent) == False) {
	_TRACEF("clearing: state var %s at %g", Name(), TimeNum());
	StaticVarRemove(stateVar);
	StaticVarSetText(refreshVar, refreshCurrent);
} else {
	_TRACEF("running during the day: state var %s at %g", Name(), TimeNum());
}


stopLossPct = 3;

adxLevel = Optimize("ADX_LEVEL", 25, 10, 40, 1);

HV10 = StDev(log(C / Ref(C, -1)), 10) * (252 ^ 0.5) * 100;

lmt = HV10 / 10;
lmt = IIf(lmt > 10, 10, IIf(lmt < 3, 3, lmt));
shortSig = C > 100;  // I have removed some of signal parameters but still facing the issues here
shortLimitPrice = C * (1 + lmt/100);
shortLimitPrice = TickSize * round(C / TickSize);
shortLimitPrice = Ref(shortLimitPrice, -1);
shortSig = Ref(shortSig, -1);
tn = TimeNum();
bi = LastValue(BarIndex());
if (shortSig[bi]) {
	state = StaticVarGet(stateVar);
	if (state == Null) {
		if (H[bi] >= shortLimitPrice[bi]) {
			StaticVarSet(stateVar, 1);
			Short[bi] = 1;
			ShortPrice[bi] = shortLimitPrice[bi]; // Add condition to enter on open if bigger
		}
	}
	else if (state == 1) {
		firstStopLossPrice = ShortPrice[bi] * (1 + stopLossPct/100);
		profitTarget = LastValue(Ref(C, -1));
		if (H[bi] > firstStopLossPrice) {
			Cover[bi] = 1;
			CoverPrice[bi] = firstStopLossPrice;
			StaticVarSet(stateVar, -1);
		}
		if (L[bi] <= profitTarget) {
			Cover[bi] = 1;
			CoverPrice[bi] = profitTarget;
			Short[bi] = 1;
			ShortPrice[bi] = profitTarget;
			StaticVarSet(stateVar, 2);
		}
	}
	else if (state == 2) {
		secondStopLossPrice = ShortPrice[bi] * (1 + stopLossPct/100);
		
		if (H[bi] > secondStopLossPrice) {
			Cover[bi] = 1;
			CoverPrice[bi] = secondStopLossPrice;
			StaticVarSet(stateVar, -1);
		}
		if (tn[bi] == 153000) {
			Cover[bi] = 1;
			CoverPrice[bi] = C[bi];
			StaticVarSet(stateVar, 3);
		}
	}
}
2 Likes

Thanks. I didn't realized that AFL doesn't allow such construct and the error message was being displayed so far above that it didn't leave any clue.