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

This is what I got though. Why it wouldn't work?


aW8p8IB.png
 
After spending like 3 days looking at this thing, I don't think the newest iteration is any different. All the scripts suffer from future bias and are on paper profitable because they are looking into the future. At least in terms of how the backtest orders are placed.

I spent $250k on consulting and dev time building algos over the last few years. Made a bunch of money trading futures, lost a bunch of money trading futures. I got lucky to break even. It all started from a script I found here that took me down the rabbit hole. It was a hull moving avg 'holy grail' algo from what i remember. My point is these entries are not even close to real. If you cannot automate a strategy, you're just using colors on a chart to gamble. Gambling is fun but making sure money is more fun.

I hope I'm misinterpreting your code and you know something I don't. The basic entry logic and exit logic is fine but you cannot manipulate the entry price. You have to use open[-1] in TOS and mentally account for some slippage. If you try and use this chart live, the EMA cannot and will not stay stagnant in the current candle that's updating, which it shouldn't, and therefore you cannot make an entry until the candle is closed. Right now you're entering trades at some percent relative to current candles EMA, based on last candles buy trigger. You cannot go in the past and get the price of what it was. This is future telling bias. The current candle EMA isn't calculated until the current candle is closed. Does that make sense?

I'm happy to hop on a skype call and chat. I sure hope I'm wrong and you've figured it out though!
What is your opinion instead of saying low <= EMA1 I say low <= EMA1[1] since that EMA has been set and established? It would still be a good entry and the EMA wouldn’t change.
 
So... let's look at the entry.

def ShortTkPftBub = TradingDayExt and (ShortEntryInd or ShortHoldInd2) and low < EMA1 * 0.99;

It's looking at current candle situation. So let's say we're on 5 minute chart and at 5:01 ShortTkPftBub is true. We're all set to short. The low is less than the current EMA times 99% plus whatever checks you have. Now, at 5:04 the stock jumps on twitter news and now jumped up 100$ in price. Now, with 100% certainty, the low is still lower than 99% EMA. So, at the end of the candle, when the trade executes, at 5:04:59seconds, the low * 1.0025 is unattainable as an entry.

I'm trying to explain, the 5EMA that's triggering the order doesn't exist. The reason in TOS why you have to use open[-1] for entries and exits, which is using the price of the future candle open to execute a trade called on the current candle, is because how thinkscript works. If you watched your strategy live, you'd see your entries happen, then disappear when the price changes.

Thinkscript is a really strange language / compiles awkwardly. It's a particular programming language that's somewhat easy to read but really difficult to work with. Basically, Thinkscript executes on each candle over and over until the candle completes.

Does that make sense? Admin, chime in here? I'm 99% sure I'm correct but willing to be told otherwise.
I wouldn’t enter at the close. I would enter the second I get a trigger or atleast submit a trailing buy order. The twitter news in this example would make me a bunch of money.

Also we already went over this with the admin many times on this exact issue and it was decided that open[-1] would be even more inaccurate since that is not the intent of the strategy
 
Just realized that ToS has the entryPrice() function.

So this is simpler:

Code:
input tradeAmount = 10000;
def orderQuantity = Round(tradeAmount / open, 0);

#OPEN ORDERS
AddOrder(OrderType.BUY_TO_OPEN, ShowOrders and LongEntryInd, EMA1[1] * 1.0025, orderQuantity, Color.GREEN, Color.LIGHT_GREEN);
AddOrder(OrderType.SELL_TO_OPEN, ShowOrders and ShortEntryInd, EMA1[1] * 0.9975, orderQuantity, Color.GREEN, Color.LIGHT_GREEN);

#CLOSE ORDERS
AddOrder(OrderType.SELL_TO_CLOSE, ShowOrders and ShowTkPftOrders and LongTkPftBub, high * 0.999, entryPrice(), Color.RED, Color.LIGHT_RED);
AddOrder(OrderType.SELL_TO_CLOSE, ShowOrders and (LongSellInd or EndDay[-1]), open, entryPrice(), Color.RED, Color.LIGHT_RED);
AddOrder(OrderType.BUY_TO_CLOSE, ShowOrders and ShowTkPftOrders and ShortTkPftBub, low * 1.001, entryPrice(), Color.RED, Color.LIGHT_RED);
AddOrder(OrderType.BUY_TO_CLOSE, ShowOrders and (ShortSellInd or EndDay[-1]), open, entryPrice(), Color.RED, Color.LIGHT_RED);
How do you use these codes in TOS ?
 
I wouldn’t enter at the close. I would enter the second I get a trigger or atleast submit a trailing buy order. The twitter news in this example would make me a bunch of money.

Also we already went over this with the admin many times on this exact issue and it was decided that open[-1] would be even more inaccurate since that is not the intent of the strategy
Hey I have implemented your script and man has it been working great for me! Thank you for your work on this.
Question, is there a way to implement the alerts into a watchlist??
That would be highly advantages, rather than keeping several charts open on several screens, just a watchlist with the similar functionality to alert when a ticker is a long/short opportunity.
Thanks again
 
Edited Version 10 on Post# 148. The new code and link are there now.

I changed the MACD and TSI buy parameters so that they work off of each other. This change increased profits about $4k on TSLA over 90 days, I also added a little white dash above(or below) any buy candles to basically show you where the 5EMA +/- 0.25% was 1 bar prior. That way you can enter a trade after the fact on what was a good entry point (hope that part makes sense). Hopefully this white line will morph into a more accurate backtest.

If I get some positive feedback this weekend I will just post this new version on Post 1 and update that entire post with new photos, instuctions, etc.

In Addition, I created this neat little MACD/TSI Histogram. Seems to be working well. I happened to notice on the 5-Min Chart that if the histogram crosses below 3 or above -3 that is a pretty good sign of a reversal. Haven't really given the study much time though. Let me know what you see.

Code:
declare lower;

#TSI
input TSILongLength = 25;
input TSIShortLength = 13;

#TRUE STENGTH INDEX(TSI)
def DiffShort = close - close[1];
def DoubleSmoothedAbsDiffShort = ExpAverage(ExpAverage(AbsValue(DiffShort), TSILongLength), TSIShortLength);

#TSI
def TSI = if DoubleSmoothedAbsDiffShort == 0 then 0 else Round((100 * (ExpAverage(ExpAverage(DiffShort, TSILongLength), TSIShortLength)) / DoubleSmoothedAbsDiffShort), 2);

def TSIBull = TSI > 10;
def TSIBear = TSI < -10;

input fastLength = 10;
input slowLength = 22;
input MACDLength = 8;
input averageType = AverageType.EXPONENTIAL;

def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

plot Diff = if TSI > Avg then TSI + Avg else if TSI < Avg then TSI - Avg else 0;

Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.DefineColor("Neutral", Color.BLUE);
Diff.AssignValueColor(if Diff > 3 and Diff > Diff[1] then Diff.color("Positive and Up") else if Diff > 3 and Diff < Diff[1] then Diff.color("Positive and Down") else if Diff < -3 and Diff < Diff[1] then Diff.color("Negative and Down") else if Diff < -3 and Diff > Diff[1] then Diff.color("Negative and Up") else Diff.color("Neutral"));
 
Last edited:
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
 
Edited Version 10 on Post# 148. The new code and link are there now.

I changed the MACD and TSI buy parameters so that they work off of each other. This change increased profits about $4k on TSLA over 90 days, I also added a little white dash above(or below) any buy candles to basically show you where the 5EMA +/- 0.25% was 1 bar prior. That way you can enter a trade after the fact on what was a good entry point (hope that part makes sense). Hopefully this white line will morph into a more accurate backtest.

If I get some positive feedback this weekend I will just post this new version on Post 1 and update that entire post with new photos, instuctions, etc.

In Addition, I created this neat little MACD/TSI Histogram. Seems to be working well. I happened to notice on the 5-Min Chart that if the histogram crosses below 3 or above -3 that is a pretty good sign of a reversal. Haven't really given the study much time though. Let me know what you see.

Code:
declare lower;

#TSI
input TSILongLength = 25;
input TSIShortLength = 13;

#TRUE STENGTH INDEX(TSI)
def DiffShort = close - close[1];
def DoubleSmoothedAbsDiffShort = ExpAverage(ExpAverage(AbsValue(DiffShort), TSILongLength), TSIShortLength);

#TSI
def TSI = if DoubleSmoothedAbsDiffShort == 0 then 0 else Round((100 * (ExpAverage(ExpAverage(DiffShort, TSILongLength), TSIShortLength)) / DoubleSmoothedAbsDiffShort), 2);

def TSIBull = TSI > 10;
def TSIBear = TSI < -10;

input fastLength = 10;
input slowLength = 22;
input MACDLength = 8;
input averageType = AverageType.EXPONENTIAL;

def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);

plot Diff = if TSI <> Avg then TSI - Avg else 0;

Diff.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Diff.DefineColor("Positive and Up", Color.GREEN);
Diff.DefineColor("Positive and Down", Color.DARK_GREEN);
Diff.DefineColor("Negative and Down", Color.RED);
Diff.DefineColor("Negative and Up", Color.DARK_RED);
Diff.DefineColor("Neutral", Color.BLUE);
Diff.AssignValueColor(if Diff > 3 and Diff > Diff[1] then Diff.color("Positive and Up") else if Diff > 3 and Diff < Diff[1] then Diff.color("Positive and Down") else if Diff < -3 and Diff < Diff[1] then Diff.color("Negative and Down") else if Diff < -3 and Diff > Diff[1] then Diff.color("Negative and Up") else Diff.color("Neutral"));
Hey man, interesting strategy and indicator. I'm wondering if you think it's possible to add an average line to that macd tsi script. Maybe it could filter out lower quality moves. Just an idea. Good stuff!
 
Hey man, interesting strategy and indicator. I'm wondering if you think it's possible to add an average line to that macd tsi script. Maybe it could filter out lower quality moves. Just an idea. Good stuff!

The “MACD” it is using is actually the Avg in the MACD formula not the actual MACD that the Avg is used to calculate. Probably not really considered the MACD at that point lol.

From what I am noticing 3 and -3 are the magic numbers. You could probably buy when the histogram enters that zone as long as you can confirm your bias on another time frame.

I updated the post to color that zone blue if you grabbed the one from a little earlier this evening.

I haven’t reviewed enough charts to see if the histogram ever enters that “blue zone” and then reverses back in the original direction but hey there will be losses on every strategy. I was just super surprised when I randomly created this and how good it “seems” to work. I had to share it.
 
Where is 34 /50 cloud this is very important
How to add it from previous script
Updated code and link in post #148. You must turn on ShowEMACloud and Show2ndEMACloud to view the 5/12 and 34/50 EMAs and Clouds. If you only turn on Show2ndEMACloud and leave ShowEMACloud off than you will not see any clouds and if you only turn on ShowEMACloud and leave Show2ndEMACloud than you will only see the 5/12 EMA Cloud. Default is 5EMA line only.
 
One more stupid question
So if i turn pre market cloud off
It will be exclud pre market once the criteria met for all other criteria will be red or green
I am using only pre day high and low
Can you make this option to use previous day high and low instead
I know its alot of work to do guide me where to start
Thanks
 
One more stupid question
So if i turn pre market cloud off
It will be exclud pre market once the criteria met for all other criteria will be red or green
I am using only pre day high and low
Can you make this option to use previous day high and low instead
I know its alot of work to do guide me where to start
Thanks
No. The option to turn off premarket cloud is only visual. It still includes that parameter for the buy trigger. As far as your second request, I still **** at coding prior day stuff and if I figured out how to get the values, it would take me some time to figure out how to add that switch and not screw everything up.
 

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
301 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