Ver 5
Ver 5
//
-----------------------------------------------------------------------------------
----------------------------------
// Inputs for Date Range
//
-----------------------------------------------------------------------------------
----------------------------------
start_date = input.time(timestamp("2024-10-10 00:00 +0000"), "Start Date",
group="Date Range")
end_date = input.time(timestamp("2069-01-01 00:00 +0000"), "End Date", group="Date
Range")
// Ensure that the indicator only runs within the specified date range
in_date_range = (time >= start_date and time <= end_date)
//
-----------------------------------------------------------------------------------
----------------------------------
// Inputs
//
-----------------------------------------------------------------------------------
----------------------------------
// LOWESS Inputs
length_lowess = input.int(30, minval=1, title="LOWESS Length", group="LOWESS")
color_up = input.color(#60befd, "Upward Movement Color", group="LOWESS Colors")
color_down = input.color(#ab61ff, "Downward Movement Color", group="LOWESS Colors")
// Oscillator Inputs
sourceType = input.string('rsi', 'Oscillator Source', ['rsi', 'cci', 'cmo', 'cog',
'mfi', 'roc', 'price'], group='Oscillator')
osc_length = input.int(14, 'Oscillator Length', minval=5, group='Oscillator')
bandType = input.string('bb', 'OB/OS Method', ['bb', 'kc', 'dc1', 'dc2'],
group='Bands')
bandLength = input.int(20, 'Band Length', minval=5, group='Bands')
multiplier = input.float(2, 'Band Multiplier', minval=0.5, group='Bands')
//
-----------------------------------------------------------------------------------
----------------------------------
// LOWESS Calculation
//
-----------------------------------------------------------------------------------
----------------------------------
lowess(src, length) =>
sum_w = 0.0
sum_wx = 0.0
sum_wy = 0.0
for i = 0 to length - 1
w = math.pow(1 - math.pow(i / length, 3), 3)
sum_w += w
sum_wx += w * i
sum_wy += w * src[i]
a = sum_wy / sum_w
b = sum_wx / sum_w
a + b / (length - 1) / 2000
smoothed_lowess = lowess(close, length_lowess)
lowess_up = smoothed_lowess > smoothed_lowess[2]
lowess_down = smoothed_lowess < smoothed_lowess[2]
smoothedColor = lowess_up ? color_up : color_down
//
-----------------------------------------------------------------------------------
----------------------------------
// Oscillator Calculation
//
-----------------------------------------------------------------------------------
----------------------------------
oscillator(simple string oscillatorType="rsi", float source, int length=14) =>
switch oscillatorType
"cci" => ta.cci(source, length)
"cmo" => ta.cmo(source, length)
"cog" => ta.cog(source, length)
"mfi" => ta.mfi(source, length)
"roc" => ta.roc(source, length)
"rsi" => ta.rsi(source, length)
=> ta.rsi(source, length)
//
-----------------------------------------------------------------------------------
----------------------------------
// Keltner Channel (kc) Function
//
-----------------------------------------------------------------------------------
----------------------------------
kc(source, highSource, lowSource, length, multiplier) =>
tr = math.max(source, highSource, lowSource) - math.min(source, highSource,
lowSource)
atr = ta.sma(tr, length)
mid = ta.sma(source, length)
[mid, mid + atr * multiplier, mid - atr * multiplier]
//
-----------------------------------------------------------------------------------
----------------------------------
// Donchian Channel (dc) Function
//
-----------------------------------------------------------------------------------
----------------------------------
dc(source, highSource, lowSource, length) =>
[ta.highest(highSource, length), ta.lowest(osc, length)]
//
-----------------------------------------------------------------------------------
----------------------------------
// Determine Overbought & Oversold Levels
//
-----------------------------------------------------------------------------------
----------------------------------
[middle, overbought, oversold] = switch bandType
'bb' => ta.bb(osc, bandLength, multiplier)
'kc' => kc(osc, high, low, bandLength, multiplier)
'dc1' =>
high_dc = ta.highest(osc, bandLength)
low_dc = ta.lowest(osc, bandLength)
[na, high_dc, low_dc]
'dc2' =>
high_dc2 = ta.highest(osc, bandLength)
low_dc2 = ta.lowest(osc, bandLength)
[na, high_dc2, low_dc2]
=> [na, na, na] // Default case
//
-----------------------------------------------------------------------------------
----------------------------------
// Over and Under Labels (Alertable Text)
//
-----------------------------------------------------------------------------------
----------------------------------
over_condition = osc > 81
under_condition = osc < 19
//
-----------------------------------------------------------------------------------
----------------------------------
// Long Entry Condition
//
-----------------------------------------------------------------------------------
----------------------------------
long_condition = close < smoothed_lowess and osc <= oversold and osc < 22
//
-----------------------------------------------------------------------------------
----------------------------------
// Short Entry Condition
//
-----------------------------------------------------------------------------------
----------------------------------
short_condition = close > smoothed_lowess and ta.crossover(osc, overbought) and osc
> 79
//
-----------------------------------------------------------------------------------
----------------------------------
// Long Exit Condition
//
-----------------------------------------------------------------------------------
----------------------------------
exit_long_condition = osc >= overbought and osc > 80
//
-----------------------------------------------------------------------------------
----------------------------------
// Short Exit Condition
//
-----------------------------------------------------------------------------------
----------------------------------
exit_short_condition = osc <= oversold and osc < 39
//
-----------------------------------------------------------------------------------
----------------------------------
// Plot Entry/Exit Signals with Text (Buy/Sell instead of shapes)
//
-----------------------------------------------------------------------------------
----------------------------------
plotchar(series=long_condition, location=location.belowbar, color=color.green,
size=size.tiny, offset=-1)
plotchar(series=short_condition, location=location.abovebar, color=color.red,
size=size.tiny, offset=1)
//
-----------------------------------------------------------------------------------
----------------------------------
// Consolidated Alert Condition for Over and Under
//
-----------------------------------------------------------------------------------
----------------------------------
mixed_over_under_alert = over_condition or under_condition
alertcondition(mixed_over_under_alert, title="Mixed Over/Under Alert",
message="{{ticker}} Over/Under!")
//
-----------------------------------------------------------------------------------
----------------------------------
// Other Alert Conditions
//
-----------------------------------------------------------------------------------
----------------------------------
alertcondition(close < osc, title="Trend Change", message="{{ticker}} below
Oscillator Trend.")
alertcondition(long_condition, title="Long Entry", message="{{ticker}}: Long
entry.")
alertcondition(short_condition, title="Short Entry", message="{{ticker}}: Short
entry.")
alertcondition(exit_long_condition, title="Exit Long", message="{{ticker}}: Exit
Long.")
alertcondition(exit_short_condition, title="Exit Short", message="{{ticker}}: Exit
Short.")
// Volume Spike Detection
highVolumeDistanceThreshold = input.int(90, "High Volume Distance Threshold (%)",
5, 100, 5)
volumeSpikeThreshold = input.int(85, "Volume Spike Threshold (%)", 5, 100, 5)
HighPivot = ta.pivothigh(PP,PP)
LowPivot = ta.pivotlow(PP,PP)
Correct_HighPivot = 0.0
Correct_LowPivot = 0.0
PASS = 0
// get data
if ArrayType.size() > 6
PT1 := ArrayType.get(ArrayType.size() - 1)
PT2 := ArrayType.get(ArrayType.size() - 2)
PT3 := ArrayType.get(ArrayType.size() - 3)
PT4 := ArrayType.get(ArrayType.size() - 4)
PT5 := ArrayType.get(ArrayType.size() - 5)
PV1 := ArrayValue.get(ArrayType.size() - 1)
PV2 := ArrayValue.get(ArrayType.size() - 2)
PV3 := ArrayValue.get(ArrayType.size() - 3)
PV4 := ArrayValue.get(ArrayType.size() - 4)
PV5 := ArrayValue.get(ArrayType.size() - 5)
PI1 := ArrayIndex.get(ArrayType.size() - 1)
PI3 := ArrayIndex.get(ArrayType.size() - 3)
PI5 := ArrayIndex.get(ArrayType.size() - 5)
//global condition
X = math.ceil((PI1 - PI5))
INF = math.floor((PI5 + X*0.375))
SUP = math.ceil((PI5 + X*0.625))
global_condition = PI3 > INF and PI3 < SUP
// Bearish 3 Drive
BeCondition1 = PT1 == 'HH' and PT2 == 'HL' and PT3 == 'HH' and PT4 == 'HL' and
PT5 == 'HH'
BeCondition2 = (PV3-PV2) / (PV1-PV3) > 1 and
(PV5-PV4) / (PV3-PV5) > 1 and
(PV1 - PV3) / (PV3 - PV5) > 1 and
global_condition
// Bullish 3 Drive
BuCondition1 = PT1 == 'LL' and PT2 == 'LH' and PT3 == 'LL' and PT4 == 'LH' and
PT5 == 'LL'
BuCondition2 = (PV2-PV3) / (PV3-PV1) > 1 and
(PV4-PV5) / (PV5-PV3) > 1 and
(PV3 - PV1) / (PV5 - PV3) > 1 and
global_condition
plotshape(Bearish3Drive ,
'Bearish 3 Drive' ,
style = shape.arrowdown ,
location = location.abovebar ,
color = color.red ,
textcolor = color.red)
plotshape(Bullish3Drive ,
'Bullish 3 Drive' ,
style = shape.arrowup ,
location = location.belowbar ,
color = color.green ,
textcolor = color.green )
if BullCond
BullLine := line.new(PI5 , PV5 , PI1 , PV1 , color = color.rgb(35, 124, 38)
, style = line.style_dashed)
label.new(PI5 , PV5 , '1' , color = color.rgb(35, 124, 38) , textcolor =
color.white , size = size.small , style = label.style_label_up)
label.new(PI3 , line.get_price(BullLine, PI3) , '2' , color =
color.rgb(35, 124, 38) , textcolor = color.white , size = size.small , style =
label.style_label_up)
label.new(PI1 , PV1 , '3' , color = color.rgb(35, 124, 38) , textcolor =
color.white , size = size.small , style = label.style_label_up)
if BearCond
BearLine := line.new(PI5 , PV5 , PI1 , PV1 , color = color.rgb(212, 16, 16)
, style = line.style_dashed)
label.new(PI5 , PV5 , '1' , color = color.rgb(212, 16, 16) , textcolor =
color.white , size = size.small , style = label.style_label_down)
label.new(PI3 , line.get_price(BearLine, PI3) , '2' , color =
color.rgb(212, 16, 16) , textcolor = color.white , size = size.small , style =
label.style_label_down)
label.new(PI1 , PV1 , '3' , color = color.rgb(212, 16, 16) , textcolor =
color.white , size = size.small , style = label.style_label_down)
Drawing(Bullish3Drive , Bearish3Drive)
// Define Big Mover as a Non-Doji Solid Candle that Engulfs the Previous One
bodySize3 = math.abs(close[3] - open[3])
range3 = high[3] - low[3]
bodySize4 = math.abs(close[4] - open[4])
nonDoji = bodySize3 >= range3 * 0.6 // Body is at least 60% of total range
engulfing = (open[3] < close[4] and close[3] > open[4]) or (open[3] > close[4] and
close[3] < open[4]) // Fully engulfs previous candle
// Rising Three (Big Bearish + 3 Consecutive Bullish Candles) - Now on 3rd candle
risingThree = bigCandle and close[3] < open[3] and threeBullish and withinRange
// Alert Conditions
alertcondition(risingThree, title="Rising-3 Signal", message="Rising Three pattern
detected!")
alertcondition(fallingThree, title="Falling-3 Signal", message="Falling Three
pattern detected!")
// Timeframe settings
tfH4 = "240" // 4-hour timeframe
tfH1 = "60" // 1-hour timeframe
//------------------------------------------------------------------------------
// CMF and RSI Calculations for H4
//------------------------------------------------------------------------------
highH4 = request.security(syminfo.tickerid, tfH4, high)
lowH4 = request.security(syminfo.tickerid, tfH4, low)
closeH4 = request.security(syminfo.tickerid, tfH4, close)
volumeH4 = request.security(syminfo.tickerid, tfH4, volume)
//------------------------------------------------------------------------------
// CMF and RSI Calculations for H1 (Evaluated Globally)
//------------------------------------------------------------------------------
highH1 = request.security(syminfo.tickerid, tfH1, high)
lowH1 = request.security(syminfo.tickerid, tfH1, low)
closeH1 = request.security(syminfo.tickerid, tfH1, close)
volumeH1 = request.security(syminfo.tickerid, tfH1, volume)
//------------------------------------------------------------------------------
// Visualizations with Text Bubble (Using plotchar)
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
// Alert Conditions
//------------------------------------------------------------------------------
alertcondition(chaikinLongH1, title="H1 Chaikin Signal",
message="{{ticker}}, Chaikin H1 Price: {{close}}")