Fractal Indicator Strategy (Amibroker And Tradestation Code)

The original article can be found here.

The strategy in plain English:

Generally speaking, a bullish fractal happens when there are two higher low bars on each side of a candlestick or price bar. A bearish fractal happens when there are two lower highs on each side.

Amibroker code:

The code below exits by using a time stop between 1 and 10 days:

//bullish fractal

oddis=Optimize("Trading day",10,1,10,1);


Buy = Ref(L,-2)<Ref(L,-4) AND Ref(L,-2)<Ref(L,-3) AND Ref(L,-2) <Ref(L,-1) AND Ref(L,-2)<l 
;
buyPrice = Close;
Sell = 0;
sellPrice = Close ;
applyStop(stopTypeNBar,stopModeBars,oddis,1);
//bearish fractal

oddis=Optimize("Trading day",10,1,10,1);

Buy = Ref(h,-2)<Ref(h,-4) AND Ref(h,-2)<Ref(h,-3) AND Ref(h,-2) <Ref(h,-1) AND Ref(h,-2)<l
;
buyPrice = Close;
Sell = 0;
sellPrice = Close ;
applyStop(stopTypeNBar,stopModeBars,oddis,1);

Tradestation code:

Bullish:

{
Strategy - Bullish fractal
https://www.quantifiedstrategies.com/lessons/fractal-indicator-strategy-amibroker-code/
}

Inputs:
	HoldBars(10);

if L[2] < L[4] AND L[2] < L[3] AND L[2] < L[1] AND L[2] < L Then
	buy this bar on close;

if Barssinceentry(0) >= HoldBars Then
	sell this bar on close;

Bearish:

{
Strategy - Bearish fractal
https://www.quantifiedstrategies.com/lessons/fractal-indicator-strategy-amibroker-code/
}

Inputs:
	HoldBars(10);

if H[2] > H[4] AND H[2] > H[3] AND H[2] > H[1] AND H[2] > H Then
	buy this bar on close;

if Barssinceentry(0) >= HoldBars Then
	sell this bar on close;