점에 기반한 Stop Loss 전략을 이동하고 수익을 취하고 Stop Loss

저자:차오장, 날짜: 2024-01-11 11:04:57
태그:

img

전반적인 설명

이 전략의 핵심 아이디어는 EMA와 WMA의 크로스오버를 엔트리 신호로 사용하여 거래에 대한 포인트 계산에 기반한 수익을 취하고 손실을 멈추는 것을 통합하는 것입니다. 가장 큰 장점은 수익을 취하고 손실을 멈추는 폭을 제어하기 위해 포인트 수를 조정함으로써 위험을 매우 유연하고 정확하게 제어 할 수 있다는 것입니다.

전략 원칙

EMA가 WMA를 상향으로 넘을 때 긴 신호가 생성됩니다. EMA가 WMA를 하향으로 넘을 때 짧은 신호가 생성됩니다. 포지션을 입력 한 후 입상 가격은 실시간으로 계산되며 이를 기반으로 스톱 로스와 영업이 설정됩니다. 예를 들어, 스톱 로스를 20 포인트로 설정하고 영업을 100 포인트로 설정하면 특정 스톱 로스 가격은 입시 가격 마이너스 20 포인트 * 계약 가치, 그리고 영업 가격은 입시 가격 더하기 100 포인트 * 계약 가치입니다. 이렇게 위험과 영업이 제어됩니다.

동시에, 전략은 현재 시장 가격과 역사적인 스톱 손실을 결합하여 이동 스톱 손실 위치를 조정하고 후속 스톱 손실을 실현합니다.

이점 분석

고정 포인트 또는 백분율 스톱 러스 (Stop Loss) 와 비교하면 이 전략의 가장 큰 장점은 매우 유연하고 정확하게 위험을 제어할 수 있다는 것입니다. 포인트 수를 조정함으로써 스톱 러스의 진폭이 직접적으로 영향을받을 수 있습니다. 이것은 다른 품종에 매우 잘 적용되며 시장 변동 주파수 및 진폭에 따라 매개 변수를 세밀하게 조정 할 수 있습니다.

또한, 트레일링 스톱 로스는 매우 실용적인 기능이기도 합니다. 리얼 타임 시장 변화에 따라 스톱 로스 포지션을 추적하고 조정할 수 있으며, 동시에 위험 통제를 보장하고 가능한 수익을 극대화 할 수 있습니다.

위험 분석

이 전략의 주요 위험은 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))

더 많은