동적 퍼센트 상자 추적 전략


생성 날짜: 2023-11-23 10:32:39 마지막으로 수정됨: 2023-11-23 10:32:39
복사: 1 클릭수: 605
avatar of ChaoZhang ChaoZhang
1
집중하다
1617
수행원

동적 퍼센트 상자 추적 전략

개요

이 전략은 가격의 퍼센트 변화를 사용하여 구매 라인 및 중지 라인을 설정하고, 구매 라인을 깨는 가격에 따라 포지션을 구축하고, 중지 라인 아래에서 중지한다. 그것의 주요 특징은 단 1 단위의 위험을 감수하는 것 이다. 즉, 상위 포지션이 기본 수익 목표를 달성 한 후에만 포지션을 추가한다.

전략 원칙

이 전략은 먼저 기준 가격을 설정하고, 이 가격의 10%를 가격 범위에 두고, 상한은 구매 라인이고, 하한은 중지 라인이다. 가격이 구매 라인을 깨면, 고정된 양으로 구매한다. 가격이 중지 라인을 넘어지면, 평소 위치 중지한다. 수익을 얻은 후, 구매 라인과 중지 라인은 수익 영역을 확장하는 비율로 조정된다.

이 전략의 또 다른 중요한 점은 단 1 단위의 위험을 감수하는 것이다. 즉, 현재 포지션이 수익 목표에 도달한 후에만 새로운 포지션을 매장한다. 새로운 포지션은 또한 새로운 구매 라인 및 중지 라인에 의해 설정된다. 이것은 위험을 제한할 수 있다.

우위 분석

이 전략은 트래킹 스톱로스 (tracking stop loss) 와 포지션 관리 (storage management) 의 장점을 결합하여, 위험을 효과적으로 통제하면서 수익을 창출할 수 있습니다.

  1. 백분율 간격을 사용하여 구매 라인 및 중지 라인을 설정하여 트렌드를 자동으로 추적 할 수 있습니다.
  2. 리스크를 1자릿수로 조절하고 손실을 제한합니다.
  3. 이윤이 있을 때만 투자하고, 손실을 쫓는 것을 피하세요.
  4. 이윤을 취한 후, Stop Loss 라인을 이동하여 이윤을 잠금합니다.

위험 분석

이 전략에는 몇 가지 위험도 있습니다.

  1. 이 지수분야는 너무 넓고, 구매선과 중단선 사이가 너무 멀어서 위험이 커집니다.
  2. 소규모의 비율, 구매선과 중지선과 너무 가깝고, 수익의 여지가 제한되어 있습니다.
  3. 정지 혜택이 잘못 설정되어 있기 때문에 조기 정지될 수 있습니다.
  4. 너무 급진적으로 투자하면 손실이 커질 수 있다.

이러한 위험은 파라미터를 조정하여 피할 수 있습니다. 예를 들어, 비율 분기 크기를 조정하거나, 부가 조건을 조정합니다.

최적화 방향

이 전략에는 더 많은 최적화가 가능합니다.

  1. 트렌드 지표와 결합하여 트렌드 방향을 결정한 후에 입장을 세울 수 있습니다.
  2. 기계 학습 모형을 추가하여 구매 라인 및 중지 라인을 더 지능화 할 수 있습니다.
  3. 다른 가액 조건이 설정되어 위험을 더 낮출 수 있습니다.
  4. 다양한 포지션 기간을 테스트하여 최적의 포지션 주기를 찾을 수 있습니다.

요약하다

이것은 퍼센티지 간격을 이용한 거래 전략이다. 그것은 간단하고 실용적이며 위험을 효과적으로 통제한다. 매개 변수 조정과 모델 최적화를 통해, 이 전략은 투자자에게 안정적인 초과 수익을 창출하는 신뢰할 수 있는 트렌드 추적 시스템이 될 수 있다.

전략 소스 코드
/*backtest
start: 2022-11-16 00:00:00
end: 2023-11-22 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HermanBrummer 4 April 2021

strategy ("The Box Percent Strat", shorttitle="The Box", overlay = true)

///     Designed for LONG only on Daily, 2D or 3D Charts
///     Uses fixed investment risk amount, meaning you're willing to lose that amount per trade
///     Limit buy to not overpay

RiskPerTrade            = input(10000, "Risk losing this much per trade", tooltip="This calculates how much you will lose based on difference between the entry price and stop loss price")
TradeAboveMAFilterPer   = input(50, "The System won't trade if price is below this MA")

UpBoxSize               = (input(10, "Box size in %") * 0.01)+1 // 1.1 == 10% up
DnBoxSize               = 1-(input(10, "Box size in %") * 0.01) // 0.9 == 10% dn


var FirstBar            = close > 0 ? close : na
var FirstTop            = FirstBar * UpBoxSize
var FirstBot            = FirstBar * DnBoxSize


var top                 = sma(FirstTop, 1)
var bot                 = sma(FirstBot, 1)

///     The Box Calcs
if  high[2] > top
    top                 := top * UpBoxSize
    bot                 := bot * UpBoxSize
if  low[1]  < bot
    top                 := top * DnBoxSize
    bot                 := bot * DnBoxSize

 
plot(bot,   "Bot",      #ff0000) // Green
plot(top,   "Top",      #00ff00) // Red

mid                     = ((top-bot)/2)+bot 
plot(mid,   "Mid", color.gray)

TradeAboveMAFilter      = sma(close, TradeAboveMAFilterPer)
plot(TradeAboveMAFilter, "Trade AboveMAF Filter", color.yellow, 3, style=plot.style_circles)

// col = high[1] < top and high >= top ? color.white : na
// bgcolor(col)


///     Shares
RiskRange                   = close * abs(DnBoxSize - 1) // 0.9 - 1 == 1.10 // 10% abs so you don't get a neg number NB NB
Shares                      = RiskPerTrade / RiskRange 
//plot(close-RiskRange, "RiskRange", color.fuchsia)

Enter   =   high >= top
             and close[1] > TradeAboveMAFilter
             and strategy.opentrades[0] == strategy.opentrades[1]
             and strategy.opentrades[1] == strategy.opentrades[2] 
             and strategy.opentrades[2] == strategy.opentrades[3]
             and strategy.opentrades[3] == strategy.opentrades[4] 
             and strategy.opentrades[4] == strategy.opentrades[5]
             and strategy.opentrades[5] == strategy.opentrades[6]
             // won't enter if new positon was taken in the last 6 bars
             // need better code for this.

///     Buy & Sell
//  (new highs)    and  (Close above moving average filter) and (No new trades were taken receently)
if  Enter //(high >= top)  and  (close[1] > TradeAboveMAFilter) and strategy.opentrades[0] == strategy.opentrades[1] 
    strategy.order("En", strategy.long, qty=Shares, limit=top)//, stop=top)
    
//barcolor(strategy.position_size != 0 ? #00ff00 : color.gray)


// ///     If ONE Position THEN this Stop Because: 
// if  strategy.position_size == 1
//     strategy.exit("Ex", "En", stop=bot)
///     If it has more than one trad OPEN
if  strategy.position_size > 0
    strategy.exit("Ex", "En", stop=bot[2] )   // puts stop on old bot

//plot(strategy.position_avg_price, "Avg Price", color.yellow)