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
25 lines of Pine Script v4 from Buy From All Time High.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
Buy From All Time High.pine
//@version=4
strategy("All-time-high", "ATH", overlay=true, initial_capital=10000, default_qty_value=100, default_qty_type=strategy.percent_of_equity, pyramiding=1, commission_type=strategy.commission.cash_per_contract, commission_value=0.000)
// input
buyPerc=input(0.8,title="Buy from what % from all time high?")
var float highestHigh = 0
if high > highestHigh
highestHigh := high
plot(highestHigh)
buyzone=highestHigh*0.9
buyzone2=highestHigh*0.8
buyzone3=highestHigh*0.7
sellzone=highestHigh*0.99
plot(buyzone, color=color.red)
plot(buyzone2, color=color.white)
plot(buyzone3, color=color.green)
begin = timestamp(2011,1,1,0,0)
end = timestamp(2022,4,19,0,0)
if time >=begin and time <=end
longCondition = close<highestHigh*buyPerc
if (longCondition)
strategy.entry("Buy", strategy.long)
closeCondition = close>sellzone
if (closeCondition)
strategy.close("Buy", strategy.long)
Expand (40 lines)
Overview
All-time-high enters a long when the close falls below a user-set fraction of the high, defaulting to 80 percent, using full equity. It closes the long when the close rises above 99 percent of the high. Orders are allowed only from January 2011 through April 2022. There is no stop loss.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Buy from what % from all time high?
float
0.8
buyPerc
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 strategy divides a fixed price range between an upper and a lower limit into equally spaced grid levels and plots them on the price chart. It marks a buy when price crosses down through a grid and a sell when price crosses up through a grid, using either
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 strategy builds a spot grid between user-set high and low prices and draws it on the price chart. It splits that range into ten levels and places up to five long limit orders at the lower levels, sizing each from current equity. Orders already below price
Calculates the distance between the current price and the opposite end of the latest fair value gap, entering trades on the expectation that price will partially fill the gap. It incorporates risk management with customizable stop loss, take profit based on ri
This strategy identifies Wyckoff consolidation ranges directly on the price chart to trade potential spring and upthrust events. It calculates highest highs and lowest lows over a customizable lookback period, filtering setups by average volume spikes and ATR
This strategy enters one long trade when the bar low comes within a set point tolerance of the prior day's low and the close finishes above that level. Entries are allowed only inside a UTC session and are blocked after a Friday cutoff hour. It stays flat unti