InvestorsHub Logo
Followers 47
Posts 97
Boards Moderated 1
Alias Born 04/09/2002

Re: Tom K post# 109

Wednesday, 09/04/2002 11:05:47 AM

Wednesday, September 04, 2002 11:05:47 AM

Post# of 215
OK, I think I got it now

You ignore the -200 requirement after the Aroon rises above -50.

Understood; thanks for the clarification.

OK, then the last script I posted needs to be fixed. The new one produces exactly the same results (because the condition I have misunderstood has never really happened during the period of the backtesting) but it's better to have a fixed script than a buggy one. smile

Regards,
Vesselin

 
const AroonPeriod = 200;
const AroonHigh = 50;
const AroonLow = -50;
const Neutral = 0;
const CCIPeriod = 80;
const CCILow = -100;
const CCILower = -200;
const CCIHigh = 100;
const CCIHigher = 200;
const StopLoss = 5;

var AroonPane, CCIPane, AroonOsc, MyCCI : integer;
var Bar, StartBar, EndBar, BuyState, SellState : integer;

HideVolume;

CCIPane := CreatePane(60, False, True);
SetPaneMinMax(CCIPane, CCILower - 10, CCIHigher + 10);
MyCCI := CCISeries(CCIPeriod);
PlotSeries(MyCCI, CCIPane, #Black, #Thick);
DrawHorzLine(CCILow, CCIPane, #Red, #Thin);
DrawHorzLine(CCILower, CCIPane, #Red, #Thick);
DrawHorzLine(Neutral, CCIPane, #Red, #Dotted);
DrawHorzLine(CCIHigh, CCIPane, #Red, #Thin);
DrawHorzLine(CCIHigher, CCIPane, #Red, #Thick);
DrawLabel(GetDescription(MyCCI), CCIPane);

AroonPane := CreatePane(60, False, True);
SetPaneMinMax(AroonPane, AroonLow - 10, AroonHigh + 10);
AroonOsc := SubtractSeries(AroonUpSeries (#Close, AroonPeriod),
AroonDownSeries(#Close, AroonPeriod));
PlotSeries(AroonOsc, AroonPane, #Black, #Thick);
DrawHorzLine(AroonHigh, AroonPane, #Blue, #Thick);
DrawHorzLine(AroonLow, AroonPane, #Blue, #Thick);
DrawHorzLine(Neutral, AroonPane, #Black, #Dotted);
DrawLabel('Aroon Osc (' + IntToStr(AroonPeriod) + ')', AroonPane);

InstallStopLoss(StopLoss);

BuyState := 0;
SellState := 0;
StartBar := AroonPeriod;
EndBar := BarCount - 1;

for Bar := StartBar to EndBar do
begin
ApplyAutoStops(Bar);
if LastPositionActive then
begin
if PositionLong(LastPosition) then
begin
{ Long Position Exit Rules }
if GetSeriesValue(Bar, AroonOsc) < AroonHigh then
begin
if CrossUnderValue(Bar, MyCCI, CCIHigh) then
SellAtMarket(Bar + 1, LastPosition, 'Sell');
end
else
begin
case SellState of
0 :
if CrossOverValue(Bar, MyCCI, CCIHigher) then
SellState := 1; { Wait for a crossing below CCIHigh }
1 :
if CrossUnderValue(Bar, MyCCI, CCIHigh) then
SellAtMarket(Bar + 1, LastPosition, 'Sell Higher');
end;
end;
end
else { We have a Short position }
begin
{ Short Position Exit Rules }
if GetSeriesValue(Bar, AroonOsc) > AroonLow then
begin
if CrossOverValue(Bar, MyCCI, CCILow) then
begin
CoverAtMarket(Bar + 1, LastPosition, 'Cover & Buy');
BuyAtMarket(Bar + 1, '');
end;
end
else
begin
case BuyState of
0 :
if CrossUnderValue(Bar, MyCCI, CCILower) then
BuyState := 1; { Wait for a crossing above CCILow }
1 :
if CrossOverValue(Bar, MyCCI, CCILow) then
begin
CoverAtMarket(Bar + 1, LastPosition, 'Cover&Buy Lower');
BuyAtMarket(Bar + 1, '');
BuyState := 0;
end;
end;
end;
end;
end
else
begin
{ Long Position Entry Rules }
if GetSeriesValue(Bar, AroonOsc) > AroonLow then
begin
if CrossOverValue(Bar, MyCCI, CCILow) then
BuyAtMarket(Bar + 1, 'Buy');
end
else
begin
case BuyState of
0 :
if CrossUnderValue(Bar, MyCCI, CCILower) then
BuyState := 1; { Wait for a crossing above CCILow }
1 :
if CrossOverValue(Bar, MyCCI, CCILow) then
begin
BuyAtMarket(Bar + 1, 'Buy Lower');
BuyState := 0;
end;
end;
end;
{ Short Position Entry Rules }
if (GetSeriesValue(Bar, AroonOsc) < Neutral) and
(CrossUnderValue(Bar, MyCCI, CCILow)) then
ShortAtMarket(Bar + 1, 'Short');
end;
end;


Join the InvestorsHub Community

Register for free to join our community of investors and share your ideas. You will also get access to streaming quotes, interactive charts, trades, portfolio, live options flow and more tools.