It's not great but I'm just getting started in wealth-lab. basically it shorts hammers in a bear market and buy them in a bull market. maybe some of you guys can play with it and improve it..
Code:
{#OptVar2 100;10;100;5}
{#OptVar3 10;10;100;5}
{#OptVar1 6;1;30;1}
var Bar: integer;
var stop: float;
//InstallTimeBasedExit( #OptVar1 );
SetAutoStopMode( #AsPoint );
InstallProfitTarget( 0.0350 );
InstallStopLoss( 0.0100 );
//InstallTrailingStop( 0.0100, 30 );
function LS( i: integer ): float;
begin
Result := PriceOpen(i) - PriceLow(i);
end;
function Hammer: boolean;
begin
var B, US: float;
B := PriceClose (Bar) - PriceOpen (Bar);
US := PriceHigh( Bar ) - PriceClose (Bar);
Result := ( PriceClose (Bar) > PriceOpen (Bar)) and
( LS (Bar) > 2 * B) and ( LS (Bar) > US );
{and
{ LS of Hammer longer than LSes of last 3 candles }
// ( LS (Bar) > LS (Bar - 1)) and ( LS (Bar) > LS (Bar - 2)) and ( LS (Bar) > LS (Bar - 3)) and
{ Low of Hammer lower than Lows of last 3 candles }
// ( PriceLow (Bar) < PriceLow (Bar - 1)) and ( PriceLow (Bar) < PriceLow (Bar - 2)) and
// ( PriceLow (Bar) < PriceLow (Bar - 3));
end;
PlotSeries( EMASeries (#Close, 200), 0, #Blue, #Thick );
for Bar := 20 to BarCount - 1 do
begin
ApplyAutoStops( Bar );
if not LastPositionActive then begin
if Hammer() {and ( PriceClose (Bar) < EMA( Bar, #Close, 1600 ))} and
( GetYear( Bar ) < 2002 )
then
if ShortAtLimit( Bar+1, ( PriceHigh (Bar) + 0.0001), '' )
then stop := 2 * PriceHigh ( Bar ) - PriceLow ( Bar );
if Hammer() {and ( PriceClose (Bar) < EMA( Bar, #Close, 1600 ))} and
( GetYear( Bar ) >= 2002 ) then BuyAtStop( Bar+1, ( PriceHigh (Bar) + 0.0001), '' );
end;
//else CoverAtStop( Bar+1, Highest( Bar, #High, 3 ), LastPosition, '');
end;