Convert Tradingview Tom DeMark Sequential Combo

EastMan

New member
Hello Team. Can anyone suggest a conversion of this Tradingview script into TOS?

Code:
study("TD Sequential",overlay=true)
PlotTheSetup = input(true)
SetupLimit = input(9, minval=5, maxval=13)
PlotTheCountdown = input(true)
CountdownLimit = input(13, minval=8, maxval=16)
ShowSetupSells = input(true)
ShowCountdownSells = input(true)
hundred_ = 100

//**** FUNCTIONS
num_hundreds(value) =>
    f = floor(value / 100)
    h = value > 0 and value % 100 == 0 ? f-1 : f

//TD Setup series
TdSetupSell = close > close[4] ?nz(TdSetupSell[1])+1:0
TdSetupBuy = close < close[4] ?nz(TdSetupBuy[1])+1:0


PlotSellSetup = PlotTheSetup and TdSetupSell <= SetupLimit
//**** Plot Sell setup
plotchar(PlotSellSetup ?(TdSetupSell==1?true:na):na,char='1',color=green,size=size.auto)
plotchar(PlotSellSetup?(TdSetupSell==2?true:na):na,char='2',color=green,size=size.auto)
plotchar(PlotSellSetup?(TdSetupSell==3?true:na):na,char='3',color=green,size=size.auto)
plotchar(PlotSellSetup?(TdSetupSell==4?true:na):na,char='4',color=green,size=size.auto)
plotchar(PlotSellSetup?(TdSetupSell==5?true:na):na,char='5',color=green,size=size.auto)
plotchar(PlotSellSetup?(TdSetupSell==6?true:na):na,char='6',color=green,size=size.auto)
plotchar(PlotSellSetup?(TdSetupSell==7?true:na):na,char='7',color=green,size=size.auto)
plotchar(PlotSellSetup?(TdSetupSell==8?true:na):na,char='8',color=green,size=size.auto)
plotchar(PlotSellSetup?(TdSetupSell==9?true:na):na,char='9',color=green,size=size.auto)
plotchar(PlotSellSetup?(TdSetupSell==10?true:na):na,char='', text='10',color=green,size=size.auto)
plotchar(PlotSellSetup?(TdSetupSell==11?true:na):na,char='',text='11',color=green,size=size.auto)
plotchar(PlotSellSetup?(TdSetupSell==12?true:na):na,char='',text='12',color=green,size=size.auto)
plotchar(PlotSellSetup?(TdSetupSell==13?true:na):na,char='',text='13',color=green,size=size.auto)
plotshape(ShowSetupSells?(TdSetupSell==SetupLimit?true:na):na, "Sell Setup", style=shape.triangledown,color=red,size=size.normal,location=location.top,text='Setup End')


PlotBuySetup = PlotTheSetup and TdSetupBuy <= SetupLimit
//**** Plot Buy setup
plotchar(PlotBuySetup?(TdSetupBuy==1?true:na):na,char='1',color=red,size=size.auto)
plotchar(PlotBuySetup?(TdSetupBuy==2?true:na):na,char='2',color=red,size=size.auto)
plotchar(PlotBuySetup?(TdSetupBuy==3?true:na):na,char='3',color=red,size=size.auto)
plotchar(PlotBuySetup?(TdSetupBuy==4?true:na):na,char='4',color=red,size=size.auto)
plotchar(PlotBuySetup?(TdSetupBuy==5?true:na):na,char='5',color=red,size=size.auto)
plotchar(PlotBuySetup?(TdSetupBuy==6?true:na):na,char='6',color=red,size=size.auto)
plotchar(PlotBuySetup?(TdSetupBuy==7?true:na):na,char='7',color=red,size=size.auto)
plotchar(PlotBuySetup?(TdSetupBuy==8?true:na):na,char='8',color=red,size=size.auto)
plotchar(PlotBuySetup?(TdSetupBuy==9?true:na):na,char='9',color=red,size=size.auto)
plotchar(PlotBuySetup?(TdSetupBuy==10?true:na):na,char='',text='10',color=red,size=size.auto)
plotchar(PlotBuySetup?(TdSetupBuy==11?true:na):na,char='',text='11',color=red,size=size.auto)
plotchar(PlotBuySetup?(TdSetupBuy==12?true:na):na,char='',text='12',color=red,size=size.auto)
plotchar(PlotBuySetup?(TdSetupBuy==13?true:na):na,char='',text='13',color=red,size=size.auto)

plotshape(ShowSetupSells?(TdSetupBuy==SetupLimit?true:na):na, "Buy Setup", style=shape.triangleup,color=green,size=size.normal,location=location.bottom,text='Setup End')

//------------//
// Sell Setup //
//------------//
PriceHasFlippedSell = barssince(close<close[4])
IsSellSetup = close>close[4] and PriceHasFlippedSell
sell = IsSellSetup and barssince(PriceHasFlippedSell!=SetupLimit)

//**** TD Countdown for sell //
TdSellCountdown = iff(sell, 0,
                  iff(TdSetupSell < SetupLimit +1, 0,
                  iff(close > high[2] and TdSellCountdown[1] > hundred_,TdSellCountdown[1]- (num_hundreds(TdSellCountdown[1]) * hundred_) + 1,
                  iff(close > high[2],nz(TdSellCountdown[1])+1,TdSellCountdown[1] + hundred_))))

PlotSellCountdown = PlotTheCountdown and TdSetupSell > SetupLimit and TdSellCountdown <= CountdownLimit
//*** Plot TD sell Countdown //
plotchar(PlotSellCountdown?(TdSellCountdown == 1?true:na):na,char='',text='1',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 2?true:na):na,char='',text='2',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 3?true:na):na,char='',text='3',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 4?true:na):na,char='',text='4',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 5?true:na):na,char='',text='5',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 6?true:na):na,char='',text='6',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 7?true:na):na,char='',text='7',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 8?true:na):na,char='',text='8',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 9?true:na):na,char='',text='9',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 10?true:na):na,char='',text='10',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 11?true:na):na,char='',text='11',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 12?true:na):na,char='',text='12',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 13?true:na):na,char='',text='13',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 14?true:na):na,char='',text='14',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 15?true:na):na,char='',text='15',size=size.tiny,color=lime,location=location.belowbar)
plotchar(PlotSellCountdown?(TdSellCountdown == 16?true:na):na,char='',text='16',size=size.tiny,color=lime,location=location.belowbar)

plotshape(ShowCountdownSells?(TdSetupSell > SetupLimit and TdSellCountdown == CountdownLimit?true:na):na, "Sell Countdown", style=shape.arrowdown,color=red,size=size.normal,location=location.top,text='Countdown End')

//----------//
// Buy setup//
//----------//
PriceHasFlippedBuy = barssince(close>close[4])
IsBuySetup = close<close[4] and PriceHasFlippedBuy
buy = IsBuySetup and barssince(PriceHasFlippedBuy!=SetupLimit)

//**** TD Countdown for Buy //
TdBuyCountdown = iff(buy, 0,
                  iff(TdSetupBuy < SetupLimit + 1, 0,
                  iff(close < low[2] and TdBuyCountdown[1] > hundred_,TdBuyCountdown[1]- (num_hundreds(TdBuyCountdown[1]) * hundred_) + 1,
                  iff(close < low[2],nz(TdBuyCountdown[1])+1,TdBuyCountdown[1] + hundred_))))

PlotBuyCountdown = PlotTheCountdown and TdSetupBuy > SetupLimit and TdBuyCountdown <= CountdownLimit
//*** Plot TD buy Countdown //
plotchar(PlotBuyCountdown?(TdBuyCountdown == 1?true:na):na,char='',text='1',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 2?true:na):na,char='',text='2',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 3?true:na):na,char='',text='3',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 4?true:na):na,char='',text='4',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 5?true:na):na,char='',text='5',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 6?true:na):na,char='',text='6',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 7?true:na):na,char='',text='7',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 8?true:na):na,char='',text='8',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 9?true:na):na,char='',text='9',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 10?true:na):na,char='',text='10',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 11?true:na):na,char='',text='11',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 12?true:na):na,char='',text='12',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 13?true:na):na,char='',text='13',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 14?true:na):na,char='',text='14',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 15?true:na):na,char='',text='15',size=size.tiny,color=maroon,location=location.belowbar)
plotchar(PlotBuyCountdown?(TdBuyCountdown == 16?true:na):na,char='',text='16',size=size.tiny,color=maroon,location=location.belowbar)

plotshape(ShowCountdownSells?(TdSetupBuy > SetupLimit and TdBuyCountdown == CountdownLimit?true:na):na,"Buy Countdown", style=shape.arrowup,color=green,size=size.normal,location=location.bottom,text='Countdown End')
 

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