// Downloaded From https://www.WiseStockTrader.com
// Four Model by Martin Zweig's
// See Zweig Book: Martin Zweig's Winning with New IRAs, pages 117-128
// Translated to AFL by Xavier 
// Model was designed to be applied toa weekly chart of the Value Line Composite index ( VLCI)
// Program uses a the weekly close of the VLCI to initate trades
// Buy if the weekly close of the VLCI rises 4% or more from its lowest close ( since the last sell signal)
// Sell if the weekly close of the VLCI falls 4% or more from its highest close ( since the last buy signal)

perOffLo = Param("% off lowest close", 4,1, 10);
perOffHi = Param("% off highest close", 4,1, 10);
trend = 0;
HC = LC = C[0];

for( i =0; i < BarCount ; ++i)
{
	if ( trend == 0)
	{
		if (((C[i] - LC) / LC) >= (perOffLo / 100))
		{
			trend = 1;
		}
		if (((HC - C[i] ) / HC) >= (perOffLo / 100)) 
		{
			trend = -1;
		}
	}
	else if ( trend == 1 AND ((HC - C[i]) / HC) >= (perOffHi / 100)) 
	{
		Sell[i] = 1;
		trend = -1;
		LC = C[i];
	}
	else if ( trend == -1 AND ((C[i] - LC) / LC) >= (perOffLo / 100)) 
	{
		Buy[i] = 1;
		trend = 1;
		HC = C[i];
	}
	
	if ( C[i] < LC) LC = C[i];
	if ( C[i] > HC) HC = C[i];
}