Type/to search

Leveraged RSI Strategy in Pine Script

Common strategy
Created: 2023-12-29 10:46:35
Last modified: 3 years ago
1
Follow
1802
Followers

img

Overview

This strategy aims to solve the problem that Pine Script cannot set leverage during backtesting to achieve compound interest with leverage. The strategy dynamically calculates the position size based on the strategy equity, set leverage ratio and closing price.

Strategy Logic

  1. Set precision precision to control the precision of position size
  2. Set leverage ratio leverage, default is 1x
  3. Calculate position size: Lev = math.max(math.round(strategy.equity * leverage / close), 0), make it proportional to equity and leverage
  4. Entry signal: long when RSI breaks above 30 from below; short when RSI breaks below 70 from above
  5. Place order with calculated size Lev

Advantage Analysis

  1. Solve the problem that Pine Script cannot set leverage
  2. Position size changes proportionally with equity changes, achieving compound interest with leverage
  3. RSI filtered, avoiding unnecessary trades
  4. Precision precision is adjustable to meet different requirements

Risk Analysis

  1. Excessive leverage can easily cause liquidation
  2. Need to adjust leverage and position size properly to control risk

Optimization Direction

  1. Can test stability under different parameters
  2. Can incorporate stop loss to further control risk
  3. Can consider multi-factor model to improve strategy performance

Summary

This strategy implements leverage setting in Pine Script, solving the problem that backtesting cannot simulate leverage, calculates position size linked to equity to achieve compound interest with leverage. The strategy is simple and effective, can be further optimized, and worth learning.

Source
Pine
/*backtest
start: 2022-12-22 00:00:00
end: 2023-12-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © RingsCherrY

//@version=5
Strategy parameters
Strategy parameters
length
overSold
overBought
Precision
Leverage
Comment
All comments (0)
No data
No data
  • 1
Forums
PINE Language
Get the app
iPhone Download
© 2015 - ∞ INVENTOR PTE LTD (SG)