EasyLanguage code such as this:

```
Variables: ..., Frac1(0), ....;
....
....
Frac1 = IFF( Value2 > 0, 100 * ( xMACD - Value1 ) / Value2, Frac1[1]);
```

Can be translated to AFL via...

Loop version:

```
Frac1 = 0;
for ( i = 1; i < BarCount; i++ ) {
prev = Frac1[ i - 1 ];// previous bar's Frac1
Frac1[ i ] = IIf(Value2[ i ] > 0, 100 * ( xMACD[ i ] - Value1[ i ] ) / Value2[ i ], prev );
}
```

Non-Loop version (-> AFL array processing):

```
Frac1 = ValueWhen(Value2 > 0, 100 * ( xMACD - Value1 ) / Value2);
```

Or just preventing infinite bar result or division by zero via:

```
Frac1 = 100 * Nz(( xMACD - Value1 ) / Value2, 0);
```

or

```
Frac1 = 100 * ( xMACD - Value1 ) / (Value2+1e-9);
```

As for RestorePriceArrays()... actually it is need to be called just once within that upper posted function (to restore original price arrays again if needed in further code).

So...

```
function SchaffTC(period, s_len, l_len) {
/// Schaff Trend Cycle
/// AFL version by fxshrat@gmail.com
/// @link https://forum.amibroker.com/t/schaff-trend-indicator-stc/13355/6
local MCD, Frac1, Frac2, PF, PFF;
MCD = MACD(s_len, l_len);
//StochK of MACD
C = H = L = MCD;
Frac1 = StochK(period, 1);
//Smoothed calculation
PF = AMA(frac1, factor = 0.5);
//StochK of PF
C = H = L = PF;
Frac2 = StochK(period, 1);
RestorePriceArrays();
//Smoothed calculation
PFF = AMA(frac2, factor);
return PFF;
}
period = Param("Schaff Period", 10, 1, 100, 1);
short_period = Param("Short Period", 23, 1, 100, 1);
long_period = Param("Long Period", 50, 1, 100, 1);
Schaff = SchaffTC(period, short_period, long_period);
Plot(Schaff,"Schaff Trend Cycle", colorRed, styleLine);
```