Strategy · Pine Script v4 · On the chart

Buy The Dip

by hasnocool· code credited to racer8

Calculates a historical dip level based on the lowest low over a specified lookback period.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code25
Settings4inputs
LicenceGPL-3.0
Last update2 years ago18 Sep 2024

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

25 lines of Pine Script v4 from Buying Dip Strategy With Take Profit And Stop Loss [racer8].pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Buying Dip Strategy With Take Profit And Stop Loss [racer8].pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © racer8
//@version=4
strategy("BuyTheDip", overlay=true)
atn = input(10, "ATR Length")
atr = sma(tr,atn)[1]
bought = strategy.position_size[0] > strategy.position_size[1]
tpm = input(2.0,"ATR Take Profit",minval=0)
TakePrice  = strategy.position_avg_price + tpm*atr              // determines Take Profit's price 
FixedTakePrice = valuewhen(bought,TakePrice,0)                  // stores original TakePrice  
plot(FixedTakePrice,"ATR Take Profit",color=color.blue,linewidth=1,style=plot.style_cross)
slm = input(2.0,"ATR Stop Loss",minval=0)
StopPrice  = strategy.position_avg_price - slm*atr              // determines stop loss's price 
FixedStopPrice = valuewhen(bought,StopPrice,0)                  // stores original StopPrice  
plot(FixedStopPrice,"ATR Stop Loss",color=color.yellow,linewidth=1,style=plot.style_cross)
n = input(7,"Dip Length")
Dip = lowest(low,n)
if close<Dip[1]
    strategy.entry("Buy",strategy.long)
if strategy.position_size > 0
    strategy.exit(id="Stop", stop=FixedStopPrice, limit=FixedTakePrice)    // commands stop loss order to exit!
    
plot(Dip,"Dip Line",color=color.aqua,linewidth=2)    
// ♡♡♡
Expand (29 lines)

Overview

Buy The Dip enters a long strategy position when the current bar close falls below the previous dip level. Positions are managed with take profit and stop loss exits placed at fixed distances based on Average True Range multipliers calculated at entry. It plots the dip reference line and dynamic exit target prices directly on the price chart.

Details

Published by

hasnocool on GitHub

Code credit

racer8, as written in the script's header

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Mean reversion, Volatility & bands, Support & resistance

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
ATR Lengthint10atn
ATR Take Profitfloat2.0tpm
ATR Stop Lossfloat2.0slm
Dip Lengthint7n
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

3 stars

This strategy combines two sets of Bollinger Bands with a Laguerre RSI oscillator plotted on the price chart. It generates buy and sell signals when price touches the upper or lower bands or zones. The strategy allows enabling or disabling entries and includes

Strategy v5 Mean reversionVolatility & bands
Updated 5 months ago · None stated GitHub repository of BB + LaRSI Strategy

DP2

by grinay
3 stars

DP2 is a price-chart strategy that looks for a short dump between the chosen from and to prices, optionally requiring a break of a multi-day low while ignoring moves larger than a dump cap. It can enter through classic, two-close, break-and-retest, ATR-stop, a

Strategy v6 Mean reversionVolatility & bands
Updated 7 months ago · MIT GitHub repository of DP2

3C QFL Mean Reversal

by wynnforthework
2 stars

This strategy implements a Quickfinger Luc mean-reversion trading model tailored for automated execution. It calculates base support levels and volume moving averages across timeframes to identify sharp price dips below established base levels. The script incl

Strategy v5 Mean reversionSupport & resistance Repaints
Updated 1 year ago · None stated GitHub repository of 3C QFL Mean Reversal

Bollinger Bands

by Studentcodee
1 stars

This strategy plots Bollinger Bands directly on the price chart. It computes the middle band as the simple moving average of the close price over the input length and the upper and lower bands by multiplying the standard deviation by the multiplier and adding

Strategy v6 Volatility & bandsMoving averages
Updated 1 year ago · None stated GitHub repository of Bollinger Bands

ES Professional Fade

by knectardev
1 stars

The ES Professional Fade strategy trades overnight price gaps during regular trading hours on intraday charts. It establishes an opening range and enters counter-trend positions when price fails near overnight extremes. Positions target the previous day's clos

Strategy v5 Mean reversionSessions & time
Updated 9 months ago · None stated GitHub repository of ES Professional Fade
1 stars

The strategy detects range expansion by comparing the previous bar's range to its ATR multiple. It places pending stop entries above highs of up bars or below lows of down bars. On trigger it enters positions with take profit and stop loss in ticks using OCA g

Strategy v6 Volatility & bandsSupport & resistance
Updated 5 days ago · Apache-2.0 GitHub repository of PF probe 97 - tp/sl gap reversal oca

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