Strategy · Pine Script v4 · On the chart

PivotConfirm-with-SellToClose

by PipC

This strategy marks an n-bar pivot low and treats it as confirmed when the close crosses above that bar's high.

View on GitHub

GitHub stars8on the repository
Pine versionv4older, still runs
Lines of code64
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update4 years ago20 Aug 2022

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 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

64 lines of Pine Script v4 from TradingView/PivotConfirm-with-SellToClose.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

PivotConfirm-with-SellToClose.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// c philchan2008

//@version=4
strategy(title="PivotConfirm-with-SellToClose", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0, initial_capital=10000)

data = input(close, title = "Data source")
n = input(5, title = "For pivot/standard deviation")
addAtPercentStDev = input(75, title = "% of standard deviation below previous low")
initialLots = input(4, title = "initialLots")
lotsToAdd = input(2, title = "Lots to add")
stDevMult = input(2.0, title = "tail stop multiplier")

openingLots = max(4, initialLots)
addedlots = max(2, lotsToAdd)

h = high
l = low
c = close
//nan=na replace nan to na
tick = syminfo.mintick //ticks()
x = 0
x := bar_index  //BarNumber();
stDev = x > 1 ? stdev(c,n): na //CompoundValue(1, StDev(c, n), nan);
ll = l == lowest(l, n)
LPx =  ll ? x : na
LP_low = 0.0
LP_low := na(LPx) ? LP_low[1] : l
LP_High = 0.0
LP_High := na(LPx) ? LP_High[1] : h
confirmation_count = 0.0
confirmation_count := ll ? 0 : ( crossover(c,LP_High) ? confirmation_count[1] + 1 : confirmation_count[1])
confirmationX =  crossover( confirmation_count, 0) ? x : na
confirmed = crossover(confirmation_count, 0)

ro=0.0
stc=0.0
trail=0.0
retrace=0.0
if confirmed
    ro := round((c + (c - LP_low) / (openingLots - 2)) / tick) * tick
    stc := LP_low
    trail := LP_low
    retrace := LP_low
else
    ro := x > 1 ? ro[1] : na //CompoundValue(1, ro[1], nan)
    stc := stc[1]
    trail := round(max(trail[1], l[1] - stDev[1] * stDevMult) / tick) * tick
    retrace := round(max(retrace[1], l[1] - stDev[1] * addAtPercentStDev / 100) / tick) * tick

ro_reached = 0.0
ro_reached := confirmed ? 0 : ( h > ro ? 1 : ro_reached[1] )
added = 0.0
added := confirmed ? 0 :  ( crossunder(l,retrace) ? 1 : added[1])
trail_hit = 0.0
trail_hit := confirmed ? 0 : ( c < trail ? 1 : trail_hit[1])
stop_hit = 0.0
stop_hit := confirmed ? 0 : ( l < stc ? 1 : stop_hit[1])

//plot(stop_hit, title="Stop Hit", color=color.red, style=line.style_solid, linewidth=2)
plot(trail_hit, title='Trail Stop', color=color.red, linewidth=2, style=plot.style_line, transp=10)

//if (bar_index == 1000)
//    label l1= label.new(bar_index-50, high[0], text="There are "+tostring(bar_index)+" bars on chart", style=label.style_none, textcolor=color.orange)

Overview

On confirmation it stores a sell-to-close level at the pivot low, a standard-deviation trailing stop, a retrace level for adding size, and a rounded objective based on the pivot range and the opening lot count. Inputs change the lookback, add percentage, lot counts, and trail multiplier. It is declared on the price chart with pyramiding off. The shown code plots the trail-hit flag and does not place orders or exits.

Details

Published by

PipC on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Support & resistance, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Data sourcesourceclosedata
For pivot/standard deviationint5n
% of standard deviation below previous lowint75addAtPercentStDev
initialLotsint4initialLots
Lots to addint2lotsToAdd
tail stop multiplierfloat2.0stDevMult
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.

Similar Pine Scripts

257 stars

This overlay strategy is built for ES futures on the one-minute chart. It plots a volume-weighted moving average of price opens and standard-deviation bands at Fibonacci ratios, plus a second longer volume-weighted average from a higher-timeframe open. Call an

Strategy v5 Volatility & bandsMoving averages
Updated 6 weeks ago · None stated GitHub repository of ES Futures 1M No Repaint

Daily Bias + FVG Strategy

by TradersPost
218 stars

This overlay strategy plots previous-day high and low, the daily open, and fair value gap zones on the price chart. It takes entries on a selectable timeframe when the FVG requirement and an optional session window allow them, then uses an ATR or fixed pip sto

Strategy v6 SMC / ICT / price actionSupport & resistance Repaints
Updated 3 months ago · None stated GitHub repository of Daily Bias + FVG Strategy
106 stars

This overlay strategy plots a two-timeframe Ichimoku setup on the price chart, with Tenkan, Kijun, Chikou, and Kumo from a base higher timeframe and an optional highest-timeframe cloud. It allows two entries in the same direction and uses ATR-based trailing st

Strategy v4 TrendVolatility & bands
Updated 2 years ago · GPL-3.0 GitHub repository of 2Tier Ichimoku Pyramiding [Takazudo]

KC15

by benso87
24 stars

KC15 is a price-chart strategy that configures two moving averages, a Bollinger Band Width Percentile filter, and PMARP entry and exit thresholds for long and short trades. Users can switch each average between SMA and EMA, set lengths and colors, and toggle l

Strategy v5 Moving averagesVolatility & bands
Updated 4 years ago · MPL-2.0 GitHub repository of KC15

This strategy implements a multi-stage trend following system inspired by John W. Seykota. It generates long and short entries when price breaks above or below Donchian channels of specified length. Each entry adds a unit sized to risk a fixed percentage of cu

Strategy v6 TrendVolatility & bands
Updated 11 months ago · None stated GitHub repository of Seykota Alt 29: Multi-Stage Scaling
11 stars

Calculates upper and lower Donchian Channel bands over a customizable lookback length and plots them on the main price chart. At a specified exchange hour, the strategy places a long buy stop order at the upper Donchian Channel level. Unfilled pending orders a

Strategy v6 BreakoutSupport & resistance
Updated 5 months ago · Apache-2.0 GitHub repository of Estrategia Donchian Breakout

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers