ポイントをベースにしたストップ・ロスの戦略を移動する 利益とストップ・ロスのポイント

作者: リン・ハーンチャオチャン開催日:2024年11月11日 11:04:57
タグ:

img

概要

この戦略の主なアイデアは,EMAとWMAのクロスオーバーをエントリー信号として利用し,取引のためのポイント計算に基づいて利益とストップロスを組み込むことです.最大の利点は,利益とストップロスの幅を制御するためにポイントの数を調整することで,リスクを非常に柔軟かつ正確に制御できるということです.

戦略原則

EMAがWMAを上向きに横切ると,ロングシグナルが生成される. EMAがWMAを下向きに横切ると,ショートシグナルが生成される.ポジションを入力した後,エントリー価格がリアルタイムで計算され,ストップ・ロストとテイク・プロフィートがそれに基づいて設定される.例えば,ストップ・ロストを20ポイントに設定し,テイク・プロフィートを100ポイントに設定すると,特定のストップ・ロスト価格がエントリー価格マイナス20ポイント*契約価値,テイク・プロフィートの価格がエントリー価格プラス100ポイント*契約価値となる.この方法でリスクと利益が制御される.

同時に,戦略は,現在の市場価格と歴史的なストップ損失を組み合わせて,移動ストップ損失ポジションを調整し,トラッキングストップ損失を実現します.

利点分析

固定ポイントまたは百分比ストップ損失と比較して,この戦略の最大の利点は,非常に柔軟かつ正確にリスクを制御できるということです.ポイントの数を調整することによって,ストップ損失の幅が直接影響を受けることができます.これは異なる品種に非常によく適用され,市場変動の頻度と幅に基づいてパラメータを微調整することができます.

さらに,ストップロスは非常に実用的な機能でもあります.リスク制御を保証しながら,リアルタイム市場変化に基づいてストップロスのポジションを追跡し調整し,可能な利益を最大化することができます.

リスク分析

この戦略の主なリスクは,EMAおよびWMA指標自体に由来する.激しい市場動きがあるとき,それらはしばしば間違った信号を発し,簡単にストップ損失につながる.この場合は,ストップ損失ポイントの数を適切に緩め,または他の指標組み合わせの置き換えを検討することを推奨する.

また,ストップ・ロストとテイク・プロフィートをバランスすることは困難である.より高いテイク・プロフィートを追求するには,しばしばより大きなリスクを負う必要がある.これは,市場が回転すると簡単にストップ・ロストにつながる.したがって,ストップ・ロストとテイク・プロフィートの構成は慎重にテストおよび評価する必要があります.

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

この戦略は,次の側面で最適化できます.

  1. EMAとWMAの異なるパラメータの組み合わせをテストし,最適なパラメータを見つけます.
  2. MACD,KDJなどの他の指標を試して 置き換えたり組み合わせたりして 勝率を向上させられるか見てみましょう
  3. ストップ・ロストとテイク・プロフィートの異なるポイント構成のリスク報酬を評価し,最適な設定を見つけます.
  4. 異なる品種の特徴を調査し,異なる市場に対応するためのパラメータを調整する.
  5. マシン学習アルゴリズムを組み込み パラメータのダイナミック最適化を実現する

結論

この戦略の核心構想は,EMAとWMAをベースとして使用し,リスク管理のためにポイントベースのストップ・ロスト・アンド・テイク・プロフィートメカニズムを使用することで,シンプルで明確である.戦略の利点は,異なる市場に対応して調整できる正確な柔軟なリスク制御にあります. フォローアップ最適化がエントリー信号,パラメータ選択,ストップ・ロストメカニズムなどで行われ,戦略が複雑で常に変化する市場環境により良い適応できるようにします.


/*backtest
start: 2024-01-03 00:00:00
end: 2024-01-10 00:00:00
period: 45m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// inspiration script from: @ahmad_naquib
// inspiration script link: https://www.tradingview.com/script/tGTV8MkY-Two-Take-Profits-and-Two-Stop-Loss/
// inspiration strategy script name: Two Take Profits and Two Stop Loss


////////////
// Do not use this strategy, it's just an exmaple !! The goal from this script is to show you TP and SL based on PIPS
////////////


//@version=5
strategy('SL & TP based on Pips', "PIP SL & TP", overlay=true, initial_capital=1000)

// MA
ema_period = input(title='EMA period', defval=10)
wma_period = input(title='WMA period', defval=20)
ema = ta.ema(close, ema_period)
wma = ta.wma(close, wma_period)

// Entry Conditions
long = ta.crossover(ema, wma) and nz(strategy.position_size) == 0
short = ta.crossunder(ema, wma) and nz(strategy.position_size) == 0

// Pips Calculation
pip1 = input(20, title = "TP PIP", group = "PIP CALCULATION") * 10 * syminfo.mintick
pip2 = input(20, title = "SL PIP", group = "PIP CALCULATION") * 10 * syminfo.mintick

// Trading parameters 
var bool LS = na
var bool SS = na

var float EP = na // Entry Position
var float TVL = na
var float TVS = na
var float TSL = na
var float TSS = na

var float TP1 = na
//var float TP2 = na
var float SL1 = na
///var float SL2 = na

// SL & TP Values
// there's also SL2 and TP2 in case you want to add them to your script, 
//also you can add a break event in the strategy.entry section.

if short or long and strategy.position_size == 0
    EP := close
    SL1 := EP - pip2 * (short ? -1 : 1)
    //SL2 := EP - pip2 * (short ? -1 : 1)
    
    TP1 := EP + pip1 * (short ? -1 : 1)
    //TP2 := EP + pip1 * 2 * (short ? -1 : 1)


// current trade direction    
LS := long or strategy.position_size > 0
SS := short or strategy.position_size < 0

// adjust trade parameters and trailing stop calculations
TVL := math.max(TP1, open) - pip1[1]
TVS := math.min(TP1, open) + pip1[1]
TSL := open[1] > TSL[1] ? math.max(TVL, TSL[1]) : TVL
TSS := open[1] < TSS[1] ? math.min(TVS, TSS[1]) : TVS

//if LS and high > TP1
    //if open <= TP1
        //SL2 := math.min(EP, TSL)

//if SS and low < TP1
    //if open >= TP1
        //SL2 := math.max(EP, TSS)


// Closing conditions
// and those are a closing conditions in case you want to add them.

//close_long = LS and open < SL2
//close_short = SS and open > SL2

// Buy
if (long and not SS)
    strategy.entry('buy', strategy.long)
strategy.exit('exit1', from_entry='buy', stop=SL1, limit=TP1, qty_percent=100)
//strategy.exit('exit2', from_entry='buy', stop=SL2, limit=TP2)

// Sell
if (short and not LS)
    strategy.entry('sell', strategy.short)
strategy.exit('exit3', from_entry='sell', stop=SL1, limit=TP1, qty_percent=100)
//strategy.exit('exit4', from_entry='sell', stop=SL2, limit=TP2)

// Plots
// those are plots for the lines of The tp and sl. they are really useful, and in the next update I will use a filling option.

a = plot(strategy.position_size > 0 ? SL1 : na, color=color.new(#af0829, 30), linewidth = 2, style=plot.style_linebr)
b = plot(strategy.position_size < 0 ? SL1 : na, color=color.new(#af0829, 30), linewidth = 2, style=plot.style_linebr)

c = plot(strategy.position_size > 0 ? TP1 : na, color=color.new(#2e7e00, 30), linewidth = 2, style=plot.style_linebr)
d = plot(strategy.position_size < 0 ? TP1 : na, color=color.new(#2e7e00, 30), linewidth = 2, style=plot.style_linebr)

g = plot(strategy.position_size >= 0 ? na : EP, color=color.new(#ffffff, 50), style=plot.style_linebr)
h = plot(strategy.position_size <= 0 ? na : EP, color=color.new(#ffffff, 50), style=plot.style_linebr)


// those are plot for the TP2 and SL2, they are optional if you want to add them.

//e = plot(strategy.position_size > 0 ? TP2 : na, color=color.new(#00ced1, 0), style=plot.style_linebr)
//f = plot(strategy.position_size < 0 ? TP2 : na, color=color.new(#00ced1, 0), style=plot.style_linebr)


//those are the plot for the ema and wma strategy for short and long signal. they are not really a good strategy, I just used them as an example
//but you have the option to plot them or not.
// do not use this strategy, it's just an exmaple !! The goal from this script is to show you TP and SL based on PIPS

//plot(ema, title='ema', color=color.new(#fff176, 0))
//plot(wma, title='wma', color=color.new(#00ced1, 0))

もっと