TD Perfection Indicator for ThinkorSwim


Well-known member
I wrote this script after reading about the algorithm from a public website but added my own twist. It can be used for scalping.

Dots above and below the signal is the support and resistance levels.

Let me know what you think and how I can improve it.


# TD Perfection Indicator
# barbaros
# 04.25.2020

# v1.0 - 04.25.2020 - barbaros - Initial release of TD Perfection Indicator

input price = close;
input showbuy = yes;
input showsell = no;
input k = 0; # 0 to 8
input i = 0; # 0 to 13

# Buy Perfection
def BearishPriceTwist = price[9] > price[13] and price[8] < price[12];
def BuySystem = price[k] < price[4+k];
def BuyPerfection = Lowest(price) <= Lowest(price[3]) and Lowest(price) <= Lowest(price[2]);
def BuySupport = Lowest(low[i]);
def BuyResistance = Highest(high[i]);
def BuyProbability = ((price - BuySupport) / (BuyResistance - price)) > 0.60 and ((BuyResistance - price) / (price - BuySupport)) > 0.40;

plot buySignal = if showbuy and BearishPriceTwist and BuySystem and BuyPerfection and BuyProbability and low > BuySupport and price > BuySupport and price < BuyResistance then close else Double.NaN;

plot buySupportLine = if buySignal then BuySupport else Double.NaN;
plot buyResistanceLine = if buySignal then BuyResistance else Double.NaN;

Alert(buySignal, "Buy Perfection", Alert.BAR, Sound.Bell);

# Sell Perfection
def BullishPriceTwist = price[9] < price[13] and price[8] > price[12];
def SellSystem = price[k] > price[4+k];
def SellPerfection = Highest(price) >= Highest(price[3]) and Highest(price) >= Highest(price[2]);
def SellSupport = Highest(price[i]);
def SellResistance = Lowest(price[i]);
def SellProbability = ((SellSupport - price) / (price - SellResistance)) > 0.60 and ((price - SellResistance) / (SellSupport - price)) > 0.40;

plot sellSignal = if showsell and BullishPriceTwist and SellSystem and SellPerfection and SellProbability and high < SellSupport and price > sellResistance then close else Double.NaN;

plot sellSupportLine = if sellSignal then SellSupport else Double.NaN;
plot sellResistanceLine = if sellSignal then SellResistance else Double.NaN;

Alert(sellSignal, "Sell Perfection", Alert.BAR, Sound.Bell);
Last edited:
@HighBredCloud this is a study. It is possible to adopt to a strategy though. It doesn't repaint. With limited testing, I found it has good results with 2000t.
I added it as a study on a 15 min chart...I need to see how it reacts...Have you tested other time frames other than tick charts to see where this indicator works the best?
Forgot to mention, I use k=8 and i=13 for 2000t chart. I am not sure what parameters will work better for different time frames.
@tabs999 arrows indicate buy or sell. dots indicate support and resistance. you may want to set stop losses at support and take profit at or above the resistance.
@technicallydreaming It will repaint as it is coded right now. Backtesting is not accurate. You should take trades after the bar closes.

I am looking into having it based on one previous bar so it doesn't repaint, or use the open price instead of close. Not sure how the performance will be with open price.
If it doesn't change after the bar closes, then it doesn't repaint. Repainting means it changes AFTER the bar the signal is on closes. All indicators based on Close will not be solid until the bar finishes closing.

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
424 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.