파인 스크립트에서 리버레이드된 RSI 전략

저자:차오장, 날짜: 2023-12-29 10:46:35
태그:

img

전반적인 설명

이 전략은 피인 스크립트가 레버리지를 설정할 수 없다는 문제를 해결하는 것을 목표로 레버리지를 사용하여 복합 금리를 달성합니다. 전략 자본, 설정 레버리지 비율 및 폐쇄 가격에 따라 위치 크기를 동적으로 계산합니다.

전략 논리

  1. 위치 크기의 정확성을 제어하기 위해 정밀 정밀을 설정
  2. 레버리지 비율 레버리지 설정, 기본은 1x입니다
  3. 위치 크기를 계산합니다:Lev = math.max(math.round(strategy.equity * leverage / close), 0), 자금과 레버리지에 비례하도록
  4. 입력 신호: RSI가 아래에서 30을 넘을 때 길고, RSI가 위에서 70을 넘을 때 짧습니다.
  5. 계산된 크기와 함께 주문

이점 분석

  1. 파인 스크립트가 레버리지를 설정할 수 없다는 문제를 해결
  2. 지점 크기는 주식 변화와 비례하여 변화하며 지렛대와 함께 복합 금리를 달성합니다.
  3. RSI 필터링, 불필요한 거래를 피하는
  4. 정밀 정밀은 다른 요구 사항을 충족하도록 조정됩니다

위험 분석

  1. 과도한 레버리지는 쉽게 청산으로 이어질 수 있습니다.
  2. 리버리지와 포지션 크기를 적절히 조정해야 위험 통제가 가능합니다.

최적화 방향

  1. 다른 매개 변수에서 안정성을 테스트 할 수 있습니다.
  2. 추가적인 위험 통제를 위해 스톱 로스를 포함할 수 있습니다.
  3. 전략 성과를 개선하기 위해 다중 요소 모델을 고려할 수 있습니다.

요약

이 전략은 파인 스크립트에서 레버리지 설정을 구현하여 백테스팅이 레버리지를 시뮬레이션할 수 없다는 문제를 해결하고, 레버리지로 합성 금리를 달성하기 위해 주식과 연결된 지점 크기를 계산합니다. 전략은 간단하고 효과적이며 더 이상 최적화 될 수 있으며 배울 가치가 있습니다.


/*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("How to use Leverage in PineScript", overlay=true, pyramiding=1, initial_capital=1000000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, calc_on_order_fills=false, slippage=0, commission_type=strategy.commission.percent, commission_value=0.04)

//////////////////////////////////////////
////////////////Indicators////////////////
//////////////////////////////////////////

length = input( 14 )
overSold = input( 30 )
overBought = input( 70 )
price = close
vrsi = ta.rsi(price, length)
co = ta.crossover(vrsi, overSold)
cu = ta.crossunder(vrsi, overBought)

//////////////////////////////////////////
/////////////////Leverage/////////////////
//////////////////////////////////////////


//The number of decimal places for each position opening, i.e., the accuracy
precision = input.int(1,title='Precision')

//Leverage, the default is 1, here is not recommended to open a high leverage

leverage = input.int(1,title='Leverage',minval = 1, maxval = 100 ,step = 1)

//Calculate the number of open contracts, here using equity for calculation, considering that everyone compound interest is used for trading equity
Lev = math.max(math.round(strategy.equity * leverage  / close , precision), 0)

if (not na(vrsi))
	if (co)
		strategy.entry("RsiLE", strategy.long,qty = Lev, comment="RsiLE")
	if (cu)
		strategy.entry("RsiSE", strategy.short,qty = Lev, comment="RsiSE")
//plot(strategy.equity, title="equity", color=color.red, linewidth=2, style=plot.style_areabr)

더 많은