Chiến lược hợp nhất các chỉ số trung bình động kép

Tác giả:ChaoZhang, Ngày: 2023-09-11 16:32:22
Tags:

Chiến lược hợp nhất các chỉ số trung bình động kép

Chiến lược này tích hợp chỉ số 2/20 MA và Bộ dao động giá tuyệt đối (APO) để tạo ra tín hiệu giao dịch.

Thứ nhất, nó tính toán EMA 20 giai đoạn và tạo ra các tín hiệu dài / ngắn đơn giản khi giá phá vỡ trên hoặc dưới EMA. Thứ hai, nó tính toán chỉ số APO từ chênh lệch EMA nhanh và chậm để xác định đà tăng / giảm.

Cuối cùng, chiến lược kết hợp cả hai chỉ số: các mục nhập dài / ngắn được kích hoạt khi cả 2/20 MA và APO đều đưa ra các tín hiệu tương ứng; ra khỏi xảy ra khi hai tín hiệu trái ngược.

Ưu điểm của chiến lược hai chỉ số này là khai thác các điểm mạnh kỹ thuật của mỗi chỉ số và xác minh các tín hiệu để cải thiện hiệu suất.

Tóm lại, chiến lược tổng hợp trung bình động kép kết hợp các chỉ số đơn giản và phức tạp để lọc các giao dịch tiếng ồn, nhưng điều chỉnh tham số thích hợp là cần thiết, cùng với việc tuân thủ chặt chẽ khung thời gian sử dụng được đề xuất, nếu không hiệu suất trực tiếp không thể được đảm bảo.


/*backtest
start: 2023-01-01 00:00:00
end: 2023-03-23 00:00:00
period: 12h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 14/01/2022
// This is combo strategies for get a cumulative signal. 
//
// First strategy
// This indicator plots 2/20 exponential moving average. For the Mov 
// Avg X 2/20 Indicator, the EMA bar will be painted when the Alert criteria is met.
//
// Second strategy
// The Absolute Price Oscillator displays the difference between two exponential 
// moving averages of a security's price and is expressed as an absolute value.
// How this indicator works
//    APO crossing above zero is considered bullish, while crossing below zero is bearish.
//    A positive indicator value indicates an upward movement, while negative readings 
//      signal a downward trend.
//    Divergences form when a new high or low in price is not confirmed by the Absolute Price 
//      Oscillator (APO). A bullish divergence forms when price make a lower low, but the APO 
//      forms a higher low. This indicates less downward momentum that could foreshadow a bullish 
//      reversal. A bearish divergence forms when price makes a higher high, but the APO forms a 
//      lower high. This shows less upward momentum that could foreshadow a bearish reversal.
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
EMA20(Length) =>
    pos = 0.0
    xPrice = close
    xXA = ta.ema(xPrice, Length)
    nHH = math.max(high, high[1])
    nLL = math.min(low, low[1])
    nXS = nLL > xXA or nHH < xXA ? nLL : nHH
    iff_1 = nXS < close[1] ? 1 : nz(pos[1], 0)
    pos := nXS > close[1] ? -1 : iff_1
    pos

APO(LengthShortEMA, LengthLongEMA) =>
    pos = 0.0
    xPrice = close
    xShortEMA = ta.ema(xPrice, LengthShortEMA)
    xLongEMA = ta.ema(xPrice, LengthLongEMA)
    xAPO = xShortEMA - xLongEMA
    iff_1 = xAPO < 0 ? -1 : nz(pos[1], 0)
    pos := xAPO > 0 ? 1 : iff_1
    pos

strategy(title='Combo 2/20 EMA & Absolute Price Oscillator (APO) ', shorttitle='Combo', overlay=true)
var I1 = '●═════ 2/20 EMA ═════●'
Length = input.int(14, minval=1, group=I1)
var I2 = '●═════ Absolute Price Oscillator (APO)  ═════●'
LengthShortEMA = input.int(10, minval=1, group=I2)
LengthLongEMA = input.int(20, minval=1, group=I2)
var misc = '●═════ MISC ═════●'
reverse = input.bool(false, title='Trade reverse', group=misc)
var timePeriodHeader = '●═════ Time Start ═════●'
d = input.int(1, title='From Day', minval=1, maxval=31, group=timePeriodHeader)
m = input.int(1, title='From Month', minval=1, maxval=12, group=timePeriodHeader)
y = input.int(2005, title='From Year', minval=0, group=timePeriodHeader)

StartTrade = time > timestamp(y, m, d, 00, 00) ? true : false
posEMA20 = EMA20(Length)
prePosAPO = APO(LengthShortEMA, LengthLongEMA)
iff_1 = posEMA20 == -1 and prePosAPO == -1 and StartTrade ? -1 : 0
pos = posEMA20 == 1 and prePosAPO == 1 and StartTrade ? 1 : iff_1
iff_2 = reverse and pos == -1 ? 1 : pos
possig = reverse and pos == 1 ? -1 : iff_2
if possig == 1
    strategy.entry('Long', strategy.long)
if possig == -1
    strategy.entry('Short', strategy.short)
if possig == 0
    strategy.close_all()
barcolor(possig == -1 ? #b50404 : possig == 1 ? #079605 : #0536b3)

Thêm nữa