﻿// UBFX - QTI
// © RussManJoe


//@version=6
indicator(title = 'UBFX - QTI', shorttitle = 'UBFX - QTI', overlay = false)


// Inputs for QTI settings
lengthQTI1 = input.int(defval = 13, title = 'QTI Length 1', minval = 1)
lengthQTI2 = input.int(defval = 21, title = 'QTI Length 2', minval = 1)


// Calculate QTI values
qti1 = ta.cci(hlc3, lengthQTI1)
qti2 = ta.cci(hlc3, lengthQTI2)


// Define colors based on QTI conditions
above_zero_color = color.rgb(41, 98, 255) // UBFX Blue
below_zero_color = color.rgb(255, 0, 0) // Red
mixed_color = color.rgb(100, 100, 100, 50) // Grey


// Plot histogram bars based on QTI conditions
plot(qti1 > 0 and qti2 > 0 ? 1 : na, color = above_zero_color, title = 'Both QTIs Above 0', style = plot.style_histogram, linewidth = 2)
plot(qti1 < 0 and qti2 < 0 ? 1 : na, color = below_zero_color, title = 'Both QTIs Below 0', style = plot.style_histogram, linewidth = 2)
plot(qti1 > 0 and qti2 < 0 or qti1 < 0 and qti2 > 0 ? 1 : na, color = mixed_color, title = 'One QTI Above 0 and One Below 0', style = plot.style_histogram, linewidth = 2)


// Enable Alerts
enable_buy_alerts = input.bool(true, 'Enable BUY Alert')
enable_sell_alerts = input.bool(true, 'Enable SELL Alert')


// Alerts
buyCondition = qti1 > 0 and qti2 > 0 and (qti1[1] <= 0 or qti2[1] <= 0)
sellCondition = qti1 < 0 and qti2 < 0 and (qti1[1] >= 0 or qti2[1] >= 0)


// Alert conditions
alertcondition(enable_buy_alerts and buyCondition, title = 'BUY Signal', message = 'QTI BUY Signal')
alertcondition(enable_sell_alerts and sellCondition, title = 'SELL Signal', message = 'QTI SELL Signal')