The instrument is ES 15min. Testing period is from contract start in 97 til Aug. 02. I will disclose the idea, the code, the performance stats and the equity curve picture.
The idea: We look for sequences of 3 red candles (C<O) and 3 green candles (C>O). We enter short on the break of the low of the third candle, vica versa for longs. The stop is equal to the highest high - lowest low of the 3 candle combo. Target is 0.5 of that amount. There's only 2 exits: at stop and at profit target. There's also a 200EMA filter (it greatly cuts down on number of trades without hurting profits). We require that the third candle's close be above/below 200EMA. The WealthLab code is below.
var bar, n, exitbar: integer;
var StopPrice, target, bepoint: float;
function RedSequence(bar: integer ): boolean;
begin
var z: integer;
z := bar - 1;
if (PriceClose(z)<PriceOpen(z)) and
(PriceClose(z-1)<PriceOpen(z-1)) and
(PriceClose(z-2)<PriceOpen(z-2)) then
Result := true;
end;
function GreenSequence(bar: integer ): boolean;
begin
var z: integer;
z := bar - 1;
if (PriceClose(z)>PriceOpen(z)) and
(PriceClose(z-1)>PriceOpen(z-1)) and
(PriceClose(z-2)>PriceOpen(z-2)) then
Result := true;
end;
for Bar := 4 to BarCount () - 1 do
BEGIN
if LastPositionActive () then // let's close position //
begin
// Closing short //
if PositionShort(LastPosition) then begin
// if PriceLow(bar)< bepoint then StopPrice := PositionBasisPrice(LastPosition)-0.25;
if PriceHigh(bar)> StopPrice then begin
CoverAtStop(bar, StopPrice, LastPosition, '');
exitbar := bar; end;
if PriceLow(bar)< target then begin
CoverAtLimit(bar, target, LastPosition, '' );
exitbar := bar; end;
end;
// Closing long //
if PositionLong(LastPosition) then begin
//if PriceHigh(bar)> bepoint then StopPrice := PositionBasisPrice(LastPosition);
if PriceLow(bar)< StopPrice then begin
SellAtStop(bar, StopPrice, LastPosition, '');
exitbar := bar; end;
if PriceHigh(bar)> target then begin
SellAtLimit(bar, target, LastPosition, '' );
exitbar := bar; end;
end;
end
// No position open - let's open one!
else begin
// If red sequence and triggered on this bar then do following
if RedSequence(bar) and (PriceLow(bar)<PriceLow(bar-1))
and (PriceClose(bar-1)<EMA(bar-1, #Close, 200))
then
begin
// Color chart background pink for three bars
for n := 1 to 3 do SetBackgroundColor(bar-n, #RedBkg);
ShortAtStop(bar, PriceLow(bar-1)-0.01, '');
StopPrice := Max(Max(PriceHigh(bar-1), PriceHigh(bar-2)), PriceHigh(bar-3)) + 0.01;
target := PositionBasisPrice(LastPosition) - 0.5*(StopPrice - Min(Min(PriceLow(bar-1), PriceLow(bar-2)), PriceLow(bar-3)));
bepoint := PositionBasisPrice(LastPosition) - 2*(StopPrice - Min(Min(PriceLow(bar-1), PriceLow(bar-2)), PriceLow(bar-3)));
end;
// If green sequence and triggered on this bar then do following
if GreenSequence(bar) and (PriceHigh(bar)>PriceHigh(bar-1))
and (PriceClose(bar-1)>EMA(bar-1, #Close, 200))
then
begin
// Color chart background lime for three bars
for n := 1 to 3 do SetBackgroundColor(bar-n, #GreenBkg);
BuyAtStop(bar, PriceHigh(bar-1)+0.01, '');
StopPrice := Min(Min(PriceLow(bar-1), PriceLow(bar-2)), PriceLow(bar-3)) - 0.01;
target := PositionBasisPrice(LastPosition) - 0.5*(StopPrice - Max(Max(PriceHigh(bar-1), PriceHigh(bar-2)), PriceHigh(bar-3)));
bepoint := PositionBasisPrice(LastPosition) - (StopPrice - Max(Max(PriceHigh(bar-1), PriceHigh(bar-2)), PriceHigh(bar-3)));
end;
end;
END;
The idea: We look for sequences of 3 red candles (C<O) and 3 green candles (C>O). We enter short on the break of the low of the third candle, vica versa for longs. The stop is equal to the highest high - lowest low of the 3 candle combo. Target is 0.5 of that amount. There's only 2 exits: at stop and at profit target. There's also a 200EMA filter (it greatly cuts down on number of trades without hurting profits). We require that the third candle's close be above/below 200EMA. The WealthLab code is below.
var bar, n, exitbar: integer;
var StopPrice, target, bepoint: float;
function RedSequence(bar: integer ): boolean;
begin
var z: integer;
z := bar - 1;
if (PriceClose(z)<PriceOpen(z)) and
(PriceClose(z-1)<PriceOpen(z-1)) and
(PriceClose(z-2)<PriceOpen(z-2)) then
Result := true;
end;
function GreenSequence(bar: integer ): boolean;
begin
var z: integer;
z := bar - 1;
if (PriceClose(z)>PriceOpen(z)) and
(PriceClose(z-1)>PriceOpen(z-1)) and
(PriceClose(z-2)>PriceOpen(z-2)) then
Result := true;
end;
for Bar := 4 to BarCount () - 1 do
BEGIN
if LastPositionActive () then // let's close position //
begin
// Closing short //
if PositionShort(LastPosition) then begin
// if PriceLow(bar)< bepoint then StopPrice := PositionBasisPrice(LastPosition)-0.25;
if PriceHigh(bar)> StopPrice then begin
CoverAtStop(bar, StopPrice, LastPosition, '');
exitbar := bar; end;
if PriceLow(bar)< target then begin
CoverAtLimit(bar, target, LastPosition, '' );
exitbar := bar; end;
end;
// Closing long //
if PositionLong(LastPosition) then begin
//if PriceHigh(bar)> bepoint then StopPrice := PositionBasisPrice(LastPosition);
if PriceLow(bar)< StopPrice then begin
SellAtStop(bar, StopPrice, LastPosition, '');
exitbar := bar; end;
if PriceHigh(bar)> target then begin
SellAtLimit(bar, target, LastPosition, '' );
exitbar := bar; end;
end;
end
// No position open - let's open one!
else begin
// If red sequence and triggered on this bar then do following
if RedSequence(bar) and (PriceLow(bar)<PriceLow(bar-1))
and (PriceClose(bar-1)<EMA(bar-1, #Close, 200))
then
begin
// Color chart background pink for three bars
for n := 1 to 3 do SetBackgroundColor(bar-n, #RedBkg);
ShortAtStop(bar, PriceLow(bar-1)-0.01, '');
StopPrice := Max(Max(PriceHigh(bar-1), PriceHigh(bar-2)), PriceHigh(bar-3)) + 0.01;
target := PositionBasisPrice(LastPosition) - 0.5*(StopPrice - Min(Min(PriceLow(bar-1), PriceLow(bar-2)), PriceLow(bar-3)));
bepoint := PositionBasisPrice(LastPosition) - 2*(StopPrice - Min(Min(PriceLow(bar-1), PriceLow(bar-2)), PriceLow(bar-3)));
end;
// If green sequence and triggered on this bar then do following
if GreenSequence(bar) and (PriceHigh(bar)>PriceHigh(bar-1))
and (PriceClose(bar-1)>EMA(bar-1, #Close, 200))
then
begin
// Color chart background lime for three bars
for n := 1 to 3 do SetBackgroundColor(bar-n, #GreenBkg);
BuyAtStop(bar, PriceHigh(bar-1)+0.01, '');
StopPrice := Min(Min(PriceLow(bar-1), PriceLow(bar-2)), PriceLow(bar-3)) - 0.01;
target := PositionBasisPrice(LastPosition) - 0.5*(StopPrice - Max(Max(PriceHigh(bar-1), PriceHigh(bar-2)), PriceHigh(bar-3)));
bepoint := PositionBasisPrice(LastPosition) - (StopPrice - Max(Max(PriceHigh(bar-1), PriceHigh(bar-2)), PriceHigh(bar-3)));
end;
end;
END;
