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')