PINE LIBRARY
Updated

EWCoreLib

310
EWCoreLib — Elliott Wave Pattern Evaluation Library

Overview

EWCoreLib is a Pine Script v6 library of exported functions that validate and score Elliott Wave price patterns. It has no chart output of its own and is not meant to be added to a chart; a calling script supplies the pivot data and decides what to do with the results.

It is one of three scripts published together: the EWCore indicator, this library, and EWCore Docs, an on-chart reference panel for EWCore.

If you are using EWCore, there is nothing to do here. EWCore pulls in this library itself, as part of its own code — you add EWCore to your chart and the library comes with it. This page exists for Pine programmers who want to call these functions from a script of their own, and as the open source behind EWCore's evaluation stage. The dependency runs one way only: EWCore needs this library, the library needs nothing from EWCore, and any script that can produce its own pivot series can use it.

Relation to the earlier publication

An earlier version of this library was published under the name EWCoreEvaluators. This publication continues the same codebase under a new name; it is not a variant or a competing implementation. The name changed because the earlier title stays bound to the earlier publication and cannot be reused. Any script that imports the old path should be pointed at Wick-Sniper/EWCoreLib, which is the one that receives further work.

Concepts

Pivots in, verdicts out. Every evaluator takes a pivot series — prices and bar positions in two parallel arrays — plus a starting index, and asks one question about the window beginning there: does this stretch of price form the pattern I check for? The answer comes back as a filled WaveCount object carrying the wave points, the hard-rule verdict, the component scores and an invalidation level, or as an empty one if the window does not qualify.

Configuration travels as an object, not as a parameter list. An exported function cannot read the global variables of the script importing it, and these evaluators need a great many settings — tolerances, score weights, Fibonacci levels, feature toggles. Passing them individually would mean unwieldy signatures that break on every added option. Instead the calling script builds one EngineConfig object per bar and hands it to whichever functions it calls.

Every exported function is pure. Parameters in, values out, no hidden state. That is what makes it safe to call the same evaluator from several contexts in one bar — a forward search, a historical chain walk, a sub-wave decomposition — without behaviour drifting between them.

Marginal violations are penalised, not rejected. A candidate that misses a rule by a hair is scored down rather than discarded, so a near-miss reading stays visible and comparable instead of vanishing silently.

Exported types

WaveCount — one complete candidate scenario: pattern type, direction, degree label, wave points and their bars, hard-rule and overlap flags, component scores, confidence tier, invalidation level, extension info.
EngineConfig — the settings bundle described above.

Exported functions, by purpose

Pattern evaluation — one per pattern in the canon this project supports: evaluateImpulseWindow, evaluateDiagonalWindow, evaluateZigzagFlatWindow, evaluateTriangleWindow, evaluateComboWXYWindow, evaluateComboWXYXZWindow, evaluateImpulseRecoveredWindow (rebuilds an impulse whose fourth wave the coarse pivot pass swallowed), evaluateLegWhole (judges a whole leg as a single structure rather than a chain of fragments).

Type arbitration — f_discriminateWindow, f_evalWindowTrio: when impulse, diagonal and triangle all pass on the same window, these decide which type the window really is, so the least strict pattern cannot win by default.

Re-checking and scoring — revalidateCandidate, f_comboBonus, f_dpEdgeModifier, f_legDominance, f_legWholeDominance, f_evalCandDegStep, f_evalFloorLeg, f_candDegPasses, f_floorLegPasses.

Chain and gap handling — f_realGapFill (dynamic-programming best-path search for a continuous chain of valid patterns across a pivot series), f_gapNoiseMetrics, f_depth2InnerLegs.

Degree handling — getDegreeLabel, shiftDegreeUp, shiftDegreeDown, f_degreeNameFor, f_notatedLabelTextArray: translate between Elliott degrees and the notation that belongs to each.

Explanatory text — f_patternExplanation, f_extGlyph, f_extTooltip, f_atomicDiagText, f_gapBridgeText, f_rankStage, f_rankWhy, impulseFunnelText, comboFunnelText: turn a verdict into readable reasoning for labels and tooltips.

Drawing helpers — drawImpulseFunnel, drawComboFunnel, f_drawWholeLegFallback, f_drawWholeLegFallbackFromPivots, f_drawWholeLegFallbackFromArrays, f_drawExplanationLabel, f_drawDateMarker, f_drawRoutedLeg.

Utilities — subLowerBound, f_barValToTime (resolves a stored bar value to a timestamp; historical drawings need xloc.bar_time), getLabelSize, f_lineStyle, f_frameCount.

Calling it from your own script

This section is for Pine programmers writing their own script. EWCore users can skip it — EWCore handles the import itself.

import Wick-Sniper/EWCoreLib/1 as ewcore

Type the alias by hand. The "copy to clipboard" button on the library page appends the library name a second time and produces an import line that does not resolve.

From there, build an EngineConfig once per bar, then call the evaluator for the pattern and window you are testing and read the returned WaveCount.

Notes

This library validates structure; it does not detect pivots. The quality of everything it returns depends on the pivot series you feed it — a threshold that admits noise produces confident verdicts about noise. In this project's own testing, wave counting becomes reliable at 15-minute charts and above.

A passing verdict means a reading exists that satisfies the rules checked, not that it is the correct count. Elliott Wave analysis admits more than one valid interpretation of the same chart, and these functions score candidates rather than settle them.

This library is a technical analysis building block. It is not financial advice and generates no trading signals.
Release Notes
v0.1.0.2 — Structure Overlay support

Adds two exported functions, both used by EWCore's new Structure Overlay:

f_structDetect — a percent-of-price swing detector. The caller owns the point
arrays and the detector state, so a script can maintain two series at once (a
structure series and a finer validation series) from a single call per bar.

f_structOverlay — evaluates a caller-supplied swing series with the library's
existing pattern evaluators (impulse, diagonal, zigzag/flat, triangle, WXY,
WXYXZ), picks the best reading that ends at the newest point, and draws it with
notation labels. Returns a small diagnostic tuple so the caller can report why
nothing was drawn.

No changes to existing exports or to the WaveCount / EngineConfig types —
scripts already importing this library are unaffected.
Release Notes
v0.1.0.3 — Structure Overlay support + shared helpers

Adds two exported functions for EWCore's new Structure Overlay:

f_structDetect — a percent-of-price swing detector. The caller owns the point
arrays and the detector state, so a script can maintain two series at once (a
structure series and a finer validation series) from a single call per bar.

f_structOverlay — evaluates a caller-supplied swing series with the library's
existing pattern evaluators (impulse, diagonal, zigzag/flat, triangle, WXY,
WXYXZ), picks the best reading that ends at the newest point, and draws it with
notation labels. Returns a small diagnostic tuple so the caller can report why
nothing was drawn.

Also promotes five helpers from the indicator into the library, unchanged in
behaviour, so importing scripts can use them directly:

compressPivotLevel — percent-threshold compression of a pivot series into a
coarser one, returning prices, bars, types and source indices.
offsetAmt — resolves a label distance into price units for a chosen unit mode
(ATR multiple, ticks, percent of price, percent of pattern range).
f_parentGateCheck — tests a wave count against a higher-timeframe direction and
invalidation level, with a time tolerance.
f_formatDuration — formats a millisecond span as a compact d/h/m string.
f_futureTime — projects a bar time forward by N bars of the chart timeframe.

No changes to existing exports or to the WaveCount / EngineConfig types —
scripts already importing this library are unaffected.
Release Notes
v0.1.0.4 — Structure Overlay label styling

f_structOverlay gains three parameters at the end of its signature: a separate
text color for its labels, an on/off switch for its result pill, and an
independent size for that pill.

Previously every label the overlay drew — both the waypoint labels along the
structure and the result pill at its end point — shared the same color as the
overlay's connecting line, and the pill always matched the waypoint label size.
Callers can now set the label text color independently of the line color, turn
the result pill off entirely, and give it its own size.

The result pill's text is also now two lines (pattern name, then "fit <score>")
instead of one long line, so it takes up less horizontal space on the chart.

No other export or type changed — WaveCount, EngineConfig and every other
exported function are untouched.

Scripts already importing a fixed revision of this library (e.g. revision /3)
are unaffected and keep compiling exactly as before. Only a script that updates
its own import to the new revision needs to pass the three new arguments to
f_structOverlay.
Release Notes
v0.1.0.6 — Fibonacci target-zone support; unused diagnostic exports removed

Adds two exported functions: f_fibTargetsDraw and f_waveProjection. Together
they draw the Fibonacci target boxes, invalidation marker, confluence zone and
the dashed Wave-4/5 projection, and expose a small state array the caller can
read to drive its own alert condition.

Removes four exports that were leftover diagnostic views and drew placeholder
text: impulseFunnelText, drawImpulseFunnel, comboFunnelText, drawComboFunnel.
If you import this library and call any of them, pin your import to revision 4
or earlier. Every other export is unchanged.
Release Notes
v6

Updated:
f_structOverlay(tgtLines, tgtLabels, sP, sB, sT, vP, vB, degree, maxPoints, minScore, endTol, enImp, enDiag, enTri, enZZ, enC3, enC5, cfg, rsiSeries, notationTF, lineCol, lineW, lineStyleName, lblSizeName, offTop, offBottom, lblCol, showPill, pillSizeName, pillOff)
  Parameters:
    tgtLines (array<line>)
    tgtLabels (array<label>)
    sP (array<float>)
    sB (array<int>)
    sT (array<int>)
    vP (array<float>)
    vB (array<int>)
    degree (int)
    maxPoints (int)
    minScore (float)
    endTol (int)
    enImp (bool)
    enDiag (bool)
    enTri (bool)
    enZZ (bool)
    enC3 (bool)
    enC5 (bool)
    cfg (EngineConfig)
    rsiSeries (float)
    notationTF (string)
    lineCol (color)
    lineW (int)
    lineStyleName (string)
    lblSizeName (string)
    offTop (float)
    offBottom (float)
    lblCol (color)
    showPill (bool)
    pillSizeName (string)
    pillOff (float)

f_fibTargetsDraw(fibZoneLabels, zoneOut, w1s, w1e, w2e, w3e, w4e, w5e, topPatternType, topStartIdx, topInvalidationLevel, hardRulesValid, w4eTime, qPrice, qTime, p0Time, lastPtTime, lastPtPrice, w5eTime, showFibBoxes, showInvalidationLine, showInvalidationLabel, fibBoxExtendBars, fibBoxColorNear, fibBoxColorFar, confluenceTolPct, confluenceZoneBorderColor, confluenceZoneBorderWidth, confluenceZoneBorderStyle, confluenceZoneBgColor, confluenceZoneTextColor, confluenceZoneTextSize, invalidationColor, invalidationLineStyle, invalidationLineWidth, invalidationRightOffset, invalidationDotColor, measRefLineColor, measRefLineStyle, measRefLineWidth, measProjLineColor, measProjLineStyle, measProjLineWidth, fibTextSize, invalidationLabelSize, invalidationDotSize, invLabels)
  Parameters:
    fibZoneLabels (array<label>)
    zoneOut (array<float>)
    w1s (float)
    w1e (float)
    w2e (float)
    w3e (float)
    w4e (float)
    w5e (float)
    topPatternType (string)
    topStartIdx (int)
    topInvalidationLevel (float)
    hardRulesValid (bool)
    w4eTime (int)
    qPrice (float)
    qTime (int)
    p0Time (int)
    lastPtTime (int)
    lastPtPrice (float)
    w5eTime (int)
    showFibBoxes (bool)
    showInvalidationLine (bool)
    showInvalidationLabel (bool)
    fibBoxExtendBars (int)
    fibBoxColorNear (color)
    fibBoxColorFar (color)
    confluenceTolPct (float)
    confluenceZoneBorderColor (color)
    confluenceZoneBorderWidth (int)
    confluenceZoneBorderStyle (string)
    confluenceZoneBgColor (color)
    confluenceZoneTextColor (color)
    confluenceZoneTextSize (string)
    invalidationColor (color)
    invalidationLineStyle (string)
    invalidationLineWidth (int)
    invalidationRightOffset (int)
    invalidationDotColor (color)
    measRefLineColor (color)
    measRefLineStyle (string)
    measRefLineWidth (int)
    measProjLineColor (color)
    measProjLineStyle (string)
    measProjLineWidth (int)
    fibTextSize (string)
    invalidationLabelSize (string)
    invalidationDotSize (string)
    invLabels (array<label>)
Release Notes
v0.1.0.8 — Automation

  • The confluence-zone label is now registered with the label set the EWCore indicator's collision guard manages. Previously it was positioned independently and could overlap the Ext-0.618 target label — which was likely whenever a confluence zone existed, since the zone itself means the two targets are close.
  • The invalidation marker deliberately stays outside the guard: it belongs on its line.
  • The structure-overlay result pill takes a distance parameter, so the indicator can place it off its anchor point (including zoom-based placement); passing 0 reproduces the previous behaviour.
  • The invalidation label handle is exposed to the indicator, which uses it to slide the label horizontally along its line when other labels crowd the same price.
  • 56 exported functions; two signatures extended (f_structOverlay, f_fibTargetsDraw). EWCore v0.3.3.8 imports this revision.
Release Notes
v0.1.0.9 — housekeeping and consolidation

Removed. Twelve definitions that no longer had any caller, left behind when the matching features were retired in EWCore. Eight of them were exported: f_frameCount, f_structOverlay, f_structDetect, f_rankWhy, f_formatDuration, f_candDegPasses, f_floorLegPasses, f_comboBonus. If you import this library and call any of those, stay on the previous revision — every other export is unchanged.

Added. Four functions moved here from EWCore, where Pine was rebuilding them at every call site: f_dpRelax, f_tagReg, f_szDn, f_recPointTime. They are exported so EWCore can call them, and they behave as they did inside the indicator.

Unchanged. The signatures and behaviour of the 48 exports that remain.

No new capability — this release makes room. It does not change what EWCore counts or draws.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.