TD Perfection Indicator for ThinkorSwim

barbaros

Well-known member
VIP
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.

r0OYpVv.png


Code:
# 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;
buySignal.SetDefaultColor(Color.WHITE);
buySignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);

plot buySupportLine = if buySignal then BuySupport else Double.NaN;
buySupportLine.SetDefaultColor(Color.WHITE);
buySupportLine.SetPaintingStrategy(PaintingStrategy.POINTS);
plot buyResistanceLine = if buySignal then BuyResistance else Double.NaN;
buyResistanceLine.SetPaintingStrategy(PaintingStrategy.POINTS);
buyResistanceLine.SetDefaultColor(Color.WHITE);

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;
sellSignal.SetDefaultColor(Color.WHITE);
sellSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);

plot sellSupportLine = if sellSignal then SellSupport else Double.NaN;
sellSupportLine.SetDefaultColor(Color.WHITE);
sellSupportLine.SetPaintingStrategy(PaintingStrategy.POINTS);
plot sellResistanceLine = if sellSignal then SellResistance else Double.NaN;
sellResistanceLine.SetDefaultColor(Color.WHITE);
sellResistanceLine.SetPaintingStrategy(PaintingStrategy.POINTS);

Alert(sellSignal, "Sell Perfection", Alert.BAR, Sound.Bell);
 
Last edited:

barbaros

Well-known member
VIP
@HighBredCloud this is a study. It is possible to adopt to a strategy though. With limited testing, I found it has good results with 2000t.
 
Last edited:

HighBredCloud

Well-known member
VIP
@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?
 

barbaros

Well-known member
VIP
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.
 

barbaros

Well-known member
VIP
@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.
 

barbaros

Well-known member
VIP
@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.
 

TrueDepth

Member
VIP
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.
 

Similar threads

Top