Found this ela Strategy in a book and can not compile it.
Posted: 06 Jan 2011
Produces the error, expecting bars.
Strategy:
Inputs: Price1(Close of data3), Price2(Close of data4), StandartDev(1.5), Lenght(30), Equity(100000), RiskModel(3), RiskPercent(2.0), RiskATR(1.0),LogTrades(False),LogFile("Orders.txt");
Variables: N(0), HV1(0), HV2(0), CV(0), VolBand(0), VolConstant(0.0523),UpperBand(0), LowerBand(0), Spread(0);
if date <> date[1] then begin
N=LOCGetSharesFunc(Equity, RiskModel, RiskPercent, RiskATR) of data3;
HV1= LOCVolatilityFunc(Lenght) of data3;
HV2= LOCVolatilityFunc(Lenght) of data4;
CV= Correlation(Price1, Price2, Lenght);
VolBand=VolConstant*(HV1+HV2)*(1-CV);
UpperBand=StandartDev*VolBand;
LowerBand=StandartDev*(-VolBand);
end;
Spread = ((Close of data1 / Price1) -(Close of data2 / Price2));
if Spread crosses_above LowerBand then
Buy("LOCPT LE") n shares next bar at market;
if Spread crosses_above 0 then
sell("LOCPT LX+") next bar at market
else if Spread <= StandartDev*LowerBand then
Sell("LOCPT LX-") next bar at market;
if Spread crosses_below UpperBand then
sellshort("LOCPT SE") n shares next bar at market;
If Spread crosses_below 0 then
buy("LOCPT SX+") next bar at market
else if Spread >= StandartDev*UpperBand then
buy("LOCPT SC-") next bar at market;
Function:
Inputs: Lenght(Numeric);
variables: DaysInYear(365),DaysInMonth(30),DaysInWeek(7),TimeFactor(0.0);
LOCVolatilityFunc=0;
if close>0 and close[1]>0 then begin
if datacompression>=2 and datacompression <5 then begin
if datacompression =2 then
TimeFactor=DaysInYear
else if datacompression=3 then
TimeFactor=DaysInYear/DaysInWeek
else if datacompression=4 then
TimeFactor=DaysInYear/DaysInMonth;
LOCVolatilityFunc=StdDev(Log(Close/Close[1]), Lenght)*SquareRoot(TimeFactor);
end;
end;
Inputs: Equity(numeric),RiskModel(numeric),RiskPercent(numeric),RiskUnits(numeric);
Variables: MinimumShares(200),RiskShares(0),ERP(0),Lenght(20);
ERP= Equity*RiskPercent/100;
If RiskModel=1 and Close>0 then
RiskShares=maxlist(MinimumShares,100*IntPortion(Equity/(100*Close)));
If RiskModel=2 and RiskUnits>0 then
RiskShares=maxlist(MinimumShares,100*IntPortion(Equity/(100*RiskUnits)));
If RiskModel=3 and Volatility(Lenght)>0 then
RiskShares=maxlist(MinimumShares,100*IntPortion(Equity/(100*Volatility(Lenght))));
Strategy:
Inputs: Price1(Close of data3), Price2(Close of data4), StandartDev(1.5), Lenght(30), Equity(100000), RiskModel(3), RiskPercent(2.0), RiskATR(1.0),LogTrades(False),LogFile("Orders.txt");
Variables: N(0), HV1(0), HV2(0), CV(0), VolBand(0), VolConstant(0.0523),UpperBand(0), LowerBand(0), Spread(0);
if date <> date[1] then begin
N=LOCGetSharesFunc(Equity, RiskModel, RiskPercent, RiskATR) of data3;
HV1= LOCVolatilityFunc(Lenght) of data3;
HV2= LOCVolatilityFunc(Lenght) of data4;
CV= Correlation(Price1, Price2, Lenght);
VolBand=VolConstant*(HV1+HV2)*(1-CV);
UpperBand=StandartDev*VolBand;
LowerBand=StandartDev*(-VolBand);
end;
Spread = ((Close of data1 / Price1) -(Close of data2 / Price2));
if Spread crosses_above LowerBand then
Buy("LOCPT LE") n shares next bar at market;
if Spread crosses_above 0 then
sell("LOCPT LX+") next bar at market
else if Spread <= StandartDev*LowerBand then
Sell("LOCPT LX-") next bar at market;
if Spread crosses_below UpperBand then
sellshort("LOCPT SE") n shares next bar at market;
If Spread crosses_below 0 then
buy("LOCPT SX+") next bar at market
else if Spread >= StandartDev*UpperBand then
buy("LOCPT SC-") next bar at market;
Function:
Inputs: Lenght(Numeric);
variables: DaysInYear(365),DaysInMonth(30),DaysInWeek(7),TimeFactor(0.0);
LOCVolatilityFunc=0;
if close>0 and close[1]>0 then begin
if datacompression>=2 and datacompression <5 then begin
if datacompression =2 then
TimeFactor=DaysInYear
else if datacompression=3 then
TimeFactor=DaysInYear/DaysInWeek
else if datacompression=4 then
TimeFactor=DaysInYear/DaysInMonth;
LOCVolatilityFunc=StdDev(Log(Close/Close[1]), Lenght)*SquareRoot(TimeFactor);
end;
end;
Inputs: Equity(numeric),RiskModel(numeric),RiskPercent(numeric),RiskUnits(numeric);
Variables: MinimumShares(200),RiskShares(0),ERP(0),Lenght(20);
ERP= Equity*RiskPercent/100;
If RiskModel=1 and Close>0 then
RiskShares=maxlist(MinimumShares,100*IntPortion(Equity/(100*Close)));
If RiskModel=2 and RiskUnits>0 then
RiskShares=maxlist(MinimumShares,100*IntPortion(Equity/(100*RiskUnits)));
If RiskModel=3 and Volatility(Lenght)>0 then
RiskShares=maxlist(MinimumShares,100*IntPortion(Equity/(100*Volatility(Lenght))));