SMA オフセット変動取引戦略

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

img

戦略の概要

この戦略は,簡単な移動平均値 (SMA) といくつかの数学的計算を使用して,買/売ポイントを決定する.我々は100日間のSMAラインをベースとして保持する.閉値がこの線を下回る場合,設定可能な価格が線を下回る割合 (低オフセット) をベースに開口ポジションを決定する.同様に,我々はロングポジションを閉じる前に100日間のSMA上に高いオフセットパーセントを設定する.価格が上昇している間,あまりにも早く閉じるようにしようとすると,トレーリングストップロスは引き起こす.

戦略の論理

この戦略は3つのSMAラインを使用します. 急速なライン (デフォルト14日),遅いライン (デフォルト100日),基準ライン (デフォルト30日).

閉じる価格が基準線を下回り,スローライン (低オフセット) 下の割合が設定値より大きいとき,スローラインが上昇し,スローラインが落ちるときに長くなります.この条件を満たすとき,スローラインとスローラインはすぐに交差する可能性が高いので,良いエントリーポイントです.

閉じる価格が基準線上にある場合,閉じる価格が3連行で上昇し,高速線がスローライン上にある場合,閉じる価格が設定値よりも高くなります.

オーダーのサイズは 総資本の割合に基づいており ポジションの大きさを制御します

利点分析

  1. 価格変動を緩和し,市場の騒音をフィルタリングできるSMAの利点を活用する.
  2. SMAクロスオーバーは,トレンド変化を予測する能力がある.
  3. 偏差を設定することで,SMA線の誤ったブレイクが回避されます.
  4. 傾向指標とクロスオーバー指標を組み合わせることで,取引信号の正確性が向上します.
  5. ストップ・ロスは利益を固定し 引き下げを防ぐ

リスク分析

  1. SMA自体は遅れがあり,価格のターニングポイントを見逃す可能性があります.
  2. 不適切なオフセットは 戦略を攻撃的すぎたり 保守的すぎたりします
  3. 誤ったストップ損失パラメータは,遅すぎたり,ストップ損失パーセントが大きすぎたりする可能性があります.
  4. 価格変動に耐えられない

対応する改善:

  1. フィルターエントリに他の主要指標を追加します.
  2. バックテストとオフセットの最適化
  3. バックテストして最適なストップ損失パラメータを見つけます
  4. 高波動期間のポジションサイズを減らす.

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

  1. 最適なパラメータを見つけるために,異なる期間のSMAをテストする.
  2. 市場構造と動向を決定するために他の指標を追加します.
  3. ストップ・ロスのパラメータを最適化して 利益を増やす
  4. 市場変動に基づいてポジションのサイズを調整する.
  5. 戦略を複数の製品に同時に適用して 多様化します

結論

SMAオフセット変動取引戦略は,異なるSMAラインに基づいてオフセットを設定することによって最適なエントリーポイントを特定する.出口メカニズムは,利益をロックするためにトライリングストップ損失を設定する.この戦略は理解し実行するのが簡単です.SMA期間,オフセット,ストップ損失レベルなどのパラメータを最適化することで,より良い結果が得られます.安定した利益を求める中長期投資家に適しています.


/*backtest
start: 2022-12-12 00:00:00
end: 2023-12-18 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version=4
// Author: Sonny Parlin (highschool dropout)
strategy(shorttitle="SMA+Strategy", title="SMA Offset Strategy",
                                      overlay=true,  currency=currency.USD,
                                      initial_capital=10000)

// Inputs and variables
ss = input(14, minval=10, maxval=50, title="SMA Fast (days)")
ff = input(100, minval=55, maxval=200, title="SMA Slow (days)")
ref = input(30, minval=20, maxval=50, title="SMA Reference (days)")
lowOffset = input(0.001, "Low Offset (%)", minval=0, step=0.001)
highOffset = input(0.0164, "High Offset (%)", minval=0, step=0.0001)
orderStake = input(0.96, "Order Stake (%)", minval=0, step=0.01)

// SMA
smaFast = sma(close, ss)
smaSlow = sma(close, ff)
smaRef = sma(close, ref)
distanceLow = (close - smaSlow) / close
distanceHigh = (close - smaSlow) / close

// Set up SMA plot but don't show by default
plot(smaFast, "smaFast", color=#00ff00, display = 0)
plot(smaSlow, "smaSlow", color=#ff0000, display = 0)
plot(smaRef, "smaRef", color=#ffffff, display = 0)

// The buy stratey:
// guard that the low is under our sma low reference line by our lowOffset %, 
// default is 0.001. (low < smaRef) and (distanceLow > lowOffset)
// SMA fast is on the rise and SMA slow is falling and they are very likely
// to cross. (rising(smaFast,1)) and (falling(smaSlow, 1)) 
enterLong = (low < smaRef) and (distanceLow > lowOffset) and (rising(smaFast,1)) and (falling(smaSlow, 1)) 

// The sell Strategy:
// Guard that close is higher than our sma high reference line by our 
// highOffset %, default is 0.0164. (close > smaRef) and (distanceHigh > highOffset)
// Guard that close has risen by 3 candles in a row (rising(close,3)) 
// Guard that we currently have profit (strategy.openprofit > 0)
// Guard that SMA fast is higher than smaSlow (smaFast > smaSlow)
// If it keeps going up past our close position the trailing stoploss will kick in!
enterShort = (close > smaRef) and (distanceHigh > highOffset) and (rising(close,3)) and (strategy.openprofit > 0) and (smaFast > smaSlow)

// Order size is based on total equity
// Example 1:
// startingEquity = 2000
// close = 47434.93
// orderStake = 0.45
// (2,000 × orderStake) / close = orderSize = 0.0189733599 = approx $900

// Example 2:
// startingEquity = 2000
// close = 1.272
// orderStake = 0.45
// (startingEquity × orderStake) / close = orderSize = 707.5471698113 = approx $900
orderSize = (strategy.equity * orderStake) / close

// Trailing Stoploss
// I'm using 1.35 as my default value, play with this for different results.
longTrailPerc = input(title="Trailing Stoploss (%)",
     type=input.float, minval=0.0, step=0.1, defval=1.35) * 0.01
     
longStopPrice = 0.0

longStopPrice := if (strategy.position_size > 0)
    stopValue = close * (1 - longTrailPerc)
    max(stopValue, longStopPrice[1])
else
    0

if (enterLong)
    strategy.entry("Open Long Position", strategy.long, orderSize, when=strategy.position_size <= 0)
    
if (enterShort)
    strategy.exit(id="Close Long Position", stop=longStopPrice)


//plot(strategy.equity)

もっと