本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AYEHAN
//@version=6
//@description [Cryptonian] Fibonacci confluence geometry v1. Chart-free, deterministic, bounded comparison of confirmed swings.
// No input, chart drawings, data requests, future-looking logic or trade signals.
library("CryptonianFibConfluence", overlay = false)
//@type A proposed confluence from TWO distinct, confirmed swing degrees.
//@field found True when a qualified cross-degree retracement match exists.
//@field id Assigned by the host, not by this mathematical search.
//@field localSwingId Identifier of the contributing local swing.
//@field majorSwingId Identifier of the contributing major swing.
//@field localRatio Local retracement ratio used.
//@field majorRatio Major retracement ratio used.
//@field localLevel Absolute local price level.
//@field majorLevel Absolute major price level.
//@field lowerPrice Lower of the two contributing retracement levels.
//@field upperPrice Upper of the two contributing retracement levels.
//@field gap Absolute distance separating the two levels.
//@field publishedBar Filled by host only on confirmed bar.
//@field publishedTime Filled by host only on confirmed bar.
//@field checkedPairs Number of deterministic ratio comparisons inspected.
export type Cluster
bool found = false
int id = 0
int localSwingId = 0
int majorSwingId = 0
float localRatio = na
float majorRatio = na
float localLevel = na
float majorLevel = na
float lowerPrice = na
float upperPrice = na
float gap = na
int publishedBar = na
int publishedTime = na
int checkedPairs = 0
// Ratios intentionally limited for first confluence module.
// Broader Fibonacci geometries belong to later, separately auditable phases.
ratioFor(int index) =>
switch index
0 => 0.382
1 => 0.5
2 => 0.618
3 => 0.786
=> float(na)
//@function Find the closest matching retracements of two distinct confirmed swing degrees.
//@param la Start price of local movement.
//@param lb End price of local movement.
//@param ma Start price of major movement.
//@param mb End price of major movement.
//@param lFromBar Original bar of local start anchor.
//@param lToBar Original bar of local end anchor.
//@param mFromBar Original bar of major start anchor.
//@param mToBar Original bar of major end anchor.
//@param lId Host-assigned local confirmed swing identity.
//@param mId Host-assigned major confirmed swing identity.
//@param tolerance Absolute maximum price distance between the two retracement levels.
//@returns Deterministic best match or found=false. NO probability or BUY/SELL prediction.
export find(float la, float lb, float ma, float mb, int lFromBar, int lToBar, int mFromBar, int mToBar, int lId, int mId, float tolerance) =>
Cluster result = Cluster.new()
bool validInput = not na(la) and not na(lb) and not na(ma) and not na(mb) and not na(lFromBar) and not na(lToBar) and not na(mFromBar) and not na(mToBar) and not na(tolerance) and tolerance > 0 and lId > 0 and mId > 0 and la != lb and ma != mb
bool duplicateAnchors = validInput and lFromBar == mFromBar and lToBar == mToBar
bool sameDirection = validInput and ((lb > la and mb > ma) or (lb < la and mb < ma))
// Same pair in two pivot scanners is one piece of evidence, NOT confluence.
if validInput and not duplicateAnchors and sameDirection
float bestGap = na
for i = 0 to 3
float localR = ratioFor(i)
float localP = lb + (la - lb) * localR
for j = 0 to 3
float majorR = ratioFor(j)
float majorP = mb + (ma - mb) * majorR
float candidateGap = math.abs(localP - majorP)
result.checkedPairs := result.checkedPairs + 1
if candidateGap <= tolerance and (na(bestGap) or candidateGap < bestGap)
bestGap := candidateGap
result.found := true
result.localRatio := localR
result.majorRatio := majorR
result.localLevel := localP
result.majorLevel := majorP
result.lowerPrice := math.min(localP, majorP)
result.upperPrice := math.max(localP, majorP)
result.gap := candidateGap
result.localSwingId := lId
result.majorSwingId := mId
result