// SPDX-License-Identifier: MIT
//@version=6
// ──────────────────────────────────────────────────────────────────────────
// Library: LibraryName
// Description: Brief description of what the library exports.
// Usage:
// import username/LibraryName/1 as lib
// lib.someFunction(close, 14)
// ──────────────────────────────────────────────────────────────────────────
library("LibraryName", overlay = true)
// ──────────────────────────────────────────────────────────────────────────
// TYPES
// ──────────────────────────────────────────────────────────────────────────
//@type Pivot point with bar index, price, and direction.
//@field bar Bar index where the pivot occurred.
//@field price Price level of the pivot.
//@field isHigh True for a pivot high, false for a pivot low.
export type Pivot
int bar
float price
bool isHigh
// ──────────────────────────────────────────────────────────────────────────
// EXPORTED FUNCTIONS
// ──────────────────────────────────────────────────────────────────────────
//@function Returns the value of `expr` from the most-recently-closed bar of `tf`.
// Non-repainting, consistent between history and realtime.
//@param sym Symbol to request (e.g. syminfo.tickerid).
//@param tf Higher timeframe string (e.g. "D", "60", "240").
//@param expr Series expression evaluated in the (sym, tf) context.
//@returns The value of `expr` from the previously-closed HTF bar.
export f_secure(simple string sym, simple string tf, series float expr) =>
request.security(sym, tf, expr[1], lookahead = barmerge.lookahead_on)
//@function Detects swing pivots without lookahead-induced repainting.
// Returns na until `right` bars after the pivot has formed.
//@param src Source series.
//@param left Bars to the left required to be lower (for highs) / higher (for lows).
//@param right Bars to the right required to confirm.
//@returns Pivot object, or na if no pivot at this bar.
export method confirmedPivot(series float src, simple int left, simple int right, simple bool findHigh) =>
pivotPrice = findHigh ? ta.pivothigh(src, left, right) : ta.pivotlow(src, left, right)
Pivot result = na
if not na(pivotPrice)
result := Pivot.new(bar = bar_index - right, price = pivotPrice, isHigh = findHigh)
result
//@function Rounds a price to the symbol's mintick.
//@param price Price to round.
//@returns Price rounded to the symbol's mintick.
export roundToTick(series float price) =>
math.round_to_mintick(price)
// ──────────────────────────────────────────────────────────────────────────
// DEMO PLOT (libraries require at least one output for compilation)
// ──────────────────────────────────────────────────────────────────────────
plot(close, "Close", display = display.none)
Overview
Library Template defines a Pivot type holding bar index, price and direction, a higher timeframe request helper that reads the previous closed bar, a method that returns a confirmed swing pivot only after the right-hand bars have formed, and a helper that rounds prices to the symbol tick. It is a starting point for other scripts to import, not a standalone indicator.
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This Pine Script v5 library provides functions to calculate and plot linear regression channels using sample point arrays. It evaluates paired X and Y arrays to calculate the regression slope, intercept, fitted values, maximum deviation, minimum deviation, and
This Pine Script v6 library calculates trade position sizes and provides risk management functions for external scripts. It computes position sizes from account equity, percentage risk, and stop-loss distance, and offers dynamic sizing adjustments based on vol
Chart Patterns is a Pine Script v6 library designed to scan for and render technical chart patterns directly on the price chart. It defines custom user-defined types to configure scanning parameters, such as Zigzag pivot offsets, error ratios, flat ratios, and
AuthLib is a Pine Script utility library providing access control and state management structures for technical indicators. It checks callers against a hardcoded array of authorized TradingView usernames before executing operations. The library exports user-de
WebhookMessageLibrary is a helper library designed to construct structured JSON payload messages for automated trading integrations like TradersPost. It defines custom exported types and constants for trade actions, market sentiments, quantities, limit prices,
PineDraw is a Pine Script v6 library that provides object primitives for drawing and updating price levels on the chart. It enables indicators and strategies to maintain lines, boxes, and labels in place by updating existing objects instead of deleting and rec