Strategy · Pine Script v5 · Own pane

John Day Stop Loss

by hasnocool

This long-only Pine v5 strategy plots RSI, Money Flow Index, Stochastic RSI, and a MACD calculation in a separate pane.

View on GitHub

GitHub stars106on the repository
Pine versionv5runs as is
Lines of code89
Settings24inputs
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

89 lines of Pine Script v5 from BTC 30m Script.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

BTC 30m Script.pine
//@version=5
strategy('John Day Stop Loss', overlay=false, pyramiding=1, default_qty_type=strategy.cash, default_qty_value=10000, initial_capital=10000, currency='USD', precision=2)
strategy.risk.allow_entry_in(strategy.direction.long) 
from_day = input.int(defval=1, title='From Day', minval=1)
from_month = input.int(defval=1, title='From Month', minval=1)
from_year = input.int(defval=2021, title='From Year', minval=2020)
to_day = input.int(defval=1, title='To Day', minval=1)
to_month = input.int(defval=1, title='To Month', minval=1)
to_year = input.int(defval=2025, title='To Year', minval=2020)
time_cond = time > timestamp(from_year, from_month, from_day, 00, 00) and time < timestamp(to_year, to_month, to_day, 00, 00)
//time_cond = true
//Stop Loss
longProfitPerc = input.float(title="Stop Loss Profit (%)", defval=2.1) / 100
longExitPrice  = strategy.position_avg_price * (1 - longProfitPerc)
//RSI - yellow
up = ta.rma(math.max(ta.change(close), 0), 14)
down = ta.rma(-math.min(ta.change(close), 0), 14)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
plot(rsi, "RSI", color=#00FFFF)
buy_rsi = true // rsi < 40
sell_rsi = true //rsi > 70
//MFI - cyan
mf = ta.mfi(hlc3, 14)
plot(mf, "MF", color=#FFFF00)
buy_mfi = mf < input.int(defval=23, title='Max MF', minval=1)
sell_mfi = mf > input.int(defval=80, title='Min MF', minval=1)
//Stoch RSI
OverBought_StochRSI = input(80)
OverSold_StochRSI = input(34)
smoothK = input.int(3, "K", minval=1)
smoothD = input.int(2, "D", minval=1)
lengthRSI = input.int(14, "RSI Length", minval=1)
lengthStoch = input.int(14, "Stochastic Length", minval=1)
srcRSI = input(close, title="RSI Source")
rsi1 = ta.rsi(srcRSI, lengthRSI)
kStochRSI = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(kStochRSI, smoothD)
co = ta.crossover(kStochRSI,d)
cu = ta.crossunder(kStochRSI,d)
buy_stochRSI = co and kStochRSI < OverSold_StochRSI
sell_stochRSI = cu and kStochRSI > OverBought_StochRSI
plot(kStochRSI, "K", color=#2962FF)
plot(d, "D", color=#FF6D00)
h0 = hline(OverBought_StochRSI, "Upper Band", color=#787B86)
h1 = hline(OverSold_StochRSI, "Lower Band", color=#787B86)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")
//MACD
// Getting inputs
fast_length = input(title="Fast Length", defval=12)
slow_length = input(title="Slow Length", defval=26)
src = input(title="Source", defval=close)
signal_length = input.int(title="Signal Smoothing",  minval = 1, maxval = 50, defval = 9)
sma_source = input.string(title="Oscillator MA Type",  defval="EMA", options=["SMA", "EMA"])
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"])
// Plot colors
//col_macd = input(#2962FF, "MACD Line  ", group="Color Settings", inline="MACD")
//col_signal = input(#FF6D00, "Signal Line  ", group="Color Settings", inline="Signal")
//col_grow_above = input(#26A69A, "Above   Grow", group="Histogram", inline="Above")
//col_fall_above = input(#B2DFDB, "Fall", group="Histogram", inline="Above")
//col_grow_below = input(#FFCDD2, "Below Grow", group="Histogram", inline="Below")
//col_fall_below = input(#FF5252, "Fall", group="Histogram", inline="Below")
// Calculating
fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal
buy_MACD = macd < signal and hist < 0 
sell_MACD = macd > signal and hist > 0 
//buy_MACD = true 
//sell_MACD = true
//plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below)))
//plot(macd, title="MACD", color=col_macd)
//plot(signal, title="Signal", color=col_signal)
sessionColor = color(na)
if time_cond
    if (not na(kStochRSI) and not na(d))
        cmt = str.tostring(close)
        if (buy_stochRSI and buy_MACD and buy_mfi and buy_rsi)
            strategy.entry("BUY", strategy.long, comment='BUY @ ' + cmt)
            if longProfitPerc != 0
                strategy.exit(id="x", stop=longExitPrice, comment='EXIT @ ' + str.tostring(longExitPrice))
            sessionColor := input.color(#0000FF, "buy") //red
        if (sell_stochRSI and sell_MACD and sell_mfi and sell_rsi)
            strategy.entry("SELL", strategy.short, comment='SELL @ ' + cmt)
            sessionColor := input.color(#FF0000, "sell") //green
        
bgcolor(sessionColor)
Expand (102 lines)

Overview

Visible buy logic requires Money Flow below a maximum and a Stochastic RSI K-line cross above D while below the oversold band; the matching sell conditions use the opposite Money Flow and Stochastic RSI tests. RSI buy and sell flags are hardcoded true. A date window limits when the logic can run, and a stop price is computed below average entry, but the excerpt does not show that stop or any exit order being placed.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v5

Draws

Separate pane below the chart

Category

Oscillators & momentum, Volume

Markets

Crypto

Timeframes

M15-H1

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
From Dayint1from_day
From Monthint1from_month
From Yearint2021from_year
To Dayint1to_day
To Monthint1to_month
To Yearint2025to_year
Stop Loss Profit (%)float2.1longProfitPerc
Max MFint23Max MF
Min MFint80Min MF
OverBought_StochRSIint80OverBought_StochRSI
OverSold_StochRSIint34OverSold_StochRSI
Kint3smoothK
Show all 24 settings
SettingTypeDefaultVariable
Dint2smoothD
RSI Lengthint14lengthRSI
Stochastic Lengthint14lengthStoch
RSI SourcesourceclosesrcRSI
Fast Lengthint12fast_length
Slow Lengthint26slow_length
Sourcesourceclosesrc
Signal Smoothingint9signal_length
Oscillator MA TypestringEMAsma_source
Signal Line MA TypestringEMAsma_signal
buycolor#0000FFsessionColor
sellcolor#FF0000sessionColor
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

Q-Trend + KVO Strategy

by TradersPost
218 stars

This strategy combines the ATR-banded Q-Trend indicator with the Klinger Volume Oscillator (KVO) to execute confluence trades. It enters long when a Q-Trend buy trigger aligns with a positive KVO value and a bullish candle confirmation, taking short trades und

Strategy v6 TrendVolume
Updated 3 months ago · None stated GitHub repository of Q-Trend + KVO Strategy

BTC Futures MACD

by iamrichardD
57 stars

This strategy plots a MACD oscillator in a separate pane and trades Bitcoin futures from zero-line and signal-line crosses. Optional early momentum signals, a volume filter, and a trend moving-average filter can confirm entries. It sizes positions as fixed con

Strategy v6 Oscillators & momentumMoving averages Repaints
Updated 1 year ago · Apache-2.0 GitHub repository of BTC Futures MACD

RSI-VWAP Indicator

by oguzhandilber
47 stars

This strategy calculates a Relative Strength Index (RSI) applied to the Volume Weighted Average Price (VWAP) rather than standard close values. It plots dedicated long and short RSI-VWAP lines with customizable overbought and oversold thresholds, alongside an

Strategy v4 Oscillators & momentumVolume
Updated 5 years ago · None stated GitHub repository of RSI-VWAP Indicator
13 stars

This strategy calculates the Volume Zone Oscillator (VZO) alongside volume spikes to detect directional momentum. It enters long positions when the VZO turns bullish accompanied by a volume spike, and enters short when the VZO turns bearish with elevated volum

Strategy v5 VolumeOscillators & momentum
Updated 1 year ago · None stated GitHub repository of Ruckard Neobutane VZO bA002

Chaikin Oscillator - Eterna MCP

by EternaHybridExchange
9 stars

This strategy calculates the Chaikin Oscillator by taking the difference between fast and slow exponential moving averages of the Accumulation/Distribution line. It generates long and short entries when the oscillator crosses the signal threshold with directio

Strategy v5 Oscillators & momentumVolume
Updated 7 months ago · MIT GitHub repository of Chaikin Oscillator - Eterna MCP

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