52 Week High Strategy (Amibroker And Tradestation Code)
The original article can be found here.
Strategy number one:
- Calculate a 200-day moving average and a 50-day moving average of the 52 week high indicator.
- When the 50-day moving average crosses above the 200-day moving average, we go long SPY at the close.
- When the 200-day moving average crosses above the 50-day moving average, we sell SPY at the close.
Amibroker code:
Buy= Cross(MA(fremmed,50),MA(fremmed,200)) ;
buyPrice= Close ;
Sell= Cross(MA(fremmed,200),MA(fremmed,50));
sellPrice=Close ;
Strategy number two:
- The 52-week high reading sets a new 10-day high and we go long at the close.
- We sell when the 52-week high reading sets a 10-day low.
Amibroker code:
Buy= fremmed>Ref(HHV(fremmed,10),-1) ;
buyPrice= Close ;
Sell= fremmed<Ref(llV(fremmed,10),-1);
sellPrice=Close ;
Tradestation code:
{
Strategy 131A 52-week high strategy
Calculate a 200-day moving average and a 50-day moving average of the 52 week high indicator.
When the 50-day moving average crosses above the 200-day moving average, we go long SPY at the close.
When the 200-day moving average crosses above the 50-day moving average, we sell SPY at the close.
}
Inputs:
LookbackSlow(200),
LookbackFast(50);
Vars:
High52(0);
High52 = Highest(Close, 252);
if Average(High52, LookbackFast) cross over Average(High52, LookbackSlow) Then
buy this bar on close;
if Average(High52, LookbackFast) cross under Average(High52, LookbackSlow) Then
sell this bar on close;
-------------------------------------------------------------------------
{
Strategy 131B 52-week high strategy
The 52-week high reading sets a new 10-day high and we go long at the close.
We sell when the 52-week high reading sets a 10-day low.
}
Inputs:
Lookback(10);
Vars:
High52(0);
High52 = Highest(Close, 252);
if High52 > Highest(High52, Lookback)[1] Then
buy this bar on close;
if High52 < Lowest(High52, Lookback)[1] Then
sell this bar on close;
