パインスクリプトにおけるレバレッジRSI戦略

作者: リン・ハーンチャオチャン, 日付: 2023-12-29 10:46:35
タグ:

img

概要

この戦略は,Pine Scriptがレバレッジで複利利息を達成するためにバックテスト中にレバレッジを設定できないという問題を解決することを目的としています.この戦略は,戦略の株式,設定レバレッジ比率,閉場価格に基づいてポジションサイズを動的に計算します.

戦略の論理

  1. 位置サイズ精度を制御するために精度精度を設定
  2. 負債のレバレッジを設定します 負債のレバレッジはデフォルトで1xです
  3. ポジションサイズを計算する:Lev = math.max(math.round(strategy.equity * leverage / close), 0)資本とレバレッジに比例する
  4. 入力シグナル:RSIが下から30を超えると長い;RSIが上から70を超えると短い
  5. 計算されたサイズで注文をしてください Lev

利点分析

  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)

もっと