Strategy · Pine Script v5 · On the chart

Bitfinex Shorts Strat

by hasnocool

This strategy calculates a 7-period Relative Strength Index (RSI) on external Bitfinex Bitcoin short position data to execute trades on the price chart.

View on GitHub

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

39 lines of Pine Script v5 from Bitfinex Shorts Strat.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Bitfinex Shorts Strat.pine
//@version=5
strategy("Bitfinex Shorts Strat", 
     overlay=true,
     default_qty_type=strategy.percent_of_equity,
     default_qty_value=10, precision=2, initial_capital=1000,
     pyramiding=2,
     commission_value=0.05)
//Backtest date range
StartDate = input.time(timestamp("01 Jan 2021"), title="Start Date")
EndDate = input.time(timestamp("01 Jan 2024"), title="Start Date")
inDateRange = (time >= StartDate) and (time < EndDate)
symbolInput = input.symbol(title="Bitfinex Short Symbol", defval="BITFINEX:BTCUSDSHORTS")
Shorts = request.security(symbolInput, "", open)
// RSI Input Settings
length = input(title="Length", defval=7, group="RSI Settings" )
overSold = input(title="High Shorts Threshold", defval=75, group="RSI Settings" )
overBought = input(title="Low Shorts Threshold", defval=30, group="RSI Settings" )
// Calculating RSI
vrsi = ta.rsi(Shorts, length)
RSIunder = ta.crossover(vrsi, overSold)
RSIover = ta.crossunder(vrsi, overBought)
// Stop Loss Input Settings
longLossPerc = input.float(title="Long Stop Loss (%)", defval=25, group="Stop Loss Settings") * 0.01
shortLossPerc = input.float(title="Short Stop Loss (%)", defval=25, group="Stop Loss Settings") * 0.01
// Calculating Stop Loss
longStopPrice  = strategy.position_avg_price * (1 - longLossPerc)
shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)
// Strategy Entry
if (not na(vrsi))
    if (inDateRange and RSIover)
        strategy.entry("LONG", strategy.long, comment="LONG")
    if (inDateRange and RSIunder)
        strategy.entry("SHORT", strategy.short, comment="SHORT")
// Submit exit orders based on calculated stop loss price
if (strategy.position_size > 0)
    strategy.exit(id="LONG STOP", stop=longStopPrice)
if (strategy.position_size < 0)
    strategy.exit(id="SHORT STOP", stop=shortStopPrice)
Expand (46 lines)

Overview

Bitfinex Shorts Strat enters a long position when the short-position RSI drops below a low threshold, and enters a short position when it crosses above a high threshold. Trades are protected with percentage-based stop losses, and pyramiding up to two entries is allowed. Main settings adjust the external symbol, RSI period, threshold levels, and stop loss percentages.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Oscillators & momentum

Markets

Crypto

Timeframes

Any timeframe

Risk Notes

  • The strategy can add several entries in the same direction

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
Start Datetimetimestamp("01 Jan 2021")StartDate
Start Datetimetimestamp("01 Jan 2024")EndDate
Bitfinex Short SymbolsymbolBITFINEX:BTCUSDSHORTSsymbolInput
Lengthint7length
High Shorts Thresholdint75overSold
Low Shorts Thresholdint30overBought
Long Stop Loss (%)float25longLossPerc
Short Stop Loss (%)float25shortLossPerc
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

330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy

MACD Strategy

by TradersPost
218 stars

This overlay strategy is built around MACD inputs for a fast average, a slow average, and a signal line. Comments say the script keeps MACD values available and can draw a histogram and zero line in a separate pane, with an optional overlay on price. Settings

Strategy v6 Oscillators & momentumMoving averages
Updated 3 months ago · None stated GitHub repository of MACD Strategy
105 stars

This overlay strategy looks for gold scalps from break of structure and change of character. It enters long when a bullish break, a bullish character change, and an optional volume filter align, and short on the opposite set. Optional RSI levels can block trad

Strategy v6 SMC / ICT / price actionOscillators & momentum Repaints

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