비행 용 트렌드 전략

저자:차오장, 날짜: 2023-11-07 14:57:23
태그:

img

전반적인 설명

플라잉 드래곤 트렌드 전략은 유형의 종류, 길이 및 오프셋의 이동 평균의 구성에 따라 다른 색상의 트렌드 대역을 그리면서 거래 신호를 생성합니다. 트렌드 정확성과 거래 위험을 균형을 맞추기 위해 다양한 시간 프레임에 최적의 매개 변수 세트를 찾을 수 있습니다.

전략 논리

이 전략은 트렌드 밴드를 MA1 및 MA4로 표시하는 두 개의 이동 평균을 사용합니다. MA1은 더 빠른 이동 평균이며 MA4는 느립니다. 한편, MA1에는 MA2와 MA3를 형성하는 3 개의 오프셋 설정 (오프셋1, 오프셋2, 오프셋3) 이 있습니다. 다른 이동 평균을 넘어서면 다른 위험 수준으로 거래 신호를 생성합니다.

선택할 수있는 5 가지 위험 수준이 있습니다. 거래 신호는 가격이 다른 위험 수준에서 다른 이동 평균을 가로질러 높고 낮을 때만 발생합니다: MA1 오프셋1, MA2, MA3, MA4, 모든 트렌드 밴드 동일한 색상. 트렌드 밴드의 색상은 현재 트렌드 방향을 나타냅니다. 상승 추세를 위해 녹색과 하락 추세를 위해 빨간색.

이 전략은 또한 스톱 로스 및 옵션이 길거나 짧거나 양방향으로만 허용됩니다.

이점 분석

  • 다양한 시간 프레임에 최적의 매개 변수 집합을 찾고 더 많은 시장 조건에 적응 할 수 있습니다.
  • 다양한 제품에서 최적화 할 수있는 다양한 MA 유형
  • 이 전략의 핵심인 오프셋은 트렌드 판단을 더 정확하게 합니다.
  • 위험 수준은 위험과 보상 사이의 균형을 이룬다
  • 다양한 매개 변수 조합으로 매우 사용자 정의
  • 직관적인 트렌드 대역은 명확한 시각적 거래 신호를 형성합니다.
  • 스톱 로스 리스크 제어

위험 분석

  • 높은 위험 수준은 잘못된 신호를 생성 할 수 있습니다. 위험 수준을 낮추거나 매개 변수를 조정해야 합니다.
  • 트렌드가 역전될 때 연속적인 스톱 로스 출구 위험
  • 다른 제품에는 별도의 매개 변수 테스트와 최적화가 필요합니다.
  • 높은 주파수 거래에서 빠른 MA는 느린 MA를 이끌어야 합니다.
  • 부적절한 매개 변수 최적화는 과민성 또는 느림성을 유발할 수 있습니다.

위험은 점차적으로 위험 수준을 낮추고, 더 많은 매개 변수 조합을 테스트하고, 다른 제품에 대해 매개 변수를 개별적으로 최적화함으로써 관리될 수 있습니다.

최적화 방향

  • 이동 평균의 다른 조합을 테스트
  • 최적의 길이를 찾기 위해 더 많은 길이 값을 시도
  • 오프셋 을 조심스럽게 조정 하는 것, 최적화 하는 열쇠
  • 다양한 제품에 대한 매개 변수를 개별적으로 최적화
  • 손해를 막는 지점을 최적화하고 수익을 고려하십시오.
  • 다른 입력 규칙 조합을 테스트
  • 최적화를 위해 필터가 필요한지 평가
  • 지원에 대한 경향 강도 지표를 추가하는 것을 고려하십시오.

요약

플라잉 드래곤 트렌드 전략은 가시화 가능한 트렌드 트레이딩 시스템으로 움직이는 평균을 현명하게 결합합니다. 높은 매개 변수 조정성은 안정성과 민감성 사이의 최적의 균형을 이루기 위해 다른 제품과 시장 체제에 대한 정밀 최적화를 가능하게합니다. 풍부한 매개 변수 조합은 충분한 최적화 공간을 제공합니다. 요약하면이 전략은 새로운 논리와 높은 실용적 유용성을 가지고 있습니다. 올바르게 최적화되면 매우 강력한 트렌드 추적 시스템으로 변할 수 있습니다.


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

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MarkoP010 2023

//@version=5
//The basic idea of the strategy is to select the best set of MAs, types, lenghts and offsets, which draws red trend bands for downtrend (and green for uptrend).
//Strategy executes by selected risk level either when there is MA crossover with price (MA1 Offset1 on Highest risk level, MA2 on Low risk level) or three bands with the same color on at the same time (on Lowest risk level).
//Strategy plots user selectable Moving Average lines and a colored trend band between the MA lines. The trend bands can be turned off individually if required.
//The Offset option shifts the selected MA with the set number of steps to the right. That is where the Magic happens and the Dragon roars!

//Strategy version 1.0
strategy("Flying Dragon Trend Strategy", shorttitle="FD Trend Strategy", overlay=true, pyramiding=3, initial_capital=100000, default_qty_type=strategy.percent_of_equity, default_qty_value=5, commission_type=strategy.commission.cash_per_order, commission_value=10, calc_on_order_fills=false, process_orders_on_close=true)

strDirection = input.string(defval="Both", title="Strategy Direction", options=["Both", "Long", "Short"], group="Strategy") //Strategy direction selector by DashTrader
strSelection = strDirection == "Long" ? strategy.direction.long : strDirection == "Short" ? strategy.direction.short : strategy.direction.all //Strategy direction selector by DashTrader
strategy.risk.allow_entry_in(strSelection)

riskLevel = input.string(defval="Medium", title="Risk Level", options=["Highest", "High", "Medium", "Low", "Lowest"], tooltip="Strategy execution criteria. When Highest then MA1 Offset1 crossover with price, when Low then MA2 Offset crossover, when Lowest then all the Bands are the same color.", group="Strategy")

useStop = input(defval=false, title="Use Stop Loss", inline="SL", group="Strategy")
stopPrct = input.int(defval=10, title=" %", minval=0, maxval=100, step=1, inline="SL", group="Strategy") / 100

//Moving Averages function
MA(source, length, type) =>
    type == "EMA" ? ta.ema(source, length) :
     type == "HMA" ? ta.hma(source, length) :
     type == "RMA" ? ta.rma(source, length) :
     type == "SMA" ? ta.sma(source, length) :
     type == "SWMA" ? ta.swma(source) :
     type == "VWMA" ? ta.vwma(source, length) :
     type == "WMA" ? ta.wma(source, length) :
     na

//Inputs
ma1Type = input.string(defval="HMA", title="", inline="MA1", options=["EMA", "HMA", "RMA", "SMA","SWMA", "VWMA", "WMA"], group="Leading Moving Average") 
ma1Length = input.int(defval=35, title="",minval=1, inline="MA1", group="Leading Moving Average")
ma1Source = input(defval=close, title="", tooltip="For short timeframes, minutes to hours, instead of Default values try Lowest risk level and HMA75 with Offsets 0,1,4 and SMA12 with Offset 6.", inline="MA1", group="Leading Moving Average")
ma1Color  = input(defval=color.purple, title="", inline="MA-1", group="Leading Moving Average")
//useMa1Offset = input(defval=false, title="Use offset to MA-1", inline="MA1", group="Leading Moving Average")
ma1Offset = input.int(defval=0, title="Offset1 Steps", minval=0, maxval=10, step=1, tooltip="The Magic happens here! The offset to move the line to the right.", inline="MA-1", group="Leading Moving Average")
ma1 = MA(ma1Source, ma1Length, ma1Type)[ma1Offset]

ma2Color  = input(defval=color.lime, title="", inline="MA-2", group="Leading Moving Average")
//useMa2Offset = input(defval=true, title="Use offset to MA2", inline="MA-2", group="Leading Moving Average")
ma2Offset = input.int(defval=4, title="Offset2 Steps", minval=0, maxval=10, step=1, tooltip="The Magic happens here! The offset to move the line to the right.", inline="MA-2", group="Leading Moving Average")
ma2 = ma1[ma2Offset]

ma3Color  = input(defval=color.aqua, title="", inline="MA-3", group="Leading Moving Average")
//useMa3Offset = input(defval=false, title="Use offset to MA3", inline="MA-3", group="Leading Moving Average")
ma3Offset = input.int(defval=6, title="Offset3 Steps", minval=0, maxval=10, step=1, tooltip="The Magic happens here! The offset to move the line to the right.", inline="MA-3", group="Leading Moving Average")
ma3 = ma1[ma3Offset]

ma4Type = input.string(defval="SMA", title="", inline="MA4", options=["EMA", "HMA", "RMA", "SMA","SWMA", "VWMA", "WMA"], group="Lagging Moving Average") 
ma4Length = input.int(defval=22, title="",minval=1, inline="MA4", group="Lagging Moving Average")
ma4Source = input(defval=close, title="", inline="MA4", group="Lagging Moving Average")
ma4Color  = input(defval=color.yellow, title="", inline="MA-4", group="Lagging Moving Average")
//useMa4Offset = input(defval=true, title="Use offset to MA4", inline="MA-4", group="Lagging Moving Average")
ma4Offset = input.int(defval=2, title="Offset Steps", minval=0, maxval=10, step=1, tooltip="The Magic happens here! The offset to move the line to the right.", inline="MA-4", group="Lagging Moving Average")
ma4 = MA(ma4Source, ma4Length, ma4Type)[ma4Offset]

bandTransp = input.int(defval=60, title="Band Transparency", minval=20, maxval=80, step=10, group="Banding")
useBand1 = input(defval=true, title="Band 1", inline="Band", group="Banding")
band1Transp = useBand1 ? bandTransp : 100
band1clr = ma1 > ma2 ? color.new(#00ff00, transp=band1Transp) : color.new(#ff0000, transp=band1Transp)
useBand2 = input(defval=true, title="Band 2", inline="Band", group="Banding")
band2Transp = useBand2 ? bandTransp : 100
band2clr = ma1 > ma3 ? color.new(#00ff00, transp=band2Transp) : color.new(#ff0000, transp=band2Transp)
useBand3 = input(defval=true, title="Band 3", tooltip="Up trend green, down trend red. Colors get reversed if MA1 lenght is greater than MA2 lenght, or they are different type and MA2 quicker. In that case, just reverse your selections for MA1 and MA2, or let it be as is.", inline="Band", group="Banding")
band3Transp = useBand3 ? bandTransp : 100
band3clr = ma1 > ma4 ? color.new(#00ff00, transp=band3Transp) : color.new(#ff0000, transp=band3Transp)

//Graphs
piirto1 = plot(ma1, color = ma1Color, title="MA1")
piirto2 = plot(ma2, color = ma2Color, title="MA2")
piirto3 = plot(ma3, color = ma3Color, title="MA3")
piirto4 = plot(ma4, color = ma4Color, title="MA4")

fill(piirto1, piirto2, color=band1clr)
fill(piirto1, piirto3, color=band2clr)
fill(piirto1, piirto4, color=band3clr)

//Strategy entry and stop conditions

longCondition = riskLevel == "Highest" ? ma1Source > ma1 : riskLevel == "High" ? ma1Source > ma2 : riskLevel == "Medium" ? ma1Source > ma3 : riskLevel == "Low" ? ma1Source > ma4 : riskLevel == "Lowest" ? ma1 > ma2 and ma1 > ma3 and ma1 > ma4 : na
shortCondition = riskLevel == "Highest" ? ma1Source < ma1 : riskLevel == "High" ? ma1Source < ma2 : riskLevel == "Medium" ? ma1Source < ma3 : riskLevel == "Low" ? ma1Source < ma4 : riskLevel == "Lowest" ? ma1 < ma2 and ma1 < ma3 and ma1 < ma4 : na

stopLprice = useStop == true ? strategy.position_avg_price * (1-stopPrct) : na
stopSprice = useStop == true ? strategy.position_avg_price * (1+stopPrct) : na

if (longCondition)
    strategy.entry("Long",strategy.long)
    strategy.exit("Long Stop", "Long", stop=stopLprice)    
if (shortCondition)
    strategy.entry("Short",strategy.short)
    strategy.exit("Short Stop", "Short", stop=stopSprice)

//End


더 많은