海洋理論のグリッド取引戦略

作者: リン・ハーンチャオチャン開催日:2023年10月13日17時07分39秒
タグ:

概要

この戦略は,既定の価格範囲内で購入・販売の注文を出すために,海洋理論におけるグリッド取引方法を活用している.この戦略は,グリッド価格範囲の自動計算とグリッドラインの均一な分布を特徴づけ,リスクを効果的に管理するのに役立ちます.

戦略の論理

この戦略は,まず,ユーザーの選択またはデフォルト設定に基づいて価格グリッドの上下境界を計算する.計算には2つの方法があります:バックテスト期間の最高値と最低値を取得するか,または時間枠における移動平均値を計算する.その後,グリッド線はユーザーによって設定されたグリッドの数に応じて均等に分布されます.

取引シグナルは価格とグリッドラインの関係に基づいて生成される.価格がグリッドラインを下回ると,固定量でグリッドライン価格でロングポジションが開かれ,価格がグリッドラインを超えると,ポジションが下のグリッドラインで閉鎖される.グリッド内で価格が変動するにつれて,ポジションは相応に変化して利益を得ます.

具体的には,この戦略は,グリッドライン価格配列と,各ラインにオーダーが配列されているかどうかを示すボール配列を維持する.価格がオーダーなしのラインの下にある場合,ラインでロングポジションが開かれ,価格がライン上にあり,下にあるラインにオーダーが存在する場合,ポジションが下のラインで閉鎖される.グリッド取引はこのように実装される.

利点

  1. 格子範囲は自動で計算され,手動設定の困難を回避します.さまざまな計算オプションが利用できます.

  2. 格子線は,密度の高い格子による過剰取引を避けるために均等に分布されている.格子数の調整が可能である.

  3. 格子取引方法はリスクを効果的に制御する.格子内の価格変動が続く限り,利益を得ることができます.

  4. 価格方向の仮定はなく,範囲限定市場に適しています.

  5. 異なる取引手段のための設定可能なプロミスとポジションサイズ.

  6. 格子線を視覚化することで,取引状況を理解できます.

リスク

  1. 価格突破リスク ネットワーク上限や下限を突破すると 損失が増える可能性があります

  2. 過剰なネットワーク空間リスク. 格段に緩やかなネットワークは簡単に利益を得ることができないが,狭すぎるとコストが増加する.バランスが求められる.

  3. 長期保有リスク 長期保有は利益を困難にし 費用を増加させる

  4. パラメータを正しく設定しないリスク. バックテスト期または移動平均期が正しく設定されていない場合,グリッド範囲の計算に影響を与える可能性があります.

  5. システム市場リスク 長期傾向市場ではなく範囲限定市場に適しています

強化

  1. ネットワークのパラメータを最適化する. ネットワークの数,見返り期間等を最適化するために,市場条件,コストなどを包括的に考慮する.

  2. ダイナミックなグリッド範囲調整を導入し,市場の重要な変化が発生したときにグリッド範囲を調整する.

  3. ストップ・ロスのメカニズムを組み込む. 損失を制限するために適切なストップ・ロスのラインを設定する. 動的に調整できる.

  4. 適切な取引を避けるために,ボリンジャー帯,トレンド指標など,他の指標を使用したフィルターを追加します.

  5. 資本利用効率を向上させ 安定した期間の取引を減らすため 変動分析を導入する.

結論

この戦略は,グリッド取引原理を活用することによってリスク制御可能な範囲取引を実現する.自動グリッド計算と均一な配分は,パラメータ調整を通じてさまざまな市場に適した利点を提供します.リスクは限られており操作が簡単です.しかし,限界があり,進化する市場に適応するために継続的な改善が必要です.全体として,戦略はグリッド取引を実施するための標準化されパラメータ的なアプローチを提供します.


/*backtest
start: 2023-09-12 00:00:00
end: 2023-10-12 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
strategy("(IK) Grid Script", overlay=true, pyramiding=14, close_entries_rule="ANY", default_qty_type=strategy.cash, initial_capital=100.0, currency="USD", commission_type=strategy.commission.percent, commission_value=0.1)
i_autoBounds    = input(group="Grid Bounds", title="Use Auto Bounds?", defval=true, type=input.bool)                             // calculate upper and lower bound of the grid automatically? This will theorhetically be less profitable, but will certainly require less attention
i_boundSrc      = input(group="Grid Bounds", title="(Auto) Bound Source", defval="Hi & Low", options=["Hi & Low", "Average"])     // should bounds of the auto grid be calculated from recent High & Low, or from a Simple Moving Average
i_boundLookback = input(group="Grid Bounds", title="(Auto) Bound Lookback", defval=250, type=input.integer, maxval=500, minval=0) // when calculating auto grid bounds, how far back should we look for a High & Low, or what should the length be of our sma
i_boundDev      = input(group="Grid Bounds", title="(Auto) Bound Deviation", defval=0.10, type=input.float, maxval=1, minval=-1)  // if sourcing auto bounds from High & Low, this percentage will (positive) widen or (negative) narrow the bound limits. If sourcing from Average, this is the deviation (up and down) from the sma, and CANNOT be negative.
i_upperBound    = input(group="Grid Bounds", title="(Manual) Upper Boundry", defval=0.285, type=input.float)                      // for manual grid bounds only. The upperbound price of your grid
i_lowerBound    = input(group="Grid Bounds", title="(Manual) Lower Boundry", defval=0.225, type=input.float)                      // for manual grid bounds only. The lowerbound price of your grid.
i_gridQty       = input(group="Grid Lines",  title="Grid Line Quantity", defval=8, maxval=15, minval=3, type=input.integer)       // how many grid lines are in your grid
strategy.initial_capital = 50000
f_getGridBounds(_bs, _bl, _bd, _up) =>
    if _bs == "Hi & Low"
        _up ? highest(close, _bl) * (1 + _bd) : lowest(close, _bl)  * (1 - _bd)
    else
        avg = sma(close, _bl)
        _up ? avg * (1 + _bd) : avg * (1 - _bd)

f_buildGrid(_lb, _gw, _gq) =>
    gridArr = array.new_float(0)
    for i=0 to _gq-1
        array.push(gridArr, _lb+(_gw*i))
    gridArr

f_getNearGridLines(_gridArr, _price) =>
    arr = array.new_int(3)
    for i = 0 to array.size(_gridArr)-1
        if array.get(_gridArr, i) > _price
            array.set(arr, 0, i == array.size(_gridArr)-1 ? i : i+1)
            array.set(arr, 1, i == 0 ? i : i-1)
            break
    arr

var upperBound      = i_autoBounds ? f_getGridBounds(i_boundSrc, i_boundLookback, i_boundDev, true) : i_upperBound  // upperbound of our grid
var lowerBound      = i_autoBounds ? f_getGridBounds(i_boundSrc, i_boundLookback, i_boundDev, false) : i_lowerBound // lowerbound of our grid
var gridWidth       = (upperBound - lowerBound)/(i_gridQty-1)                                                       // space between lines in our grid
var gridLineArr     = f_buildGrid(lowerBound, gridWidth, i_gridQty)                                                 // an array of prices that correspond to our grid lines
var orderArr        = array.new_bool(i_gridQty, false)                                                              // a boolean array that indicates if there is an open order corresponding to each grid line

var closeLineArr    = f_getNearGridLines(gridLineArr, close)                                                        // for plotting purposes - an array of 2 indices that correspond to grid lines near price
var nearTopGridLine = array.get(closeLineArr, 0)                                                                    // for plotting purposes - the index (in our grid line array) of the closest grid line above current price
var nearBotGridLine = array.get(closeLineArr, 1)                                                                    // for plotting purposes - the index (in our grid line array) of the closest grid line below current price

for i = 0 to (array.size(gridLineArr) - 1)
    if close < array.get(gridLineArr, i) and not array.get(orderArr, i) and i < (array.size(gridLineArr) - 1)
        buyId = i
        array.set(orderArr, buyId, true)
        strategy.entry(id=tostring(buyId), long=true, qty=(strategy.initial_capital/(i_gridQty-1))/close, comment="#"+tostring(buyId))
    if close > array.get(gridLineArr, i) and i != 0
        if array.get(orderArr, i-1)
            sellId = i-1
            array.set(orderArr, sellId, false)
            strategy.close(id=tostring(sellId), comment="#"+tostring(sellId))

if i_autoBounds
    upperBound  := f_getGridBounds(i_boundSrc, i_boundLookback, i_boundDev, true)
    lowerBound  := f_getGridBounds(i_boundSrc, i_boundLookback, i_boundDev, false)
    gridWidth   := (upperBound - lowerBound)/(i_gridQty-1)
    gridLineArr := f_buildGrid(lowerBound, gridWidth, i_gridQty)

closeLineArr    := f_getNearGridLines(gridLineArr, close)
nearTopGridLine := array.get(closeLineArr, 0)
nearBotGridLine := array.get(closeLineArr, 1)



もっと