
Chiến lược chéo trung bình di chuyển là một chiến lược giao dịch định lượng dựa trên trung bình di chuyển. Chiến lược này tạo ra tín hiệu giao dịch, tạo ra lợi nhuận bằng cách tính toán giá trung bình của chứng khoán trong một khoảng thời gian, sử dụng chéo trung bình di chuyển của giá.
Chiến lược này chủ yếu sử dụng các đường chéo giữa đường trung bình di chuyển nhanh và đường trung bình di chuyển chậm để xác định xu hướng giá và tạo tín hiệu giao dịch. Cụ thể, là sử dụng đường trung bình di chuyển với hai chu kỳ khác nhau, chẳng hạn như đường 10 ngày và đường 20 ngày.
Khi đường trung bình di chuyển nhanh từ phía dưới phá vỡ đường trung bình di chuyển chậm, thị trường được coi là chuyển từ giảm sang tăng, tạo ra tín hiệu mua. Khi đường trung bình di chuyển nhanh từ phía trên giảm xuống đường trung bình di chuyển chậm, thị trường được coi là chuyển từ tăng sang giảm, tạo ra tín hiệu bán.
Bằng cách nắm bắt các điểm biến động của xu hướng giá, chiến lược này có thể mua khi thị trường thay đổi và bán khi thị trường thay đổi, tạo ra lợi nhuận.
Chiến lược này có những ưu điểm sau:
Chiến lược này cũng có những rủi ro sau:
Những rủi ro này có thể được giảm thiểu bằng cách tối ưu hóa thích hợp.
Chiến lược này có thể được tối ưu hóa theo các hướng sau:
Bằng cách tối ưu hóa, bạn có thể cải thiện đáng kể hiệu quả thực tế của chiến lược.
Chiến lược giao dịch chéo trung bình di chuyển nói chung là một chiến lược giao dịch định lượng dễ nắm bắt và thực hiện. Nó sử dụng nguyên tắc giao chéo của đường trung bình giá để đánh giá một cách đơn giản và trực quan xu hướng thị trường và tạo ra tín hiệu giao dịch. Bằng cách điều chỉnh tham số và kết hợp với các chỉ số kỹ thuật khác, bạn có thể tăng cường hiệu quả thực tế của chiến lược, làm cho nó trở thành một công cụ lợi nhuận định lượng đáng tin cậy.
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 1h
basePeriod: 15m
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/
// © HPotter
// Simple SMA strategy
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors
//@version=4
strategy(title="Simple SMA Strategy Backtest", shorttitle="SMA Backtest", precision=6, overlay=true)
Resolution = input(title="Resolution", type=input.resolution, defval="D")
Source = input(title="Source", type=input.source, defval=close)
xSeries = security(syminfo.tickerid, Resolution, Source)
Length = input(title="Length", type=input.integer, defval=14, minval=2)
TriggerPrice = input(title="Trigger Price", type=input.source, defval=close)
TakeProfit = input(50, title="Take Profit", step=0.01)
StopLoss = input(20, title="Stop Loss", step=0.01)
UseTPSL = input(title="Use Take\Stop", type=input.bool, defval=false)
BarColors = input(title="Painting bars", type=input.bool, defval=true)
ShowLine = input(title="Show Line", type=input.bool, defval=true)
UseAlerts = input(title="Use Alerts", type=input.bool, defval=false)
reverse = input(title="Trade Reverse", type=input.bool, defval=false)
pos = 0
xSMA = sma(xSeries, Length)
pos := iff(TriggerPrice > xSMA, 1,
iff(TriggerPrice < xSMA, -1, nz(pos[1], 0)))
nRes = ShowLine ? xSMA : na
alertcondition(UseAlerts == true and pos != pos[1] and pos == 1, title='Signal Buy', message='Strategy to change to BUY')
alertcondition(UseAlerts == true and pos != pos[1] and pos == -1, title='Signal Sell', message='Strategy to change to SELL')
alertcondition(UseAlerts == true and pos != pos[1] and pos == 0, title='FLAT', message='Strategy get out from position')
possig =iff(pos[1] != pos,
iff(reverse and pos == 1, -1,
iff(reverse and pos == -1, 1, pos)), 0)
if (possig == 1)
strategy.entry("Long", strategy.long)
if (possig == -1)
strategy.entry("Short", strategy.short)
if (UseTPSL)
strategy.close("Long", when = high > strategy.position_avg_price + TakeProfit, comment = "close buy take profit")
strategy.close("Long", when = low < strategy.position_avg_price - StopLoss, comment = "close buy stop loss")
strategy.close("Short", when = low < strategy.position_avg_price - TakeProfit, comment = "close buy take profit")
strategy.close("Short", when = high > strategy.position_avg_price + StopLoss, comment = "close buy stop loss")
nColor = BarColors ? strategy.position_avg_price != 0 and pos == 1 ? color.green :strategy.position_avg_price != 0 and pos == -1 ? color.red : color.blue : na
barcolor(nColor)
plot(nRes, title='SMA', color=#00ffaa, linewidth=2, style=plot.style_line)