Dow Theory Strategy (Amibroker And Tradestation Code)
The original article can be found here.
The strategy in plain English:
If Dow Jones Industrial sets a new 20-day high of the close (and Dow Jones Transport does not), what is the return of the Dow Jones Transport for the next 2-20 days?
Amibroker code:
fremmed=Foreign(“DIA”,”C”,fixup=1);
oddis=Optimize(“exit after N-days”,20,2,20,2);
Buy = fremmed>Ref(HHV(fremmed,20),-1) AND C<Ref(HHV(C,20),-1);
BuyPrice=Close;
Sell = 0 ;
SellPrice=Close;
ApplyStop(stopTypenbar,stopModeBars,oddis,1);
Tradestation code:
{
Strategy 122 - Dow Theory strategy
The strategy in plain English:
If Dow Jones Industrial sets a new 20-day high of the close (and Dow Jones Transport does not),
what is the return of the Dow Jones Transport for the next 2-20 days?
The first (default) data chart should be for symbol IYT or similar ETF tracking Dow Jones Transportation Average
The second symbol should be DIA
Add the second symbol DIA as the second data chart:
Activate a Chart Analysis window. From the menu, click Data > Add Symbol, type-in symbol name and click Plot
}
Inputs:
Lookback(20),
HoldBars(20);
Vars:
DIAClose(0);
Once begin
if (Getsymbolname of Data2) <> "DIA" then Print("The second symbol should be DIA");
end;
DIAClose = Close of Data2;
if DIAClose > Highest(DIAClose, Lookback)[1] and C < Highest(C, Lookback)[1] then buy this bar on close;
if Barssinceentry(0) >= HoldBars then sell this bar on close;
