SPX Trading Strategy for ThinkorSwim

Status
Not open for further replies.
@Hypoluxa I took a shot at putting your strategy into a study. All parameters are customizable. It will plot buy and sell signals and alert when signals show up. I was thinking that the BB dots being above and below the zero line can be turned into a percent up or down. Let me know if you can think of any enhancements.

Python:
# SPX Strategy
# Strategy designed by Hypoluxa
# barbaros - 2021/02/25

declare upper;

input price = close;
input SMAFastLength = 3;
input SMASlowLength = 9;
input BBlength = 30;
input BBNum_Dev = 0.8;
input BBCrossInBars = 3;
input BBCrossDistance = 1;
input MACDfastLength = 8;
input MACDslowLength = 16;
input MACDLength = 36;
input ERGODICLongLength = 2;
input ERGODICShortLength = 10;
input ERGODICSignalLength = 36;
input ERGODICAverageType = {"SIMPLE", default "EXPONENTIAL", "WEIGHTED", "WILDERS", "HULL"};

# Check for 10min chart
Assert(GetAggregationPeriod() == AggregationPeriod.TEN_MIN, "Incorrect Chart Time, use 10m");

# MACD
def MACD_Data = MACD(fastLength = MACDfastLength, slowLength = MACDslowLength, MACDLength = MACDLength);
def MACD_Direction = if MACD_Data > MACD_Data[1] then 1 else -1;

# Ergodic
def Ergodic_Data = ErgodicOsc("long length" = ERGODICLongLength, "short length" = ERGODICShortLength, "signal length" = ERGODICSignalLength, "average type" = ERGODICAverageType).ErgodicOsc;

# SMAs
def SMA_Fast = SimpleMovingAvg(price, SMAFastLength);
def SMA_Slow = SimpleMovingAvg(price, SMASlowLength);

# Signals
def buySignal = SMA_Fast > SMA_Slow and Ergodic_Data > 0 and MACD_Direction == 1 and MACD_Data >= BBCrossDistance and MACD_Data crosses above 0 within BBCrossInBars bars;
def sellSignal = SMA_Fast < SMA_Slow and Ergodic_Data < 0 and MACD_Direction == -1 and MACD_Data <= -BBCrossDistance and MACD_Data crosses below 0 within BBCrossInBars bars;

# Plots
plot buy = buySignal and !buySignal[1];
buy.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
buy.setDefaultColor(Color.GREEN);
buy.setLineWeight(3);

plot sell = sellSignal and !sellSignal[1];
sell.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sell.setDefaultColor(Color.RED);
sell.setLineWeight(3);

# Alerts
Alert(buy, "Buy", Alert.BAR, Sound.Ring);
Alert(sell, "Sell", Alert.BAR, Sound.Ring);
How delayed are the arrows going to be or will they populate the same time as the MACDBB dot crosses? Also, since the arrow populates at the crossing, what's the real benefit of the arrow? Is it to alert a signal in case you aren't looking at SPX at the time?
I've never used alerts, so that's why I'm asking that one.
 
@Hypoluxa I took a shot at putting your strategy into a study. All parameters are customizable. It will plot buy and sell signals and alert when signals show up. I was thinking that the BB dots being above and below the zero line can be turned into a percent up or down. Let me know if you can think of any enhancements.

Python:
# SPX Strategy
# Strategy designed by Hypoluxa
# barbaros - 2021/02/25

declare upper;

input price = close;
input SMAFastLength = 3;
input SMASlowLength = 9;
input BBlength = 30;
input BBNum_Dev = 0.8;
input BBCrossInBars = 3;
input BBCrossDistance = 1;
input MACDfastLength = 8;
input MACDslowLength = 16;
input MACDLength = 36;
input ERGODICLongLength = 2;
input ERGODICShortLength = 10;
input ERGODICSignalLength = 36;
input ERGODICAverageType = {"SIMPLE", default "EXPONENTIAL", "WEIGHTED", "WILDERS", "HULL"};

# Check for 10min chart
Assert(GetAggregationPeriod() == AggregationPeriod.TEN_MIN, "Incorrect Chart Time, use 10m");

# MACD
def MACD_Data = MACD(fastLength = MACDfastLength, slowLength = MACDslowLength, MACDLength = MACDLength);
def MACD_Direction = if MACD_Data > MACD_Data[1] then 1 else -1;

# Ergodic
def Ergodic_Data = ErgodicOsc("long length" = ERGODICLongLength, "short length" = ERGODICShortLength, "signal length" = ERGODICSignalLength, "average type" = ERGODICAverageType).ErgodicOsc;

# SMAs
def SMA_Fast = SimpleMovingAvg(price, SMAFastLength);
def SMA_Slow = SimpleMovingAvg(price, SMASlowLength);

# Signals
def buySignal = SMA_Fast > SMA_Slow and Ergodic_Data > 0 and MACD_Direction == 1 and MACD_Data >= BBCrossDistance and MACD_Data crosses above 0 within BBCrossInBars bars;
def sellSignal = SMA_Fast < SMA_Slow and Ergodic_Data < 0 and MACD_Direction == -1 and MACD_Data <= -BBCrossDistance and MACD_Data crosses below 0 within BBCrossInBars bars;

# Plots
plot buy = buySignal and !buySignal[1];
buy.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
buy.setDefaultColor(Color.GREEN);
buy.setLineWeight(3);

plot sell = sellSignal and !sellSignal[1];
sell.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sell.setDefaultColor(Color.RED);
sell.setLineWeight(3);

# Alerts
Alert(buy, "Buy", Alert.BAR, Sound.Ring);
Alert(sell, "Sell", Alert.BAR, Sound.Ring);

I put this study in my chart, looks interesting... Thanks for doing this
 
How delayed are the arrows going to be or will they populate the same time as the MACDBB dot crosses? Also, since the arrow populates at the crossing, what's the real benefit of the arrow? Is it to alert a signal in case you aren't looking at SPX at the time?
I've never used alerts, so that's why I'm asking that one.
Arrows will show immediately. There is no delay. All conditions need to be met. Thats the benefit of the arrow. You don't need to look at all the indicators and remember the logic. Note the BBCrossInBars and BBCrossDistance variables. BBCrossInBars is that the BB dots needs to be crossed the zero line in that many historical bars and BBCrossDistance is how much it needs to be above or below the zero line to be accepted as a valid signal.

Alerts are if you are watching many charts or you are busy with other things and you want this to get your attention.
 
What are the exit or profit rules? At what point we exit the trade example from white dot to red dot exit call side or wait until it touches zero line?
 
Arrows will show immediately. There is no delay. All conditions need to be met. Thats the benefit of the arrow. You don't need to look at all the indicators and remember the logic. Note the BBCrossInBars and BBCrossDistance variables. BBCrossInBars is that the BB dots needs to be crossed the zero line in that many historical bars and BBCrossDistance is how much it needs to be above or below the zero line to be accepted as a valid signal.

Alerts are if you are watching many charts or you are busy with other things and you want this to get your attention.
And from a visual standpoint, that def makes the screen a lot cleaner!
Side note - one thing I have noticed from this SPX setup:
Its not safe to get in a scalping situation at the opening bell if the MACDBB dots went above or below the zero line prior to the opening or if they cross right at 9:30 (eastern time) However, it does look successful if they do so at 9:40 or just after. You can look back on this and see it and PUTS are generally better than CALLS with this observation.
 
What are the exit or profit rules? At what point we exit the trade example from white dot to red dot exit call side or wait until it touches zero line?
The big flaw in this setup is I never know when to hold longer for an exit....but since this is a "scalping" entry setup...I'm not planning on holding for long anyway. Look at SPX today...If I wasn't busy this morning, I would've gotten in at 10:00ET and out between then and 10:40. For scalping...the exit plan is on the investor...IMO.
 
Can we enter if it goes close to the zeroline and retrace? Like the one now on the put side?
My advice to you on this strategy and any other strategy you may start using....is to look back at least 2 months to see how it reacts in different situations. That's what I do and then I determine if I want to go against the logic or not when certain scenarios popup.
 
Can we enter if it goes close to the zeroline and retrace? Like the one now on the put side?

The problem with with this is that the retrace may just be a sign of further impending weakness in advance of a reversal... That is why @Hypoluxa has stressed the crossing and substantial gap before an entry because that proves momentum and trend direction... Why gamble on a wishy washy setup when it's safer to wait for an ideal entry...??? Think "patience"...!!! Five slow steps forward are better than 10 rushed steps forward and 8 steps back... ALL indicators need to show an ideal trade entry, otherwise it's just gambling...
 
Hi all,

Catching up on today's action and posts since returning from work. Wow! What a move in the SPX and congrats to @tom23824! Nice trade!
@barbaros : Thank you for your efforts and study creation! Looks real good after loading the study. @Hypoluxa : Thanks for the additional guidance on entries near the open. Excellent awareness items. Sure wish I was able to trade this move today. Excellent trade again @Hypoluxa!!
I'm still learning and watching. Quick question to all and I'm sorry if I missed this earlier, what is the best way to view options to be readily available for potential trades? Thanks!
 
Last edited:
@Hypoluxa I took a shot at putting your strategy into a study. All parameters are customizable. It will plot buy and sell signals and alert when signals show up. I was thinking that the BB dots being above and below the zero line can be turned into a percent up or down. Let me know if you can think of any enhancements.

Python:
# SPX Strategy
# Strategy designed by Hypoluxa
# barbaros - 2021/02/25

declare upper;

input price = close;
input SMAFastLength = 3;
input SMASlowLength = 9;
input BBlength = 30;
input BBNum_Dev = 0.8;
input BBCrossInBars = 3;
input BBCrossDistance = 1;
input MACDfastLength = 8;
input MACDslowLength = 16;
input MACDLength = 36;
input ERGODICLongLength = 2;
input ERGODICShortLength = 10;
input ERGODICSignalLength = 36;
input ERGODICAverageType = {"SIMPLE", default "EXPONENTIAL", "WEIGHTED", "WILDERS", "HULL"};

# Check for 10min chart
Assert(GetAggregationPeriod() == AggregationPeriod.TEN_MIN, "Incorrect Chart Time, use 10m");

# MACD
def MACD_Data = MACD(fastLength = MACDfastLength, slowLength = MACDslowLength, MACDLength = MACDLength);
def MACD_Direction = if MACD_Data > MACD_Data[1] then 1 else -1;

# Ergodic
def Ergodic_Data = ErgodicOsc("long length" = ERGODICLongLength, "short length" = ERGODICShortLength, "signal length" = ERGODICSignalLength, "average type" = ERGODICAverageType).ErgodicOsc;

# SMAs
def SMA_Fast = SimpleMovingAvg(price, SMAFastLength);
def SMA_Slow = SimpleMovingAvg(price, SMASlowLength);

# Signals
def buySignal = SMA_Fast > SMA_Slow and Ergodic_Data > 0 and MACD_Direction == 1 and MACD_Data >= BBCrossDistance and MACD_Data crosses above 0 within BBCrossInBars bars;
def sellSignal = SMA_Fast < SMA_Slow and Ergodic_Data < 0 and MACD_Direction == -1 and MACD_Data <= -BBCrossDistance and MACD_Data crosses below 0 within BBCrossInBars bars;

# Plots
plot buy = buySignal and !buySignal[1];
buy.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
buy.setDefaultColor(Color.GREEN);
buy.setLineWeight(3);

plot sell = sellSignal and !sellSignal[1];
sell.setPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sell.setDefaultColor(Color.RED);
sell.setLineWeight(3);

# Alerts
Alert(buy, "Buy", Alert.BAR, Sound.Ring);
Alert(sell, "Sell", Alert.BAR, Sound.Ring);
barbaros, very nice. I noticed the study only works on the 10 minute chart. How do I code it to allow for it to work on all time frames? Thanks!
 
Status
Not open for further replies.

New Indicator: Buy the Dip

Check out our Buy the Dip indicator and see how it can help you find profitable swing trading ideas. Scanner, watchlist columns, and add-ons are included.

Download the indicator

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
320 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top