TOTAL3ES/ETH Mean Reversion

NickBencino · study · 104 行 · 点赞 614 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=5
indicator("TOTAL3ES/ETH Mean Reversion", shorttitle="T3E_MR", overlay=true)
 
// Chart validation - only works on TOTAL3ES/ETH ratio
is_correct_chart = str.contains(syminfo.ticker, "TOTAL3ES") and str.contains(syminfo.ticker, "ETH")
if not is_correct_chart
    runtime.error("This indicator is designed specifically for CRYPTOCAP:TOTAL3ES/CRYPTOCAP:ETH chart only")
 
// Historical extremes and key levels
HISTORICAL_LOW = 0.64    // July 2017 low
HISTORICAL_HIGH = 3.49   // All-time high
MIDPOINT = (HISTORICAL_LOW + HISTORICAL_HIGH) / 2  // ~2.065
PARITY = 1.0            // The key psychological level
 
// Input parameters
show_zones = input.bool(true, title="Show Reversion Zones", group="Display")
show_midpoint = input.bool(true, title="Show Midpoint", group="Display")
show_parity = input.bool(true, title="Show Parity Line", group="Display")
zone_transparency = input.int(85, title="Zone Transparency", minval=70, maxval=95, group="Display")
 
// Mean reversion calculation
reversion_strength = input.int(20, title="Reversion Strength Period", minval=10, maxval=50, group="Calculation")
extreme_threshold = input.float(0.8, title="Extreme Threshold (0-1)", minval=0.5, maxval=1.0, step=0.1, group="Calculation")
 
// Calculate current position within historical range
range_size = HISTORICAL_HIGH - HISTORICAL_LOW
current_position = (close - HISTORICAL_LOW) / range_size
 
// Define reversion zones
upper_extreme = HISTORICAL_LOW + (range_size * extreme_threshold)  // ~2.92 at 0.8 threshold
lower_extreme = HISTORICAL_LOW + (range_size * (1 - extreme_threshold))  // ~1.21 at 0.8 threshold
 
// Mean reversion signals
sma_mid = ta.sma(close, reversion_strength)
distance_from_mid = math.abs(close - MIDPOINT)
max_distance = math.max(MIDPOINT - HISTORICAL_LOW, HISTORICAL_HIGH - MIDPOINT)
reversion_pressure = distance_from_mid / max_distance
 
// Signal conditions
in_upper_extreme = close > upper_extreme
in_lower_extreme = close < lower_extreme
extreme_reversion_signal = (in_upper_extreme and close < close[1]) or (in_lower_extreme and close > close[1])
 
// Plot historical levels
plot(show_parity ? PARITY : na, title="Parity (1.0)", color=color.new(color.white, 0), linewidth=2, style=plot.style_line)
plot(show_midpoint ? MIDPOINT : na, title="Historical Midpoint", color=color.new(color.yellow, 20), linewidth=2, style=plot.style_line)
 
// Plot extreme levels
plot(HISTORICAL_HIGH, title="Historical High (3.49)", color=color.new(color.red, 30), linewidth=1, style=plot.style_line)
plot(HISTORICAL_LOW, title="Historical Low (0.64)", color=color.new(color.green, 30), linewidth=1, style=plot.style_line)
 
// Reversion zones
upper_zone = plot(show_zones ? upper_extreme : na, title="Upper Reversion Zone", color=color.new(color.red, 50), linewidth=1)
lower_zone = plot(show_zones ? lower_extreme : na, title="Lower Reversion Zone", color=color.new(color.green, 50), linewidth=1)
 
// Fill reversion zones
high_plot = plot(HISTORICAL_HIGH, color=color.new(color.white, 100))
low_plot = plot(HISTORICAL_LOW, color=color.new(color.white, 100))
 
fill(high_plot, upper_zone, color=color.new(color.red, zone_transparency), title="Bearish Reversion Zone")
fill(lower_zone, low_plot, color=color.new(color.green, zone_transparency), title="Bullish Reversion Zone")
 
// Reversion signals removed - focus on zones and levels instead
 
// Background coloring removed for cleaner chart
// bgcolor_color = current_position > 0.8 ? color.new(color.red, 95) : current_position < 0.2 ? color.new(color.green, 95) : math.abs(close - PARITY) < 0.1 ? color.new(color.yellow, 95) : na
// bgcolor(bgcolor_color, title="Position Background")
 
// Alert conditions for entering extreme zones
alertcondition(close > upper_extreme and close[1] <= upper_extreme, title="Entered Extreme High Zone", 
               message="TOTAL3ES/ETH entered extreme high zone - potential mean reversion candidate")
alertcondition(close < lower_extreme and close[1] >= lower_extreme, title="Entered Extreme Low Zone", 
               message="TOTAL3ES/ETH entered extreme low zone - potential mean reversion candidate")
alertcondition(ta.crossover(close, PARITY), title="Above Parity", 
               message="TOTAL3ES/ETH crossed above parity (1.0) - altcoins > ETH marketcap")
alertcondition(ta.crossunder(close, PARITY), title="Below Parity", 
               message="TOTAL3ES/ETH crossed below parity (1.0) - ETH > altcoins marketcap")
 
// Information table
if barstate.islast and show_zones
    var table info_table = table.new(position.bottom_right, 2, 7, bgcolor=color.new(color.black, 20), border_width=1, frame_width=1, frame_color=color.gray)
    
    table.cell(info_table, 0, 0, "Current Ratio", text_color=color.white, text_size=size.small, bgcolor=color.new(color.blue, 70))
    table.cell(info_table, 1, 0, str.tostring(close, "#.###"), text_color=color.white, text_size=size.small)
    
    table.cell(info_table, 0, 1, "Range Position", text_color=color.white, text_size=size.small, bgcolor=color.new(color.blue, 70))
    table.cell(info_table, 1, 1, str.tostring(current_position * 100, "#.#") + "%", text_color=color.white, text_size=size.small)
    
    table.cell(info_table, 0, 2, "From Parity", text_color=color.white, text_size=size.small, bgcolor=color.new(color.blue, 70))
    table.cell(info_table, 1, 2, str.tostring((close - PARITY) / PARITY * 100, "#.#") + "%", text_color=color.white, text_size=size.small)
    
    table.cell(info_table, 0, 3, "Reversion Pressure", text_color=color.white, text_size=size.small, bgcolor=color.new(color.blue, 70))
    table.cell(info_table, 1, 3, str.tostring(reversion_pressure * 100, "#.#") + "%", text_color=color.white, text_size=size.small)
    
    table.cell(info_table, 0, 4, "Zone", text_color=color.white, text_size=size.small, bgcolor=color.new(color.blue, 70))
    zone_text = in_upper_extreme ? "EXTREME HIGH" : in_lower_extreme ? "EXTREME LOW" : math.abs(close - PARITY) < 0.1 ? "NEAR PARITY" : "NORMAL"
    zone_color = in_upper_extreme ? color.red : in_lower_extreme ? color.lime : color.white
    table.cell(info_table, 1, 4, zone_text, text_color=zone_color, text_size=size.small)
    
    table.cell(info_table, 0, 5, "Historical Range", text_color=color.white, text_size=size.small, bgcolor=color.new(color.purple, 70))
    table.cell(info_table, 1, 5, "0.64 - 3.49", text_color=color.white, text_size=size.small)
    
    table.cell(info_table, 0, 6, "Midpoint", text_color=color.white, text_size=size.small, bgcolor=color.new(color.purple, 70))
    table.cell(info_table, 1, 6, str.tostring(MIDPOINT, "#.###"), text_color=color.white, text_size=size.small)

← 返回列表