4

How to use leverage in Pine Script?

//@version=3
strategy("My Strategy", overlay=true, initial_capital=100)
//enter position
if (strategy.position_size == 0)
    strategy.entry("Short", false, 1)
//exit position
if (strategy.position_size != 0 and volume > volume[2] * 2.5)
    strategy.close("Short")

I need to use leverage at enter. How to do that?

Aram
  • 51
  • 1
  • 2
  • Tradingview's strategy doesn't have margin trading. Use bigger `initial_capital` instead. – Michel_T. Mar 18 '19 at 08:56
  • TradingView recently added in 2021 marginal trading. You could check it out https://www.tradingview.com/script/9Iwinz7I-How-to-use-Leverage-and-Margin-in-PineScript/ – Maksim Shamihulau Dec 10 '21 at 22:00

1 Answers1

0

Don't. The only method (and quite a good one) is to export strategy results (use ProfitView or AutoView to do it with one click), paste into Excel and apply your own calculations.

PeterO
  • 89
  • 1
  • 1
  • 5