SPY Day Trading + Swing Trading Indicators for ThinkorSwim

BenTen

BenTen

Administrative
Staff
VIP
Warehouse
This indicator was designed to trade the S&P 500 (SPY) on a weekly chart. Developer Waylock created it and AlphaInvestor added weekly aggregation.

I modified the script a bit so that you can use it to day trade and swing trade $SPY on the lower timeframe.

From backtesting, the buy and sell signals worked really well. You may want to take a second look and see if this is something that may fit your trading style. I also added alerts in the code so that ThinkorSwim will let you know when there is a new bullish or bearish signal.





Day Trading Version

Code:
# Original name: Big_Hand_Arrows_On_Study_w_Agg

# Script by Waylock

# AlphaInvestor - 05/12/2017 - force to weekly aggregation

# Modified by BenTen to work on lower timeframe. Alerts added.

declare lower;

input agg = AggregationPeriod.FIFTEEN_MIN;

input fastLength = 19;

input slowLength = 39;

def c = close(period = agg);

plot Value = ExpAverage(c, fastLength) - ExpAverage(c, slowLength);

def Value_color = if Value > 0 then yes else no;

Value.DefineColor( "ValueUp", Color.GREEN );

Value.DefineColor( "ValueDn", Color.RED );

Value.AssignValueColor( if Value_color then Value.Color( "ValueUp" ) else Value.Color( "ValueDn" ) );

plot ZeroLine = 0;

Value.SetDefaultColor(Color.CYAN);

ZeroLine.SetDefaultColor(Color.YELLOW);

ZeroLine.HideTitle();

ZeroLine.HideBubble();

def xUndr = Value[1] < 0 and Value > 0;

def xOver = Value[1] > 0 and Value < 0;

plot ArrowUp = if xUndr then xOver else Double.NaN;

ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

ArrowUp.SetDefaultColor(Color.YELLOW);

ArrowUp.SetLineWeight(5);

ArrowUp.HideTitle();

ArrowUp.HideBubble();

plot ArrowDn = if xOver then xUndr else Double.NaN;

ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

ArrowDn.SetDefaultColor(Color.YELLOW);

ArrowDn.SetLineWeight(5);

ArrowDn.HideTitle();

ArrowDn.HideBubble();

def data = Value;

# Alerts
Alert(ArrowUp, " ", Alert.Bar, Sound.Chimes);
Alert(ArrowDn, " ", Alert.Bar, Sound.Bell);

# End Study
Shareable Link: http://tos.mx/wJd6hZ

Swing Trading Version



Code:
# Original name: Big_Hand_Arrows_On_Study_w_Agg

# Script by Waylock

# AlphaInvestor - 05/12/2017 - force to weekly aggregation

# Modified by BenTen to work on lower timeframe. Alerts added.

declare lower;

input agg = AggregationPeriod.HOUR;

input fastLength = 19;

input slowLength = 39;

def c = close(period = agg);

plot Value = ExpAverage(c, fastLength) - ExpAverage(c, slowLength);

def Value_color = if Value > 0 then yes else no;

Value.DefineColor( "ValueUp", Color.GREEN );

Value.DefineColor( "ValueDn", Color.RED );

Value.AssignValueColor( if Value_color then Value.Color( "ValueUp" ) else Value.Color( "ValueDn" ) );

plot ZeroLine = 0;

Value.SetDefaultColor(Color.CYAN);

ZeroLine.SetDefaultColor(Color.YELLOW);

ZeroLine.HideTitle();

ZeroLine.HideBubble();

def xUndr = Value[1] < 0 and Value > 0;

def xOver = Value[1] > 0 and Value < 0;

plot ArrowUp = if xUndr then xOver else Double.NaN;

ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

ArrowUp.SetDefaultColor(Color.YELLOW);

ArrowUp.SetLineWeight(5);

ArrowUp.HideTitle();

ArrowUp.HideBubble();

plot ArrowDn = if xOver then xUndr else Double.NaN;

ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

ArrowDn.SetDefaultColor(Color.YELLOW);

ArrowDn.SetLineWeight(5);

ArrowDn.HideTitle();

ArrowDn.HideBubble();

def data = Value;

# Alerts
Alert(ArrowUp, " ", Alert.Bar, Sound.Chimes);
Alert(ArrowDn, " ", Alert.Bar, Sound.Bell);

# End Study
Shareable Link: http://tos.mx/VevVxf
 
tenacity11

tenacity11

Member
VIP
Ben will the Spy Day/Swing Trading Indicator be applicable to the 2x and 3x etfs also?
 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@tenacity11 I’m not sure but you should still see the oscillator and its signals on 2x and 3x ETFs.
 
sylar2017

sylar2017

New member
VIP
@BenTen Here is the backtest code for this strategy

Strategy:

Code:
input agg = AggregationPeriod.FIFTEEN_MIN;

input TradeSize = 100;

input fastLength = 19;

input slowLength = 39;

def c = close(period = agg);

Def Value = ExpAverage(c, fastLength) - ExpAverage(c, slowLength);

def B =   Value[1] < 0 and Value > 0;

def S =   Value[1] > 0 and Value < 0 ;

AddOrder(OrderType.BUY_AUTO, condition = B, price = open[-1], TradeSize, tickcolor = Color. GREEN, arrowcolor = Color.GREEN);

AddOrder(OrderType.SELL_AUTO, condition = S, price = open[-1], TradeSize, tickcolor = Color.RED, arrowcolor = Color.RED);
SPY 90 Day 1 Hr Time Frame Results:
Max trade P/L: $964.00
Total P/L: $723.98
Total order(s): 12

 
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@sylar2017 Thank you for sharing. That was really helpful!
 
markos

markos

Well-known member
VIP
Warehouse
@sylar2017 how long did that back test run for? If you could give a few more details and show a full 90 day chart, thank you!
 
markos

markos

Well-known member
VIP
Warehouse
@BenTen Thank you for thinking outside of the box and trying so many different indicators for your members to back test and try out.
You are bringing a needed, different viewpoint to the ThinkorSwim community!
 
M

Mandalorianknight63

New member
@BenTen Here is the backtest code for this strategy

Strategy:

Code:
input agg = AggregationPeriod.FIFTEEN_MIN;

input TradeSize = 100;

input fastLength = 19;

input slowLength = 39;

def c = close(period = agg);

Def Value = ExpAverage(c, fastLength) - ExpAverage(c, slowLength);

def B =   Value[1] < 0 and Value > 0;

def S =   Value[1] > 0 and Value < 0 ;

AddOrder(OrderType.BUY_AUTO, condition = B, price = open[-1], TradeSize, tickcolor = Color. GREEN, arrowcolor = Color.GREEN);

AddOrder(OrderType.SELL_AUTO, condition = S, price = open[-1], TradeSize, tickcolor = Color.RED, arrowcolor = Color.RED);
SPY 90 Day 1 Hr Time Frame Results:
Max trade P/L: $964.00
Total P/L: $723.98
Total order(s): 12

Awesome job with the back test.

I'm trying to see what would be more effective for swing trading, if using a daily or 4 hr alerts on this.

Any thoughts on the matter?
 
T

thinky

Member
When using lower time frames like 5min and 15min, do you modify the other 2 parameters (fast length, slow length)?
 
Last edited:
BenTen

BenTen

Administrative
Staff
VIP
Warehouse
@Captainezman Alerts are in the code already. Just have your chart (with the any specific ticker) running and you should hear it.
 
Shinthus

Shinthus

Member
VIP
@BenTen Here is the backtest code for this strategy

Strategy:

Code:
input agg = AggregationPeriod.FIFTEEN_MIN;

input TradeSize = 100;

input fastLength = 19;

input slowLength = 39;

def c = close(period = agg);

Def Value = ExpAverage(c, fastLength) - ExpAverage(c, slowLength);

def B =   Value[1] < 0 and Value > 0;

def S =   Value[1] > 0 and Value < 0 ;

AddOrder(OrderType.BUY_AUTO, condition = B, price = open[-1], TradeSize, tickcolor = Color. GREEN, arrowcolor = Color.GREEN);

AddOrder(OrderType.SELL_AUTO, condition = S, price = open[-1], TradeSize, tickcolor = Color.RED, arrowcolor = Color.RED);
SPY 90 Day 1 Hr Time Frame Results:
Max trade P/L: $964.00
Total P/L: $723.98
Total order(s): 12

Those 12 trades took place within how long? Hours? Days?
 

Top