
Đây là một chiến lược giao dịch sử dụng hình thức moving average line gold fork, kết hợp với đường xu hướng liên tục tăng lên. Khi đường nhanh từ phía dưới phá vỡ đường chậm, tạo ra tín hiệu vàng. Nếu xu hướng sau khi gai vàng có thể tiếp tục tăng lên, thì bạn có thể mở nhiều vị trí ở giai đoạn này.
Chiến lược này chủ yếu dựa trên hình dạng vàng của đường trung bình di chuyển để đánh giá thời gian vào cửa. Cụ thể, xác định một đường trung bình di chuyển nhanh MA1 và đường trung bình di chuyển chậm MA2.
Để tránh các tín hiệu sai do các đường nứt ngắn hạn, chiến lược này đã thêm vào phán quyết giảm giá góc, tức là chỉ kích hoạt tín hiệu mua khi góc của MA2 lớn hơn mức giảm được đặt. Điều này có thể lọc ra một số tăng ngắn hạn không có xu hướng.
Chiến lược đặt cả đường dừng và đường dừng. Đường dừng được sử dụng để tránh tổn thất do thị trường đột ngột chuyển hướng, và đường dừng được sử dụng để khóa lợi nhuận.
Khi giá tăng lên đến điểm dừng, chiến lược sẽ chọn dừng và rời khỏi sân. Đồng thời, nếu giá tăng mạnh trong vòng này, chiến lược sẽ thực hiện lại hoạt động đảo ngược.
Đây là một chiến lược theo dõi xu hướng đơn giản và trực quan.
Chiến lược này cũng có một số rủi ro cần lưu ý:
Chiến lược này có thể được tối ưu hóa thêm bằng cách:
Nhìn chung, đây là một chiến lược theo dõi xu hướng đơn giản và thực tế. Nó có một số lợi thế, nhưng cũng cần chú ý đến rủi ro. Có thể đạt được lợi nhuận ổn định tốt hơn bằng cách tối ưu hóa tham số, lựa chọn chỉ số, thiết lập điểm dừng lỗ, v.v.
/*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")