10 Free Swing Trading Strategies (Amibroker And Tradestation Code)

The strategies on this page were summarized in this article.

Strategy 1 Monday reversal:

Amibroker code:

Buy= C<Ref(C,-1) AND Ref(C,-1)<Ref(C,-2) AND DayOfWeek()==1 ;

buyPrice=Close;

Sell= DayOfWeek()==1 OR BarsSince(Buy)>=5;

sellPrice=Close ;

Tradestation code:

{
Monday reversal (Strategy 77A)
}

Inputs:
	MaxHoldBars(5);

if Close < Close[1] and Close[1] < Close[2] and Dayofweek(Date) = 1 Then
	Buy this bar on close;

if Barssinceentry(0) >= 1 and (Dayofweek(Date) = 1 or Barssinceentry(0) >= MaxHoldBars) Then
	Sell this bar on close;

Strategy 2:

Amibroker code:

Buy= C<Ref(C,-1) AND Ref(C,-1)<Ref(C,-2) AND Ref(C,-2)<Ref(C,-3) ;

buyPrice=Close;

Sell= C>0;

sellPrice=Open ;

Tradestation code:

{
Three down days reversal overnight (Strategy 77B)
}

if Close < Close[1] and Close[1] < Close[2] and Close[2] < Close[3] Then
begin
	Buy this bar on close;
	Sell next bar on open;
end

Strategy 3:

Amibroker code:

Buy= ibs<0.15 AND H>Ref(HHV(H,5),-1) ;

buyPrice=Close;

Sell= C>Ref(H,-1);

sellPrice=Close ;

Tradestation code:

{
IBS reversal (Strategy 77C):
}

Inputs:
	BuyTreshold(0.15),
	Lookback(5);
	
Vars:
	ibs(0);

ibs=(C-L)/(H-L);

if ibs<BuyTreshold and H > Highest(H, Lookback)[1] Then
	Buy this bar at close;
	
if C > H[1]  Then
	Sell this bar at close;

Strategy 4:

Amibroker code:

Buy= ( DayOfWeek()==1 OR DayOfWeek()==2 ) AND ibs<0.15 ;

buyPrice=Close;

Sell= C>Ref(H,-1);

sellPrice=Close ;

Tradestation code:

{
IBS reversal with day of week filter (Strategy 77D):
}

Inputs:
	BuyTreshold(0.15),
	Lookback(5);
	
Vars:
	ibs(0);

ibs=(C-L)/(H-L);

if ibs<BuyTreshold and (Dayofweek(Date) = 1 or Dayofweek(Date) = 2) Then
	Buy this bar at close;
	
if C > H[1]  Then
	Sell this bar at close;

Strategy 5 and 6:

Amibroker code:

In the backtester settings you must set entry and exit delays of one day and make sure the open is ticked off.

You must test by using a filter and create the respective ETFs in one watch-list.

SetBacktestMode( backtestRotational );

SetOption(“initialequity”,100000);

SetOption(“MaxOpenPositions”,1);

SetOption(“WorstRankHeld”,1);

SetPositionSize( 100, spsPercentOfEquity );

PositionScore = 1000 +ROC(C,1) ;

Strategy 7: XLP

Amibroker code:

range=MA((H-L),25);
OddisHigh=HHV(H,25);
OddisBand=OddisHigh – (range*2);

Buy= Close<OddisBand AND ibs<0.35;
buyPrice= C;
Sell= C>Ref(H,-1);
sellPrice= Close ;

Tradestation code:

{
Oddis band (Strategy 77G)
}

Inputs: 
	IbsTreshold(0.35),
	Lookback(25),
	RngMult(2);

Vars: 
	Rng(0),
	OddisHigh(0),
	OddisBand(0),
	ibs(0);

ibs=(C-L)/(H-L);
Rng = Average(H - L, Lookback);
OddisHigh = Highest(H, Lookback);
OddisBand = OddisHigh - RngMult * Rng;


if C < OddisBand and ibs < IbsTreshold then    
	Buy this bar on close;	
  
if C > H[1] then 
	Sell this bar on close;	

Strategy 8: MACD-histogram in S&P 500

Amibroker code:

Fast = EMA(C,12) – EMA(C,26);
Slow = EMA(Fast,9);
Histogram = Fast – slow;

Buy= C<Ref(C,-1) AND Ref(Histogram,-4) < 0 AND Ref(Histogram,-4) > Ref(Histogram,-3) AND Ref(Histogram,-3) > Ref(Histogram,-2) AND Ref(Histogram,-2) > Ref(Histogram,-1) AND Ref(Histogram,-1) > Histogram;
buyPrice = Close;
Sell = Close > Ref(H,-1);
sellPrice = Close ;

Tradestation code:

{
MACD-histogram on the S&P 500  (strategy 77H)
}

Inputs:
	EmaFastLookback1(12),
	EmaFastLookback2(26),
	EmaSlowLookback(9);
	
Vars:
	Fast(0),
	Slow(0),
	Histogram(0);

Fast = XAverage(Close, EmaFastLookback1)-XAverage(Close, EmaFastLookback2);
Slow = XAverage(Fast,EmaSlowLookback);
Histogram = Fast-Slow;

if (Close < Close[1]) And
   (Histogram[4] < 0) And
   (Histogram[4] > Histogram[3]) And
   (Histogram[3] > Histogram[2]) And
   (Histogram[2] > Histogram[1]) And
   (Histogram[1] > Histogram) Then
   Buy this bar on close;

if (Close > High[1]) Then
	Sell this bar on close;

Strategy 9: Turn of the month strategy in the S&P 500

Amibroker code:

Buy= Ref(Month(),4)!=Ref(Month(),5);
buyPrice=Close;
Sell= BarsSince(Ref(Month(),4)!=Ref(Month(),5))==7;
sellPrice=Close ;

Tradestation code:

{
Turn of the month (Strategy 77I)
}

Inputs:
	DaysBeforeMonthEnd(4),
	HoldBars(7);
	
if TdaysTillMonthEnd = DaysBeforeMonthEnd then 
	Buy this bar on close;
	
if BarsSinceEntry >= HoldBars then 
	Sell this bar on close;

Strategy 10: 200-day moving average swing trading strategy in S&P 500 and gold

Amibroker code:

Buy= Cross(Close,MA(C,200));
buyPrice=Close;
Sell= Cross(MA(C,200),Close);
sellPrice=Close ;

Tradestation code:

{
200-day moving average swing trading strategy (Strategy 77J)
}

Inputs:
	Lookback(200);
	
if C crosses above Average(C, Lookback) then 
	Buy this bar on close;
	
if Average(C, Lookback) crosses above C then 
	Sell this bar on close;