Strategy Based on EMAs, TSI, MACD, and Premarket Highs/Lows For ThinkOrSwim

check this code i use it
If i can replace pre market with this previous low and high

#Plot opening range high / low
input MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;


#Plot yesterday's high / low
plot Yhigh = if ShowTodayOnly and !Today then Double.NaN else high(period = "day" )[1];
plot Ylow = if ShowTodayOnly and !Today then Double.NaN else low(period = "day" )[1];

Yhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Yhigh.SetDefaultColor(Color.GREEN);
Yhigh.SetLineWeight(2);
Ylow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Ylow.SetDefaultColor(Color.GREEN);
Ylow.SetLineWeight(2);




Alert(close>Yhigh, "buySignal",Alert.bar,Sound.Ding);
Alert(close<Ylow, "sellSignal",Alert.bar,Sound.Ding);
 
check this code i use it

#Plot opening range high / low
input MarketOpenTime = 0930;
input ShowTodayOnly = yes;

def Today = if GetDay() == GetLastDay() then 1 else 0;


#Plot yesterday's high / low
plot Yhigh = if ShowTodayOnly and !Today then Double.NaN else high(period = "day" )[1];
plot Ylow = if ShowTodayOnly and !Today then Double.NaN else low(period = "day" )[1];

Yhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Yhigh.SetDefaultColor(Color.GREEN);
Yhigh.SetLineWeight(2);
Ylow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Ylow.SetDefaultColor(Color.GREEN);
Ylow.SetLineWeight(2);




Alert(close>Yhigh, "buySignal",Alert.bar,Sound.Ding);
Alert(close<Ylow, "sellSignal",Alert.bar,Sound.Ding);

I’ll look at it on Sunday and try to get it in there. Are you wanting this to be a buy trigger? i.e. only buy if higher than yesterdays high or lower than yesterdays low? Are you only wanting yesterday and not premarket or both?
 
I’ll look at it on Sunday and try to get it in there. Are you wanting this to be a buy trigger? i.e. only buy if higher than yesterdays high or lower than yesterdays low? Are you only wanting yesterday and not premarket or both?
I think we should leave pre market low and high
Previous day low and high as
visual guide( line ) not included in buy and sell criteria
Thank you for taking the time to do this work and help every one
 
Last edited:
ripster on twitter
#tradingtips Day Trade Concepts for #Long/Short Trade Management
# Pre Market Lows Highs
#Previous Day Lows Highs
#9:45-10.15 EST Trend Daily Levels #OpeningCandle Low/Highs(Range) #5/8/12/34/50 EMAs
#RelativeVolume for the Day Option Flow & #SPY/QQQ/VIX(For LargeCaps)
 
ripster on twitter
#tradingtips Day Trade Concepts for #Long/Short Trade Management
# Pre Market Lows Highs
#Previous Day Lows Highs
#9:45-10.15 EST Trend Daily Levels #OpeningCandle Low/Highs(Range) #5/8/12/34/50 EMAs
#RelativeVolume for the Day Option Flow & #SPY/QQQ/VIX(For LargeCaps)
Yeah I follow him almost exclusively on Twitter.

What I like to do is use a flexible grid with multiple time frames for my ticker, I have the index’s on a watchlist up at all times, and a mini chart with VIX. I also have another monitor with my favorite tickers that have good options flow in a 20ish ticker flexible grid running the strategy with background color change on. I have tried the strategy without premarket on and it reduces the profit but I’ll look at coding in pre, yesterday, and none options.
 
Kinda de-railing my own thread but this relates to the histogram above.

If you had noticed the 30 minute crossover on AAPL in the premarket last Wednesday 5/11 and confirmed that trend with the 5 minute red histogram and bought AAPL 140 Puts at the open they were $0.01. Then if you had held overnight (which I hate doing) you would have noticed that the 30 minute histogram never went green all night or all day Thursday. These options hit a high of $0.45 on Wednesday and $2.65 on Thursday and never dropped below $0.39 on Thursday. That is a 26,500% gain in two days if you were wondering.

Also go look at QQQ today at the end of day and notice the crossover there also on the 5 minute chart (30 minute was still red). You could have grabbed some major gains there too.

1PqrMHU.png
the same watchlist in post 1 . or different one
 
Post #1 has been updated with Version 10. This is the latest and greatest. I will request that post 148 gets deleted so there is no confusion. I also posted the new watchlist indicator and flex grid link. All links and codes have been updated except my watchlist tickers because those haven't changed.

I added some more pictures and changed most of the instructions but honestly didn't dive into every detail. If you have used this before than you know what to do. If not just ask and I will try to get back to you as soon as possible to answer your questions.
 
I'm new so lots of term I don't know quite well yet. What is "Tk Pft Bubble" means ?
 
Last edited by a moderator:
I'm new so lots of term I don't know quite well yet. What is "Tk Pft Bubble" means ?
It’s just a bubble that lets you know that the price is extended from the EMA. Do with it what you want but more times than not if the price is extended from the EMA it will end up coming back down. Go review several charts and you will see what I mean.
 
I updated the code to include (close < open) or (close > open) on the sell trigger due to some random sell signals on AAPL today. Didn't change much with the backtest but would have kept you in AAPL.

Also added PreMarketBull and PreMarketBear on the hold signals due to some candle color errors. (light_red on QQQ when price was well above pre market low).

Version 10.2 is posted in Post#1
 
Last edited:
edit: I figured it out as I understood better explanations of post #1. The strategy assumes to wait for the stock to cross the EMA again.

In short it would be:
1. When buy signal is recorded, do nothing
2. Wait for the price to cross the EMA down and up again (if the initial signal was a crossing above). Buy at this point.

I was using this wrong.

I have some trouble with these lines and how it is supposed to be used.

Code:
AddOrder(OrderType.BUY_TO_OPEN, ShowOrders and LongEntryInd, EMA1 * 1.0025, 100, Color.GREEN, Color.LIGHT_GREEN);
AddOrder(OrderType.SELL_TO_OPEN, ShowOrders and ShortEntryInd, EMA1 * 0.9975, 100, Color.GREEN, Color.LIGHT_GREEN);

What is the actual trigger of the order? Crossing EMA5?

The issue with that is:
a) if the intent is to place the order immediately, and if the candle actually finishes above the EMA5, we're fine. But if it doesn't and reverses, the white arrow disappears and there is no recording that a (maybe losing) order has been placed and the strategy report is skewed.
b) if the intent is to wait for the candle to close, then the price of the order is not the price at the candle closing. Changing that in the script to the classical "open[-1]" modifies significantly the performance of the strategy in some cases.
 
Last edited:
I updated the code to include (close < open) or (close > open) on the sell trigger due to some random sell signals on AAPL today. Didn't change much with the backtest but would have kept you in AAPL.

Also added PreMarketBull and PreMarketBear on the hold signals due to some candle color errors. (light_red on QQQ when price was well above pre market low).

Version 10.2 is posted in Post#1
This thing drove me crazy whit apple today
 
edit: I figured it out as I understood better explanations of post #1. The strategy assumes to wait for the stock to cross the EMA again.

In short it would be:
1. When buy signal is recorded, do nothing
2. Wait for the price to cross the EMA down and up again (if the initial signal was a crossing above). Buy at this point.

A way to automate this could be to place a limit order at the value of the EMA when the buy signal was generated.

I was using this wrong.

I have some trouble with these lines and how it is supposed to be used.

Code:
AddOrder(OrderType.BUY_TO_OPEN, ShowOrders and LongEntryInd, EMA1 * 1.0025, 100, Color.GREEN, Color.LIGHT_GREEN);
AddOrder(OrderType.SELL_TO_OPEN, ShowOrders and ShortEntryInd, EMA1 * 0.9975, 100, Color.GREEN, Color.LIGHT_GREEN);

What is the actual trigger of the order? Crossing EMA5?

The issue with that is:
a) if the intent is to place the order immediately, and if the candle actually finishes above the EMA5, we're fine. But if it doesn't and reverses, the white arrow disappears and there is no recording that a (maybe losing) order has been placed and the strategy report is skewed.
b) if the intent is to wait for the candle to close, then the price of the order is not the price at the candle closing. Changing that in the script to the classical "open[-1]" modifies significantly the performance of the strategy in some cases.
If you read above, I and many others are aware that the backtest is not perfect but it is skewed in the correct direction. I am honestly done modifying the orders as it was just a way for me to see if changes I made to the code were better or worse. If you change it to open[-1] than the orders do not meet the intent of the strategy. I am definitely open to suggestions other than open[-1] but I don't know if there is a 100% accurate solution. Some strategies just apparently can't be backtested perfectly without getting tick by tick data from ToS.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
291 Online
Create Post

Similar threads

Similar threads

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