Reversal Candlestick Backtesting Strategi

Penulis:ChaoZhang, Tanggal: 2024-01-26 16:04:26
Tag:

img

Gambaran umum

Strategi ini mengidentifikasi pola candlestick untuk melacak sinyal perdagangan dan menggabungkan mengambil keuntungan dan stop loss logika untuk perdagangan otomatis.

Logika Strategi

  1. Mengidentifikasi pola candlestick: Ketika ukuran tubuh lilin lebih kecil dari ambang batas dan terbuka sama dengan dekat, itu diidentifikasi sebagai sinyal pelacakan.

  2. Long/Short: Ketika pola candlestick pembalikan diidentifikasi, pergi panjang jika sebelumnya ditutup lebih tinggi dari 2 hari yang lalu, pergi pendek jika sebelumnya ditutup lebih rendah dari 2 hari yang lalu.

Keuntungan

  1. Mekanisme Take Profit/Stop Loss secara efektif mengendalikan risiko, mengunci keuntungan, menghindari peningkatan kerugian.

  2. Perdagangan otomatis tanpa intervensi manual mengurangi biaya perdagangan dan meningkatkan efisiensi.

Risiko

  1. Pengaturan titik take profit/stop loss yang tidak benar dapat melewatkan tren yang lebih besar atau stop loss yang prematur.

Arahan Optimasi

  1. Mengoptimalkan kondisi identifikasi candlestick dengan lebih banyak indikator untuk meningkatkan akurasi.

  2. Perkaya logika strategi dengan menambahkan algoritma untuk mengidentifikasi lebih banyak sinyal perdagangan.

Kesimpulan


/*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))


Lebih banyak