Chiến lược kiểm tra ngược nến

Tác giả:ChaoZhang, Ngày: 2024-01-26 16:04:26
Tags:

img

Tổng quan

Chiến lược này xác định các mẫu nến để theo dõi tín hiệu giao dịch và kết hợp logic lấy lợi nhuận và dừng lỗ cho giao dịch tự động. Nó đi dài hoặc ngắn khi các mẫu đảo ngược được xác định và đóng các vị trí khi lấy lợi nhuận hoặc dừng lỗ được kích hoạt.

Chiến lược logic

  1. Long/short: Khi mô hình nến đảo ngược được xác định, đi dài nếu trước đó đóng cửa cao hơn 2 ngày trước, đi ngắn nếu trước đó đóng cửa thấp hơn 2 ngày trước.

Ưu điểm

  1. Cơ chế lấy lợi nhuận / dừng lỗ kiểm soát hiệu quả rủi ro, khóa lợi nhuận, tránh gia tăng lỗ.

Rủi ro

  1. Các thông số chiến lược cần kiểm tra và tối ưu hóa liên tục, nếu không sẽ quá phù hợp.

Hướng dẫn tối ưu hóa

  1. Tối ưu hóa điều kiện nhận dạng nến với nhiều chỉ số hơn để cải thiện độ chính xác.

  2. Làm giàu logic chiến lược bằng cách thêm các thuật toán để xác định nhiều tín hiệu giao dịch hơn.

Kết luận


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

//@version=3
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 30/01/2019
//   This is a candlestick where the open and close are the same. 
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
strategy(title = "Doji Backtest", overlay = true)
input_takeprofit = input(10, title="Take Profit pip", step=0.01)
input_stoploss = input(10, title="Stop Loss pip", step=0.01)
input_minsizebody = input(0.5, title="Min. Size Body pip", step=0.01)
barcolor(abs(close - open) <= input_minsizebody ? open == close ? yellow : na : na)
possell = 0.0
posbuy = 0.0
pospricebuy = 0.0
pospricesell = 0.0
barcolornow = blue
pospricesell := close< close[2] ? abs(close - open) <= input_minsizebody ? open == close ? close : nz(pospricesell[1], 0) : nz(pospricesell[1], 0) : nz(pospricesell[1], 0) 
possell := iff(pospricesell > 0 , -1, 0)
barcolornow := possell == -1 ? red: posbuy == 1 ? green : blue 
pospricesell := iff(low <= pospricesell - input_takeprofit and pospricesell > 0, 0 ,  nz(pospricesell, 0))
pospricesell := iff(high >= pospricesell + input_stoploss and pospricesell > 0, 0 ,  nz(pospricesell, 0))
pospricebuy := close > close[2] ? abs(close - open) <= input_minsizebody ? open == close ? close : nz(pospricebuy[1], 0) : nz(pospricebuy[1], 0) : nz(pospricebuy[1], 0) 
posbuy := iff(pospricebuy > 0 , 1, 0)
barcolornow := posbuy == 1 ? green: barcolornow
pospricebuy := iff(high >= pospricebuy + input_takeprofit and pospricebuy > 0, 0 ,  nz(pospricebuy, 0))
pospricebuy := iff(low <= pospricebuy - input_stoploss and pospricebuy > 0, 0 ,  nz(pospricebuy, 0))
barcolor(barcolornow)
if (posbuy == 0 and possell == 0) 
    strategy.close_all()
if (posbuy == 1)
    strategy.entry("Long", strategy.long)
if (possell == -1)
    strategy.entry("Short", strategy.short)	   	    
pospricebuy := iff(high <= pospricebuy + input_takeprofit and pospricebuy > 0, 0 ,  nz(pospricebuy, 0))
pospricebuy := iff(low >= pospricebuy - input_stoploss and pospricebuy > 0, 0 ,  nz(pospricebuy, 0))
pospricesell := iff(low <= pospricesell - input_takeprofit and pospricesell > 0, 0 ,  nz(pospricesell, 0))
pospricesell := iff(high >= pospricesell + input_stoploss and pospricesell > 0, 0 ,  nz(pospricesell, 0))


Thêm nữa