1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
195 lines of Pine Script v5 from VBottom-Top.txt, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.
VBottom-Top.txt
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Author : @Fontiramisu
// @version=5
strategy("V Bottom/Top Pattern [Misu]", shorttitle="V pattern [Misu]", overlay=true, initial_capital=50000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
// import Fontiramisu/fontLib/80 as fontilab
import Fontiramisu/fontilab/8 as fontilab
// -------- Find dev pivots ---------- [
// -- Var user input --
var devTooltip = "Deviation is a multiplier that affects how much the price should deviate from the previous pivot in order for the bar to become a new pivot."
var depthTooltip = "The minimum number of bars that will be taken into account when analyzing pivots."
thresholdMultiplier = input.float(title="Deviation", defval=3.1, step=0.1, minval=0, tooltip=devTooltip, group="Pivot")
depth = input.int(title="Depth", defval=8, minval=1, tooltip=depthTooltip, group="Pivot")
// Prepare pivot variables
var line lineLast = na
var int iLast = 0 // Index last
var int iPrev = 0 // Index previous
var float pLast = 0 // Price last
var float pLastHigh = 0 // Price last
var float pLastLow = 0 // Price last
var isHighLast = false // If false then the last pivot was a pivot low
isPivotUpdate = false
// Get pivot information from dev pivot finding function
[dupLineLast, dupIsHighLast, dupIPrev, dupILast, dupPLast, dupPLastHigh, dupPLastLow] =
fontilab.getDeviationPivots(thresholdMultiplier, depth, lineLast, isHighLast, iLast, pLast, true, close, high, low)
if not na(dupIsHighLast)
lineLast := dupLineLast
isHighLast := dupIsHighLast
iPrev := dupIPrev
iLast := dupILast
pLast := dupPLast
pLastHigh := dupPLastHigh
pLastLow := dupPLastLow
isPivotUpdate := true
// Plot.
// Get last Pivots.
var highP = 0.0
var lowP = 0.0
var midP = 0.0
highP := isHighLast ? pLast : highP
lowP := not isHighLast ? pLast : lowP
midP := (highP + lowP)/2
// ] -------- Input Vars --------------- [.
breakoutTypeConf = input.string("Mid Pivot", title="Confirmation Type", options=["At First Break", "Mid Pivot", "Opposit Pivot", "No Confirmation"], group="Signal Type Confirmation")
lenghtSizeAvgBody = input.int(9, title="Lenght Avg Body", group="Breakouts Settings")
firstBreakoutFactor = input.float(0.2, step=0.1, title="First Breakout Factor", tooltip="Factor used to validate the first breakout of the V pattern", group="Breakouts Settings")
confBreakoutFactor = input.float(1.2, step=0.1, title="Confirmation Breakout Factor", tooltip="Factor used to validate the confirmation breakout of the V pattern", group="Breakouts Settings")
maxNbBarsValidV = input.int(11, title="Max Bars Confirmation", group="Timing Confirmation")
// ] -------- Logical Vars ------------- [
var _isVbottomPot = false
var _isVtopPot = false
_isVbottom = false
_isVtop = false
lastLow = 0.0
indexLow = 0
lastHigh = 0.0
indexHigh = 0
// Confirm V pattern vars.
var lHighVtopPot = 0.0
var lLowVbotPot = 0.0
var nbBarLVtopPot = 0
var nbBarLVbotPot = 0
var breakLevelVbotPot = 0.0
var breakLevelVtopPot = 0.0
// ] -------- Util Functions ----------- [
// Cond Vars.
_bodyHi = math.max(close, open)
_bodyLo = math.min(close, open)
_body = _bodyHi - _bodyLo
_bodyAvg = ta.ema(_body, lenghtSizeAvgBody)
_longBody = _body > _bodyAvg
_upperWick = high - _bodyHi
_greenBody = open < close
_redBody = open > close
// COND: Potential V pattern.
_breakAboveLowP = ta.crossover(close, lowP) and _body > _bodyAvg * firstBreakoutFactor
_breakUnderHighP = ta.crossunder(close, highP) and _body > _bodyAvg * firstBreakoutFactor
// Crossing Vars.
breakLevelVbotPot := ta.crossunder(close, lowP) ? lowP : breakLevelVbotPot
breakLevelVtopPot := ta.crossover(close, highP) ? highP : breakLevelVtopPot
// @function to get last high/low (handle multiple rsiOver in a row)
getIndexHighLowFromNbCandles(bool isLong, int nbCandles) =>
highLow = isLong ? low : high
indexHighLows = 0
// indexHighLow = 0
for counter = 1 to nbCandles + 10
if isLong
if low[counter] < highLow
highLow := low[counter]
indexHighLows := counter
else
if high[counter] > highLow
highLow := high[counter]
indexHighLows := counter
indexHighLows
isWickCrossPattern (src, isCrossUp) =>
isCross = false
if isCrossUp
isCross := _bodyHi < src and src < high
else
isCross := low < src and src < _bodyLo
isCross
getBreakoutTypeConf(type, isVtop) =>
switch type
"No Confirmation" => isVtop ? highP : lowP
"Opposit Pivot" => isVtop ? lowP : highP
"Mid Pivot" => midP
"At First Break" => isVtop ? breakLevelVtopPot : breakLevelVbotPot
isPivotChanged (oldMidP) =>
midP != oldMidP
// ] -------- Logical Script ----------- [
// -----
// Calculate.
lastLowDup = fontilab.getHighLowFromNbCandles(true, 10)
indexLowDup = getIndexHighLowFromNbCandles(true, 10)
lastHighDup = fontilab.getHighLowFromNbCandles(false, 10)
indexHighDup = getIndexHighLowFromNbCandles(false, 10)
if _breakAboveLowP
lastLow := lastLowDup
indexLow := indexLowDup
_isVbottomPot := true
lLowVbotPot := lastLow
else if _breakUnderHighP
lastHigh := lastHighDup
indexHigh := indexHighDup
_isVtopPot := true
lHighVtopPot := lastHigh
// Confirm potential V bot pattern.
isBreakBarAvg = breakoutTypeConf != "No Confirmation" ? _body > _bodyAvg * confBreakoutFactor : true
vBotConfSrc = getBreakoutTypeConf(breakoutTypeConf, false)
_isVbottom := _isVbottomPot and ta.crossover(close, vBotConfSrc) and isBreakBarAvg
if _isVbottomPot
// Cond V pot invalidated or finished.
if not _isVbottom and low >= lLowVbotPot and nbBarLVbotPot <= maxNbBarsValidV
nbBarLVbotPot := nbBarLVbotPot + 1
else
_isVbottomPot := false
nbBarLVbotPot := 0
// Confirm potential V top pattern.
vTopConfSrc = getBreakoutTypeConf(breakoutTypeConf, true)
_isVtop := _isVtopPot and ta.crossunder(close, vTopConfSrc) and isBreakBarAvg
if _isVtopPot
// Cond V pot invalidated or finished.
if not _isVtop and high <= lHighVtopPot and nbBarLVtopPot <= maxNbBarsValidV
nbBarLVtopPot := nbBarLVtopPot + 1
else // reinit for next V patter.
_isVtopPot := false
nbBarLVtopPot := 0
// -----
// BUY / SELL COND.
buyCond = _isVbottom
sellCond = _isVtop
// ] -------- Strategy Part ------------ [
if buyCond
strategy.entry("L", strategy.long, alert_message="Buy Signal")
if sellCond
strategy.entry("S", strategy.short, alert_message="Sell Signal")
// ] -------- Plot Part & Alerts ------- [
midPPlot = plot(midP, title='Mid Pivot', linewidth=1, color=color.yellow, display=display.none)
highPlot = plot(highP, title='High Pivot', linewidth=1, color=color.red, display=display.none)
lowPlot = plot(lowP, title='Low Pivot', linewidth=1, color=color.green, display=display.none)
if buyCond
label.new(x = bar_index, y = low - (ta.atr(30) * 0.2), xloc = xloc.bar_index, text = "V", style = label.style_label_up, color = color.green, size = size.small, textcolor = color.white, textalign = text.align_center)
else if sellCond
label.new(x = bar_index, y = high + (ta.atr(30) * 0.2), xloc = xloc.bar_index, text = "V", style = label.style_label_down, color = color.red, size = size.small, textcolor = color.white, textalign = text.align_center)
if _breakAboveLowP
label.new(x = bar_index - indexLowDup, y = low[indexLowDup] - (ta.atr(30) * 0.2), xloc = xloc.bar_index, text = "Vp", style = label.style_label_up, color = color.new(color.green, 70), size = size.small, textcolor = color.white, textalign = text.align_center)
else if _breakUnderHighP
label.new(x = bar_index - indexHighDup, y = high[indexHighDup] + (ta.atr(30) * 0.2), xloc = xloc.bar_index, text = "Vp", style = label.style_label_down, color = color.new(color.red, 70), size = size.small, textcolor = color.white, textalign = text.align_center)
Overview
A deviation multiplier and depth set how large a move counts as a pivot. After a pivot, the script checks for a first breakout and then a confirmation breakout, measured against the average candle body, within a maximum number of bars. Confirmation can use the first break, the middle pivot, the opposite pivot or none. Orders use 100 percent of equity, and no stop loss is set.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Deviation
float
3.1
thresholdMultiplier
Depth
int
8
depth
Confirmation Type
string
Mid Pivot
breakoutTypeConf
Lenght Avg Body
int
9
lenghtSizeAvgBody
First Breakout Factor
float
0.2
firstBreakoutFactor
Confirmation Breakout Factor
float
1.2
confBreakoutFactor
Max Bars Confirmation
int
11
maxNbBarsValidV
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 trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr
This strategy plots running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos
STRG-HOLP is a trading strategy that identifies High of Low Period (HOLP) and Low of High Period (LOHP) breakout setups. It tracks the lowest low or highest high over a user-defined lookback window. A long trade opens when the close breaks above the high of th
The Chained Linear Regression Reversal Strategy plots linear regression channels with upper and lower standard deviation bands directly on the price chart across a user-defined time window. When price breaks out of the static channel for a confirmed number of
This script monitors opening gap conditions and breakout behavior relative to the first candle's range across up to twenty configurable stock tickers. It detects whether following bars remain inside the opening range before breaking out, displaying the status
This trend breakout strategy plots Donchian Channels consisting of upper, lower, and middle bands directly on the main price chart. Long positions enter when price touches the upper channel and pulls back to or below the middle band, placing a stop loss at the