Untitled
unknown
plain_text
a year ago
2.8 kB
10
Indexable
//@version=5
indicator("RSN KULE ORJ", overlay = true, max_lines_count = 40)
// INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
length = input.int(28, "Trend")
target = 0
// }
// VARIABLES ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
var bool trend = na
float trend_value = na
// Colors
color up_color = #06b690
color dn_color = #b60606
// ATR for calculating stop loss and target levels
series float atr_value = ta.sma(ta.atr(100), 100) * 0.8
// Moving averages for trend detection
series float sma_high = ta.sma(high, length) + atr_value
series float sma_low = ta.sma(low, length) - atr_value
color plot_color = color.new(chart.fg_color, 80)
// UDT for managing lines and labels
type TrendTargets
line[] lines
label[] labels
// Initialize UDT
var TrendTargets targets_up = TrendTargets.new(array.new_line(), array.new_label())
var TrendTargets targets_down = TrendTargets.new(array.new_line(), array.new_label())
// }
// CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
// Determine trend based on crossovers
if ta.crossover(close, sma_high) and barstate.isconfirmed
trend := true
if ta.crossunder(close, sma_low) and barstate.isconfirmed
trend := false
trend_value := switch
trend => sma_low
not trend => sma_high
trend_color = trend ? up_color : not trend ? dn_color : na
// Plot candlesticks with trend color
plotcandle(open, high, low, close,
title = 'Title',
color = trend_color,
wickcolor = trend_color,
bordercolor = trend_color)
// Plot trailing stops
// p1 = plot(trend ? trend_value : na, style = plot.style_linebr, color = plot_color)
// p2 = plot(not trend ? trend_value : na, style = plot.style_linebr, color = plot_color)
p0 = plot(hl2, display = display.none, editable = false)
// fill(p1, p0, trend_value, hl2, color.new(chart.fg_color, 90), na)
// fill(p2, p0, trend_value, hl2, color.new(chart.fg_color, 90), na)
Editor is loading...
Leave a Comment