格子ベースのロング・マルティンゲール・ダイナミック・ポジション・グリッド・トレーディング戦略

作者: リン・ハーンチャオチャン, 日付: 2024-03-22 15:12:33
タグ:

img

戦略の概要

この戦略は,グリッドベースのロングマルティンゲール動的ポジショングリッド取引戦略である.主なアイデアは,価格がグリッドラインに当たるとき,既存のポジションの数に基づいてポジションサイズを動的に調整し,最大総数のオープンポジションを設定することです.価格が上昇して利益のレベルに達すると,すべてのロングポジションは閉鎖されます.

戦略の原則

  1. 価格を"格子サイズ"パラメータに基づいて均等に格子に分けます.
  2. 各グリッドラインに長制限命令を
  3. 現在の価格がグリッドラインに達すると:
    • 現在のオープンポジション数が0である場合, start_lot サイズでポジションを開きます.
    • 現在のオープンポジション数が0以上で,現在のグリッド価格が前のエントリー価格より低い場合,現在のグリッド価格で新しいロングポジションを開設し,そのサイズが前回のポジションサイズを倍数する.
  4. オープンポジションの最大数は,パラメータ"最大オープンオーダー"によって制御されます.
  5. ポジションを開いた後,平均入場価格より"ポイント高い"TakeProfit"の利得レベルを設定します.
  6. 現在の価格が 利得のレベルに達すると すべてのロングポジションを閉じて パラメータをリセットします

このようにして,ダウントレンドの間,ポジションサイズは徐々に増加し,価格が回復し,利益のレベルに達すると利益を得ます.

戦略 の 利点

  1. ダイナミックなポジションサイズ: オープンポジションの現在の数に基づいて,各エントリのポジションサイズをダイナミックに調整します.これは継続的なダウントレンド中に徐々に露出を増加させ,戦略の利益の可能性を高めます.
  2. 柔軟なパラメータ: グリッドサイズ, スタート_ロット, マルチファクタなどのパラメータは,グリッドサイズ,初期位置サイズ,位置スケーリング因数などに柔軟な制御を可能にします.
  3. 制御可能なリスク: 最大オープンオーダーパラメータは,過度な露出を防ぐために,オープンポジションの最大数を制御する.同時に,利益の引き上げレベルを設定することで,引き上げを制御するために適時利益の引き上げが可能です.

戦略リスク

  1. ストップ損失なし: ストップ損失がない.価格が引き続き下落した場合,重大な損失リスクに直面する可能性があります.
  2. パラメータ敏感性: 戦略のパフォーマンスは"多因子"などのパラメータに非常に敏感です.不適切なパラメータはリスクをもたらす可能性があります.
  3. 高波動性: 戦略は,非常に波動性の高い市場状況下で頻繁にポジションを開閉し,追加的なスライドと手数料コストを伴う可能性があります.

リスク管理対策:

  1. リスク・トレランスに基づいて,注意して"多因子"のようなパラメータを設定します.必要に応じてストップ・ロスト・ロジックはコードに追加できます.
  2. 適切なパラメータを選択するために,慎重にバックテストと紙取引.
  3. 戦略のパフォーマンスを非常に不安定な市場条件で評価します.必要に応じて,パラメータを調整したり,使用シナリオを制限することによってリスクを軽減することができます.

オプティマイゼーションの方向性

  1. トレンド検出を追加: ポジションを開くときに価格アクションに基づいてトレンドを決定します.トレンドが下落傾向に見えた場合,リスクを減らすために新しいロングポジションを開くのを避ける.
  2. ダイナミック・テイク・プロフィート: 価格の動向,波動性,その他の指標に基づいて,テイク・プロフィートのレベルをダイナミックに調整する. 収益性を高めるためにトレンドが強いとき,テイク・プロフィートのレベルを上昇させる.
  3. ポジション管理を最適化: ポジションを追加する際には,スケーリングファクターを考慮するだけでなく,口座残高,現在の露出等も考慮し,ポジションのサイズをより正確に制御します.
  4. 他のシグナルと組み合わせる:グリッド取引を他のトレンド検出,振動検出および他の指標信号と統合して,市場を包括的に判断し,取引をガイドします.

これらの最適化は,市場の動きをよりうまく把握し,利益の可能性と安定性を高めるための戦略の適応性を向上させることができます.同時に,より正確なポジションとリスク管理は,引き上げを削減し,リスク/報酬比を改善することができます.

概要

このグリッドベースのロングマルティンゲール動的ポジショングリッド・トレーディング戦略は,格下げ傾向の際にポジションを徐々に追加することで平均保有価格を下げ,価格が上昇すると利益を得ることを試みます.この戦略はパラメータ設定を通じて強い柔軟性を提供します.しかし,慎重な評価と制御を必要とする重大な潜在的なリスクも伴います.トレンド検出,動的取利益,ポジション最適化,その他の機能が追加されれば,戦略のパフォーマンスはさらに向上する可能性があります.この戦略は,価格がグリッドラインに当たると自動的にポジションを開設し追加し,価格が取利益レベルに達すると自動的にすべてのポジションを閉鎖する機能を実現します.全体的な論理は比較的明確ですが,最適化余地があります.この戦略は,市場条件とパラメータを徹底的に評価した後,慎重に使用するのに適しています.


/*backtest
start: 2023-03-16 00:00:00
end: 2024-03-21 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/
// © lagerta13
//@version=4
strategy("Grid A.", shorttitle="Grid(A)", overlay=true, format=format.price, precision=4, pyramiding = 100)

input_tf=input("15", "Started TimeFrame", 
 options = ["1", "5", "15", "30", "1H", "4H", "1D", "1W", "1M"],
 group="TimeFrame") 

// avg_tf=input("5", "Average TimeFrame", 
//  options = ["1", "5", "15", "30", "1H", "4H", "1D", "1W", "1M"],
//  group="TimeFrame")

slip_Hilo = input(3.0, "Slippage by open order", group="Strategy Settings")
start_lot = input(0.01, "Start lot", group="Strategy Settings")
start_avg = input(2, "Started average since Order #", group="Strategy Settings")
MaxTrades_Hilo = input(10, "Max Open Orders", group="Strategy Settings")
dropdown_selection = input("Only Long", "Direction", options=["Only Long", "Only Short", "Long & Short"],
 group="Strategy Settings")
type_selection = input("By Close", "Type input", options=["By Close", "By grid line"],
 group="Strategy Settings")

multifactor = input(1.5, "Multifactor", group="Strategy Settings")
precision_lot = input(2, "Number of precision", group="Strategy Settings")
take_profit = input(1, "TakeProfit", group="Strategy Settings")

// PipStep_S1 = input(30)
// PipStepX_S1 = input(1.2)
// dinamicStep = input(false, "Dinamic Step for AVG")

get_size_lot_order(number, multi, prec, avg_from, lot_from) =>
	res = lot_from
	for i = 1 to number
		if i >= avg_from
			res := round(res * multi, precision = prec)
	res

var float[] entry_levels = array.new_float(MaxTrades_Hilo + 1)

for i = 0 to MaxTrades_Hilo
    array.push(entry_levels, 0)

gridSize = input(0.5, title="Grid Size")
gridLevels = int(close / gridSize) * gridSize

var int num_open_orders = 0
var float sum_price_orders = 0
var float entry_lot = 0

buy_condition = num_open_orders < MaxTrades_Hilo and gridLevels[0]<gridLevels[1] and dropdown_selection != "Only Short"

if (buy_condition)

    if num_open_orders == 0
        lot = get_size_lot_order(num_open_orders, multifactor, precision_lot, start_avg, start_lot)
        sum_price_orders := sum_price_orders + gridLevels[1] * lot 

        strategy.entry("buy" + tostring(num_open_orders), true, qty=lot, limit=gridLevels[1]+slip_Hilo) 
        // strategy.order("buy" + tostring(num_open_orders), true, qty=lot, limit=gridLevels[1]) 

        array.set(entry_levels, num_open_orders, gridLevels[1])

        entry_lot := entry_lot + lot
        num_open_orders := num_open_orders + 1

    else
        if gridLevels[1] < (array.get(entry_levels, num_open_orders - 1))
            lot = get_size_lot_order(num_open_orders, multifactor, precision_lot, start_avg, start_lot)
            sum_price_orders := sum_price_orders + gridLevels[1] * lot 
            entry_lot := entry_lot + lot

            strategy.entry("buy" + tostring(num_open_orders), true, qty=lot, limit=gridLevels[1]+slip_Hilo) 

            // +" S:" + tostring(sum_price_orders / (entry_lot)) + " Prev:" + tostring(array.get(entry_levels, num_open_orders - 1))
            // strategy.order("buy" + tostring(num_open_orders), true, qty=lot, limit=gridLevels[1]) 
            array.set(entry_levels, num_open_orders, gridLevels[1])

            num_open_orders := num_open_orders + 1


take = sum_price_orders > 0 and take_profit + (sum_price_orders / entry_lot) < high ? high : na
plotshape(take, location = location.belowbar, color = color.white)


strategy.exit("tp", comment = "TP " + tostring(num_open_orders), qty = entry_lot, limit = take_profit + (sum_price_orders / entry_lot))


if sum_price_orders > 0 and take_profit + (sum_price_orders / entry_lot) <= high
    num_open_orders := 0
    sum_price_orders := 0
    entry_lot := 0
    for i = 0 to MaxTrades_Hilo
        array.set(entry_levels, i, 0)

plot(gridLevels, color=color.blue, style=plot.style_circles, linewidth=2)

 

もっと