
이것은 이동 평균 선 금포 형태를 이용한 트렌드 라인이 지속적으로 상향으로 형성되는 거래 전략이다. 빠른 라인이 하향에서 느린 라인을 뚫을 때 금포 신호가 형성된다. 금포 후의 추세가 계속 상승하면 이 단계에서 더 많은 포지션을 열 수 있다. 가격이 스톱 로스 라인 또는 스톱 로스 라인에 도달했을 때 스톱 로스 또는 스톱 로스를 선택할 수 있다.
이 전략은 주로 이동 평균의 골드포크 형태를 기반으로 진입 시점을 판단한다. 구체적으로, 빠른 이동 평균 MA1과 느린 이동 평균 MA2를 정의한다. MA1이 아래쪽에서 MA2를 돌파할 때, 더 많은 신호를 낸다.
단기 골드 포크로 인한 가짜 신호를 피하기 위해, 전략에 각 하락 판단이 추가되어, 즉 MA2의 각이 설정된 하락값보다 크면만 구매 신호를 유발한다. 이것은 일부 비 트렌디컬한 단기 상승을 필터링 할 수 있다.
전략은 동시에 중지 손실 라인을 설정하고 중지 중지 라인을. 중지 손실 라인은 시장의 갑작스러운 전환으로 인한 손실을 방지하기 위해 사용되며, 중지 중지 라인은 수익을 종료하는 데 사용됩니다. 입시 가격의 특정 퍼센트 범위로 설정됩니다.
가격 상승이 정지점에 도달했을 때, 전략은 정지기를 선택한다. 한편, 이번 라운드에서 상승이 강하면 전략은 다시 하위 역전을 한다.
이것은 매우 단순하고 직관적인 트렌드 추적 전략입니다. 다음과 같은 장점이 있습니다:
이 전략에는 몇 가지 위험도 있습니다.
이 전략은 다음의 몇 가지 측면에서 더 개선될 수 있습니다.
전체적으로 볼 때, 이것은 간단하고 실용적인 트렌드 추적 전략이다. 장점이 있지만 위험도 주의해야 한다. 추가적인 매개 변수 최적화, 지표 선택, 중지 중지 설정 등으로 개선하면 더 나은 안정적인 수익을 얻을 수 있다. 그러나 어떤 전략도 시장의 체계적인 위험을 완전히 피할 수 없으며 위험 인식을 구축하고 신중한 거래가 필요합니다.
/*backtest
start: 2023-11-05 00:00:00
end: 2023-11-12 00:00:00
period: 15m
basePeriod: 5m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//written by [email protected]
//@version=5
strategy(title="MJ-Dual Moving Average",initial_capital=10000,overlay=false)
// import TradingView/ZigZag/6 as ZigZagLib
// // Create Zig Zag instance from user settings.
// var zigZag = ZigZagLib.newInstance(
// ZigZagLib.Settings.new(
// input.float(5.0, "Price deviation for reversals (%)", 0.00001, 100.0, 0.5, "0.00001 - 100"),
// input.int(10, "Pivot legs", 2),
// input(#2962FF, "Line color"),
// input(true, "Extend to last bar"),
// input(true, "Display reversal price"),
// input(true, "Display cumulative volume"),
// input(true, "Display reversal price change", inline = "priceRev"),
// input.string("Absolute", "", ["Absolute", "Percent"], inline = "priceRev"),
// true)
// )
// // Update 'zigZag' object on each bar with new pivots, volume, lines, labels.
// zigZag.update()
// // plot(zigZag.pivots, "zigZag")
ma1= ta.sma(close,8)
ma2= ta.sma(close,21)
angleCriteria = input.int(title="Angle", defval=7, minval=1, maxval=13)
i_lookback = input.int(2, "Angle Period", minval = 1)
i_atrPeriod = input.int(10, "ATR Period", minval = 1)
i_angleLevel = input.int(6, "Angle Level", minval = 1)
i_maSource = input.source(close, "MA Source")
TP = input.float(1, "TP", minval = 0.1)
SL = input.float(1, "SL", minval = 0.1)
f_angle(_src, _lookback, _atrPeriod) =>
rad2degree = 180 / 3.141592653589793238462643 //pi
ang = rad2degree * math.atan((_src[0] - _src[_lookback]) / ta.atr(_atrPeriod)/_lookback)
ang
_angle = f_angle(ma2, i_lookback, i_atrPeriod)
plot(ta.atr(i_atrPeriod), "atr")
// plot(ma1,color=#FF0000)
// plot(ma2,color=#00FF00)
crosso=ta.crossover(ma1,ma2)
crossu=ta.crossunder(ma1,ma2)
_lookback = 15
f_somethingHappened(_cond, _lookback) =>
bool _crossed = false
for i = 1 to _lookback
if _cond[i]
_crossed := true
_crossed
longcrossed = f_somethingHappened(crosso,_lookback)
shortcrossed = f_somethingHappened(crossu,_lookback)
atr_factor = 1
atr = ta.atr(i_atrPeriod)
e = atr * atr_factor
afr = close
afr := nz(afr[1], afr)
atr_factoryHigh = close + e
atr_factoryLow = close - e
if atr_factoryLow > afr
afr := atr_factoryLow
if atr_factoryHigh < afr
afr := atr_factoryHigh
// plot(afr, "afr", display = display.data_window)
// plot(atr_factoryHigh, "afr", color = color.yellow, display = display.all)
// plot(atr_factoryLow, "afr", color = color.green, display = display.all)
inLong() => strategy.position_size > 0
inShort() => strategy.position_size < 0
inZero() => not inLong() and not inShort()
long = longcrossed and _angle > angleCriteria
short= shortcrossed and _angle < -(angleCriteria)
plotshape(long, "Buy", shape.arrowup, location.belowbar, color = #FF0000)
plotshape(short, "Sell", shape.arrowdown, location.abovebar, color = #00FF00)
var longTp = 0.0
var longSl = 0.0
var shortTp = 0.0
var shortSl = 0.0
[b_middle, b_high, b_low] = ta.bb(close, 20, 2)
entry_price = strategy.opentrades.entry_price(0)
if inZero()
if short
longTp := close * (1 + TP/100)
longSl := close * (1 - SL/100)
strategy.entry("LONG",strategy.long, comment = "tp:" + str.tostring(longTp) + " sl:" + str.tostring(longSl))
if long
shortTp := close * (1 - TP/100)
shortSl := close * (1 + SL/100)
strategy.entry("SHORT",strategy.short, comment = "tp:" + str.tostring(shortTp) + " sl:" + str.tostring(shortSl))
if inLong()
// if close - entry_price > close * 0.005
// longSl := entry_price + close * 0.001
if high > longTp
strategy.close("LONG")
if (close - open) > close * 0.014
shortTp := close * (1 - TP/100)
shortSl := close * (1 + SL/100)
strategy.entry("SHORT",strategy.short, comment = "tp:" + str.tostring(shortTp) + " sl:" + str.tostring(shortSl))
if close < longSl
strategy.close("LONG")
if open >= b_high and close >= b_high
strategy.close("LONG")
// if high > b_high and entry_price < high
// strategy.close("LONG")
if inShort()
// if entry_price - close > close * 0.005
// shortSl := entry_price - close * 0.001
if low < shortTp
strategy.close("SHORT")
if (open - close) > close * 0.014
longTp := close * (1 + TP/100)
longSl := close * (1 - SL/100)
strategy.entry("LONG",strategy.long, comment = "tp:" + str.tostring(longTp) + " sl:" + str.tostring(longSl))
if close > shortSl
strategy.close("SHORT")
if open < b_low and close < b_low
strategy.close("SHORT")
// if low < b_low and entry_price > low
// strategy.close("SHORT")