Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
3.7 kB
3
Indexable
Never
//@version=5
indicator(title="Combined SAR and CTI", overlay=true, max_labels_count=500)

// Parabolik SAR
start = input(0.02)
increment = input(0.02)
maximum = input(0.2, "Max Value")
sar_out = ta.sar(start, increment, maximum)
plot(sar_out, "Parabolik SAR", style=plot.style_cross, color=#2962FF)
cross_color = color.new(#020202, 72)

var int sar_counter = 0
var label sar_label = na

label_color = input(color.new(color.white, 100), title="SAR Label Color")
label_offset = input(5, title="SAR Label Offset")

if (sar_out > close and sar_out[1] > close[1]) or (sar_out < close and sar_out[1] < close[1])
    sar_counter := sar_counter + 1
else
    sar_counter := 1

if sar_counter == 3 or sar_counter == 6 or sar_counter == 9
    if barstate.isconfirmed 
        // Adjust the label's position to avoid being too close to the SAR bars
        sar_label := label.new(bar_index, sar_out + label_offset * syminfo.mintick, str.tostring(sar_counter), color=label_color, style=label.style_none)


// Coral Trend Indicator (CTI)
src = input(close, title='CTI Source')
sm = input(21, title='CTI Smoothing Period')
cd = input(0.4, title='CTI Constant D')

bar_col = input(false, title='CTI Color Bars')
flat = input(color.new(color.blue, 0), title='CTI Line')

raise = input(color.new(color.green, 0), title='CTI Raise Color')
fall = input(color.new(color.red, 0), title='CTI Fall Color')

di = (sm - 1.0) / 2.0 + 1.0
c1 = 2 / (di + 1.0)
c2 = 1 - c1
c3 = 3.0 * (cd * cd + cd * cd * cd)
c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd

var float cti_i1 = na
var float cti_i2 = na
var float cti_i3 = na
var float cti_i4 = na
var float cti_i5 = na
var float cti_i6 = na

cti_i1 := c1 * src + c2 * nz(cti_i1[1])
cti_i2 := c1 * cti_i1 + c2 * nz(cti_i2[1])
cti_i3 := c1 * cti_i2 + c2 * nz(cti_i3[1])
cti_i4 := c1 * cti_i3 + c2 * nz(cti_i4[1])
cti_i5 := c1 * cti_i4 + c2 * nz(cti_i5[1])
cti_i6 := c1 * cti_i5 + c2 * nz(cti_i6[1])

cti_Cto = -cd * cd * cd * cti_i6 + c3 * cti_i5 + c4 * cti_i4 + c5 * cti_i3

var int cti_counter = 0

cti_bfrC = cti_Cto > nz(cti_Cto[1]) ? raise : cti_Cto < nz(cti_Cto[1]) ? fall : na
cti_tc = bar_col ? flat : cti_bfrC

distance_between_bars = input(3, title='CTI Distance Between Bars')

plot(cti_Cto, title='CTI Trend', linewidth=3, style=plot.style_circles, color=cti_tc, editable=false)

if barstate.isconfirmed
    if cti_bfrC == cti_bfrC[1]
        cti_counter := cti_counter + 1
        if cti_counter > 9
            cti_counter := 1
    else
        cti_counter := 1

    if cti_counter == 3 or cti_counter == 6 or cti_counter == 9
        label.new(bar_index, cti_Cto + distance_between_bars * syminfo.mintick, str.tostring(cti_counter), color=color.new(color.white, 100), style=label.style_none)



//kesisimde mum rengini mor yapar
crossunder_condition = ta.crossover(sar_out, cti_Cto)
crossover_condition = ta.crossunder(sar_out, cti_Cto)

//barcolor(crossunder_condition or crossover_condition ? cross_color : na) //mum rengini yapar


bgcolor(crossunder_condition or crossover_condition ? cross_color : na) //arka fonu renkli yapar



//psar_above = ta.psar(high, low, 0.02, 0.2)
//psar_below = ta.psar(low, high, 0.02, 0.2)

//crossunder_condition_above = ta.crossover(cti_Cto, psar_above)
//crossover_condition_below = ta.crossunder(cti_Cto, psar_below)

//cross_color_above = color.new(color.green, 90)
//cross_color_below = color.new(color.red, 90)

//bgcolor(crossunder_condition_above ? cross_color_above : na)
//bgcolor(crossover_condition_below ? cross_color_below : na)
Leave a Comment