Skip to content

Instantly share code, notes, and snippets.

@Toeron
Forked from basnijholt/cto_line.pine
Last active October 5, 2023 14:41
Show Gist options
  • Select an option

  • Save Toeron/8562affb4c6cd62a0e73ce59a895f394 to your computer and use it in GitHub Desktop.

Select an option

Save Toeron/8562affb4c6cd62a0e73ce59a895f394 to your computer and use it in GitHub Desktop.
CTO Line indicator for TradingView
//@version=4
study(title="CTO Line", shorttitle="CTO", overlay=true, resolution="1440")
smma(src, length) =>
smma = 0.0
smma := na(smma[1]) ? sma(src, length) : (smma[1] * (length - 1) + src) / length
smma
v1 = smma(hl2, 15)
m1 = smma(hl2, 19)
m2 = smma(hl2, 25)
v2 = smma(hl2, 29)
p2 = v1<m1 != v1<v2 or m2<v2 != v1<v2
p3 = not p2 and v1<v2
p1 = not p2 and not p3
c = p1 ? color.yellow : p2 ? color.silver : color.blue
line1 = plot(v1, "Line 1", color=c)
line2 = plot(v2, "Line 2", color=c)
fill(line1, line2, color=c)
//add buy signal when color.silver turns to yellow
cond1 = p2[1] and p1
cond2 = p2 and p1
g = cond1 ? color.yellow : cond2 ? color.yellow : na
//plot(close, "Close", color=g, style=plot.style_circles, linewidth=2, transp=80)
plotshape(cond1 or cond2, title="", style=shape.circle, size=size.small, location=location.abovebar, color=g, text="BUY")
//add sell signal when color.silver turns to blue
cond3 = p2[1] and p3
cond4 = p2 and p3
r = cond3 ? color.blue : cond4 ? color.blue : na
//plot(close, "Close", color=r, style=plot.style_circles, linewidth=2, transp=80)
plotshape(cond3 or cond4, title="", style=shape.circle, size=size.small, location=location.belowbar, color=r, text="SELL")
//add bullish alert when color.silver turns to yellow
alertcondition(cond1 or cond2, title='Golden Line Buy Alert', message='Golden Line Buy Alert')
//add bearish alert when color.silver turns to blue
alertcondition(cond3 or cond4, title='Golden Line Sell Alert', message='Golden Line Sell Alert')
@Toeron
Copy link
Author

Toeron commented Dec 6, 2022

added a buy, sell and alert signal on the chart.

@Toeron
Copy link
Author

Toeron commented Dec 6, 2022

cto_line pine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment