I need help converting this TV indicator into TOS please!! also if possible pain candles with the signal! thank you very much!! really appreciate

trading machine

New member
Platform
  1. Thinkorswim
  2. TradingView
//@version=4
//Full credit to AlexGrover: https://www.tradingview.com/script/...cient-Calculation-Of-Upper-Lower-Extremities/
study("G-Channel Trend Detection",shorttitle="G-Trend",overlay=true)
length = input(100),src = input(close)
//----
a = 0.,b = 0.
a := max(src,nz(a[1])) - nz(a[1] - b[1])/length
b := min(src,nz(b[1])) + nz(a[1] - b[1])/length
avg = avg(a,b)
//----
crossup = b[1] < close[1] and b > close
crossdn = a[1] < close[1] and a > close
bullish = barssince(crossdn) <= barssince(crossup)
c = bullish ? color.lime : color.red
//plot(a,"Upper",color=color.blue,linewidth=2,transp=100)
//plot(b,"Lower",color=color.blue,linewidth=2,transp=100)
p1=plot(avg,"Average",color=c,linewidth=1,transp=90)
p2=plot(close,"Close price",color=c,linewidth=1,transp=100)
fill(p1,p2,color=c,transp=90)

showcross = input(true)
plotshape(showcross and not bullish and bullish[1] ? avg : na, location=location.absolute, style=shape.labeldown, color=color.red, size=size.tiny, text="Sell", textcolor=#ffffff, transp=0, offset=-1)
plotshape(showcross and bullish and not bullish[1] ? avg : na, location=location.absolute, style=shape.labelup, color=color.lime, size=size.tiny, text="Buy", textcolor=#ffffff, transp=0, offset=-1)
 

barbaros

Administrator
Staff member
Very nice

mwRnI8l.png
 

barbaros

Administrator
Staff member
Please test...

Code:
# Converted for https://b4indicators.com/threads/i-need-help-converting-this-tv-indicator-into-tos-please-also-if-possible-pain-candles-with-the-signal-thank-you-very-much-really-appreciate.202/
# barbaros

def length = 100;
def src = close;

script nz {
    input val = close;
    plot result = if isNaN(val) then 0 else val;
}

def a;
def b;

a = max(src,nz(a[1])) - nz(a[1] - b[1])/length;
b = min(src,nz(b[1])) + nz(a[1] - b[1])/length;

def avg = (a + b)/2;

def crossup = b[1] < close[1] and b > close;
def crossdn = a[1] < close[1] and a > close;

def bullish = if crossup then no else if crossdn then yes else bullish[1];
def isBullish = bullish;

plot p1 = avg;

AddCloud(close, if isBullish then p1 else Double.NaN, color.green, color.green);
AddCloud(close, if !isBullish then p1 else Double.NaN, color.red, color.red);

AddChartBubble(isBullish and !isBullish[1], low, "Buy", Color.GREEN, no);
AddChartBubble(!isBullish and isBullish[1], high, "Sell", Color.RED, yes);

QnNcwCE.png
 

trading machine

New member
I was checking some symbols but is like a little different to the trading view.. can we check the futures market just to check if is me or could be the script.. thank you in advance
 

barbaros

Administrator
Staff member
Futures pricing between ToS and TradingView differs. It may calculate differently due to that. Also, there is this interpretation of bullish vs bearish in the original TradingView script:

bullish = barssince(crossdn) <= barssince(crossup)

Not sure if this was captured in the the ToS version correctly.
 

trading machine

New member
thank you very much all your help @barbaros , I did it a market replay on trading view it is not repaint the signal, also is look a bit different on TOS.i hope we can get it done right. the indicator look very good, I did it a backtesting for swing trading and day trading, the indicator is quite good.
 

barbaros

Administrator
Staff member
thank you very much all your help @barbaros , I did it a market replay on trading view it is not repaint the signal, also is look a bit different on TOS.i hope we can get it done right. the indicator look very good, I did it a backtesting for swing trading and day trading, the indicator is quite good.
You are not seeing the repainting because the replay only shows you when the bar closes. Signals are displayed one bar back.

Here is an example. At this bar, there is no signal.
a3W42vp.png


However, one bar later, the previous bar gets a signal.
h1GkdFp.png


Please share where the ToS port differs from the TradingView version. I think the 2 charts I posted in post #2 and #3 are the same, except the signal is shown on the correct bar.
 
Top