Tìm cơ hội cược BO với Trend line

Tìm cơ hội cược BO với Trend line

Tìm cơ hội cược BO với Trend line
@vĩnh0902 @Trương Nhật lúc nào rãnh thì add em indi Pre-H1 Fibo Line mình mới đăng ngoài kia vào chart, quan sát giá, demo lệnh nếu thích, và quan trọng nhất là đánh giá giúp mình xem nó có lợi thế gì để chúng ta khai thác không nhé, các ý tưởng hay mình mới code backtest, vì mấy nay mình khá bận nên cậy nhờ chất xám của anh em xíu nhé :D
hổm giờ vợ sanh nên tuần này không theo dõi đc, ae demo tiếp nhá. Xem lịch sử thì tuần này đang thử thách rồi :D
 
hổm giờ vợ sanh nên tuần này không theo dõi đc, ae demo tiếp nhá. Xem lịch sử thì tuần này đang thử thách rồi :D
Chúc mừng gia đình có thêm thành viên mới nhé :D
Có lịch sử để xem nó sướng ko nè, hihih, ko cần phải ngày nào cũng bám chart mới biết chuyện gì đã xảy ra :D
 
Mình quên chưa thêm dk là tất cả các TH thì adx phải lớn hơn 20 nhé
Như vậy setup trong ảnh minh họa của bạn vi phạm rule ADX>20 này rùi á :D
chrome_KgRAlvdwDP.png
 
@HangVu tặng bạn code DMI có ADX level để dễ tìm setup

Mã:
//@version = 4
study(title="DMI HangVu", overlay=false)
HVadxlen = input(14, title="HV ADX Smoothing")
HVdilen = input(14, title="HV DI Length")
HVadxlevel = input(20, title="HV ADX Level")
HVdirmov(HVlen) =>
    HVup = change(high)
    HVdown = -change(low)
    HVtruerange = rma(tr, HVlen)
    HVplus = fixnan(100 * rma(HVup > HVdown and HVup > 0 ? HVup : 0, HVlen) / HVtruerange)
    HVminus = fixnan(100 * rma(HVdown > HVup and HVdown > 0 ? HVdown : 0, HVlen) / HVtruerange)
    [HVplus, HVminus]

HVadx(HVdilen, HVadxlen) =>
    [HVplus, HVminus] = HVdirmov(HVdilen)
    HVsum = HVplus + HVminus
    HVadx = 100 * rma(abs(HVplus - HVminus) / (HVsum == 0 ? 1 : HVsum), HVadxlen)

HVadxHigh(HVdilen, HVadxlen) =>
    [HVplus, HVminus] = HVdirmov(HVdilen)
    HVplus
    
HVadxLow(HVdilen, HVadxlen) =>
    [HVplus, HVminus] = HVdirmov(HVdilen)
    HVminus
    
HVsig = HVadx(HVdilen, HVadxlen)
HVsigHigh = HVadxHigh(HVdilen, HVadxlen)
HVsigLow = HVadxLow(HVdilen, HVadxlen)

plot(HVsig, color=color.yellow, title="ADX", linewidth=2)
hline(HVadxlevel, color=color.olive, title="ADX Level")
plot(HVsigHigh, color=color.blue, title="DI+", linewidth=2)
plot(HVsigLow, color=color.red, title="DI-", linewidth=2)
 
@HangVu confirm lại ảnh minh họa Sell Th1 là ADX từ dưới đi lên cắt qua DI+ hay DI- nha. Trong ảnh minh họa theo mình nghĩ là nó cắt lên DI+ mà :D
Sell_th1.png
 
@HangVu về điều kiện của BB khi close hoặc H/L vượt band có xét đến điều kiện 2 bands bung ra hay không, hay chỉ cần vượt band là được?
 
@HangVu đây là Buy Th1 của bạn, adx>20 ko có setup nào nên mình tạm bỏ qua đk đó nhé :) Bạn cập nhật lại thông tin cho các ảnh minh họa mình đã hỏi bên trên để mình tiến hành code tiếp các Tr.hợp còn lại nha :D
chrome_WwJ0v7QhgY.png
 
Kết quả backtest Sell tr.h1 của bạn nè, sau khi backtest thì mới biết là rule bạn viết đúng, nhưng setup minh họa bạn tìm không chính xác
* Sai rule giống ảnh minh họa (adx cắt lên DI+)
01.png


* Đúng rule
02.png


* Đúng rule và adx<20
03.png


* Đúng rule và adx>20
04.png
 
@HangVu Sell trh2 cuar bạn, chỉ còn thiếu rule của buy trh2 thôi :)
* Không xét BB có bung bands hay không
CuRcnNbSA1.png


* BB bắt buộc phải bung bands
chrome_TgjvRf1JjG.png
 
hi, mình ghi nhầm đấy DI+
Nếu DI+ thì hiệu suất cực thấp nha. Adx là đường xác nhận trend, adx cắt lên DI+ nhưng thấp hơn DI- tức là trend giảm vẫn còn yếu đó, chỉ khi adx cắt lên DI- luôn thì trend giảm mới mạnh. Code xong rồi, để lát mình gửi, vâỵ sell trh1 này mình sẽ sửa lại cho đúng rule của bạn là DI+ nhé, hiệu suất nó thấp lắm í :)
 
@HangVu code backtest của bạn :)
Mã:
//@version=4
//BO Backtesting HangVu
//author: anhnguyen14

strategy(title="BO Backtesting HangVu", overlay=true, pyramiding=10)

// === INPUT BACKTEST RANGE ===
Date   = input(true, title = "=== Date Option ===")
FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
FromYear  = input(defval = 2019, title = "From Year", minval = 2017)

ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToYear    = input(defval = 9999, title = "To Year", minval = 2017)

// === DATE RANGE ===
start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start window
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        // backtest finish window
window()  => time >= start and time <= finish ? true : false // create function "within window of time"

// === Trading Time ===
CTimeDvM   = input(true, title = "=== Trading Time ===")
FromHourDvM   = input(defval = 05, title = "From Hour", minval = 00, maxval = 23)
FromMinuteDvM = input(defval = 00, title = "From Minute", minval = 00, maxval = 59)
ToHourDvM   = input(defval = 04, title = "To Hour", minval = 00, maxval = 23)
ToMinuteDvM = input(defval = 59, title = "To Minute", minval = 00, maxval = 59)
GMT_FHDvM=FromHourDvM<7?FromHourDvM-7+24:FromHourDvM-7
GMT_THDvM=ToHourDvM<7?ToHourDvM-7+24:ToHourDvM-7
fhDvM= (GMT_FHDvM<10?"0"+tostring(GMT_FHDvM):tostring(GMT_FHDvM))
fmDvM= (FromMinuteDvM<10?"0"+tostring(FromMinuteDvM):tostring(FromMinuteDvM))
thDvM= (GMT_THDvM<10?"0"+tostring(GMT_THDvM):tostring(GMT_THDvM))
tmDvM= (ToMinuteDvM<10?"0"+tostring(ToMinuteDvM):tostring(ToMinuteDvM))
WorkingHourDvM = fhDvM+fmDvM+"-"+thDvM+tmDvM
t0_DvM = time(timeframe.period, WorkingHourDvM)
//bgcolor(CTimeDvM? t0_DvM? color.gray : na:na, title="Trading Time", transp=90)
HVtt   = input(true, title = "=== HangVu Setup ===")
call1 = input(true, title = "1. Call Case 1")
call2 = input(true, title = "2. Call Case 2")
put1 = input(true, title = "3. Put Case 1")
put2 = input(true, title = "4. Put Case 2")
//Bollinger Bands - 20 - 2.0
BBHVlen = input(20, title="BBHV Periode")
BBHVmult = input(2.0, minval=0.001, maxval=5, title="BBHV Multip")
BBHVbasis = sma(close,BBHVlen)

BBHVdev = BBHVmult * stdev(close, BBHVlen)
BBHVupper = BBHVbasis + BBHVdev
BBHVlower = BBHVbasis - BBHVdev

//Bollinger BandWidth
BBHVbbw = (BBHVupper - BBHVlower) / BBHVbasis
//plot(BBHVbbw)

//Bollinger Bands %B
BBHVpB = (close - BBHVlower) / (BBHVupper - BBHVlower)
//plot(BBHVpB)

//plot Bollinger Bands
plot(BBHVbasis, title="BBHV Basis", linewidth=2, color=color.green, transp=0, linewidth=1)
BBHVpb3 = plot(BBHVupper, color=color.green, transp=0,title="BBHV Upper", linewidth=1)
BBHVpb4 = plot(BBHVlower, color=color.green, transp=0,title="BBHV Lower", linewidth=1)
fill(BBHVpb3, BBHVpb4, color=color.aqua,title="Bollinger Bands Background - HangVu",transp=80)

//DMI HangVu
HVadxlen = input(14, title="HV ADX Smoothing")
HVdilen = input(14, title="HV DI Length")
HVadxlevel = input(20, title="HV ADX Level")
HVdirmov(HVlen) =>
    HVup = change(high)
    HVdown = -change(low)
    HVtruerange = rma(tr, HVlen)
    HVplus = fixnan(100 * rma(HVup > HVdown and HVup > 0 ? HVup : 0, HVlen) / HVtruerange)
    HVminus = fixnan(100 * rma(HVdown > HVup and HVdown > 0 ? HVdown : 0, HVlen) / HVtruerange)
    [HVplus, HVminus]

HVadx(HVdilen, HVadxlen) =>
    [HVplus, HVminus] = HVdirmov(HVdilen)
    HVsum = HVplus + HVminus
    HVadx = 100 * rma(abs(HVplus - HVminus) / (HVsum == 0 ? 1 : HVsum), HVadxlen)

HVadxHigh(HVdilen, HVadxlen) =>
    [HVplus, HVminus] = HVdirmov(HVdilen)
    HVplus
   
HVadxLow(HVdilen, HVadxlen) =>
    [HVplus, HVminus] = HVdirmov(HVdilen)
    HVminus
   
HVsig = HVadx(HVdilen, HVadxlen)
HVsigHigh = HVadxHigh(HVdilen, HVadxlen)
HVsigLow = HVadxLow(HVdilen, HVadxlen)
adx=HVsig
dip=HVsigHigh
dim=HVsigLow

//plot(HVsig, color=color.yellow, title="ADX", linewidth=2)
//hline(HVadxlevel, color=color.olive, title="ADX Level")
//plot(HVsigHigh, color=color.blue, title="DI+", linewidth=2)
//plot(HVsigLow, color=color.red, title="DI-", linewidth=2)

//ADX Between DI+, DI-
adxBT =
       (adx>dip and adx<dim)
       or
       (adx<dip and adx>dim)

//DI+, DI- Cross
dicross =
       cross(dip,dim)
       or
       cross(dim,dip)


//Out the band
Outup =
       (close>BBHVupper
       or high>BBHVupper)
       //and BBHVbbw>BBHVbbw[1]
Outlow =
       (close<BBHVlower
       or low<BBHVlower)
       //and BBHVbbw>BBHVbbw[1]

//ADX down
adxDn =
       highest(adx,14)>20
       and adx[0]<20
     

//Case 1
//Put Condition
x1=
       put1?
       Outlow
       and adx[1]<adx[2]
       and dim[1]>dip[1]
       and dip[1]>adx[1]
       and crossover(adx,dip)
       :false

//Call Condition
y1=
       call1?
       barssince(dicross)>0 and barssince(dicross)<5
       and adxBT
       and crossover(close,BBHVbasis)
       :false

//Case 2
//Put Condition
x2=
       put2?
       Outlow
       and adxDn
       and crossover(dim,adx)
       and dim[1]>dip[1]
       and adx>adx[1]
       and BBHVbbw>BBHVbbw[1]
       :false

//Call Condition
y2=
       call2?
       Outup
       and adx>adx[1]
       and dip[1]>dim[1]
       and dim[1]>adx[1]
       and crossover(adx,dim)
       :false
     

// - /FUNCTIONS

xDvM=
       x1
       or x2
     
     

yDvM=
       y1
       or y2
     
     

//--------------------------------------\\

// - /FUNCTIONS

//--------------------------------------\\

// Alert
CputcolDvM = xDvM ? color.red : na
CcallcolDvM = yDvM ? color.blue : na
plotshape(CTimeDvM?t0_DvM?xDvM:na:na, title='Put', text="Put", style=shape.labeldown, location=location.bottom, color=color.orange, textcolor=color.black, offset=1, transp=0)
plotshape(CTimeDvM?t0_DvM?yDvM:na:na, title='Call', text="Call", style=shape.labelup, location=location.bottom, color=color.orange, textcolor=color.black, offset=1, transp=0)
bgcolor(CTimeDvM?t0_DvM?CputcolDvM:na:na, transp=50, offset=1, title="Put Signal")
bgcolor(CTimeDvM?t0_DvM?CcallcolDvM:na:na, transp=50, offset=1, title="Call Signal")

//Backtesting
if (CTimeDvM)
    strategy.entry("Call", strategy.long, when=yDvM and window() and t0_DvM)
if (CTimeDvM)
    strategy.entry("Put", strategy.short, when=xDvM and window() and t0_DvM)

strategy.close_all(when=barstate.isnew)
   
//EOF
 
@HangVu code backtest của bạn :)
Mã:
//@version=4
//BO Backtesting HangVu
//author: anhnguyen14

strategy(title="BO Backtesting HangVu", overlay=true, pyramiding=10)

// === INPUT BACKTEST RANGE ===
Date   = input(true, title = "=== Date Option ===")
FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
FromYear  = input(defval = 2019, title = "From Year", minval = 2017)

ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToYear    = input(defval = 9999, title = "To Year", minval = 2017)

// === DATE RANGE ===
start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start window
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        // backtest finish window
window()  => time >= start and time <= finish ? true : false // create function "within window of time"

// === Trading Time ===
CTimeDvM   = input(true, title = "=== Trading Time ===")
FromHourDvM   = input(defval = 05, title = "From Hour", minval = 00, maxval = 23)
FromMinuteDvM = input(defval = 00, title = "From Minute", minval = 00, maxval = 59)
ToHourDvM   = input(defval = 04, title = "To Hour", minval = 00, maxval = 23)
ToMinuteDvM = input(defval = 59, title = "To Minute", minval = 00, maxval = 59)
GMT_FHDvM=FromHourDvM<7?FromHourDvM-7+24:FromHourDvM-7
GMT_THDvM=ToHourDvM<7?ToHourDvM-7+24:ToHourDvM-7
fhDvM= (GMT_FHDvM<10?"0"+tostring(GMT_FHDvM):tostring(GMT_FHDvM))
fmDvM= (FromMinuteDvM<10?"0"+tostring(FromMinuteDvM):tostring(FromMinuteDvM))
thDvM= (GMT_THDvM<10?"0"+tostring(GMT_THDvM):tostring(GMT_THDvM))
tmDvM= (ToMinuteDvM<10?"0"+tostring(ToMinuteDvM):tostring(ToMinuteDvM))
WorkingHourDvM = fhDvM+fmDvM+"-"+thDvM+tmDvM
t0_DvM = time(timeframe.period, WorkingHourDvM)
//bgcolor(CTimeDvM? t0_DvM? color.gray : na:na, title="Trading Time", transp=90)
HVtt   = input(true, title = "=== HangVu Setup ===")
call1 = input(true, title = "1. Call Case 1")
call2 = input(true, title = "2. Call Case 2")
put1 = input(true, title = "3. Put Case 1")
put2 = input(true, title = "4. Put Case 2")
//Bollinger Bands - 20 - 2.0
BBHVlen = input(20, title="BBHV Periode")
BBHVmult = input(2.0, minval=0.001, maxval=5, title="BBHV Multip")
BBHVbasis = sma(close,BBHVlen)

BBHVdev = BBHVmult * stdev(close, BBHVlen)
BBHVupper = BBHVbasis + BBHVdev
BBHVlower = BBHVbasis - BBHVdev

//Bollinger BandWidth
BBHVbbw = (BBHVupper - BBHVlower) / BBHVbasis
//plot(BBHVbbw)

//Bollinger Bands %B
BBHVpB = (close - BBHVlower) / (BBHVupper - BBHVlower)
//plot(BBHVpB)

//plot Bollinger Bands
plot(BBHVbasis, title="BBHV Basis", linewidth=2, color=color.green, transp=0, linewidth=1)
BBHVpb3 = plot(BBHVupper, color=color.green, transp=0,title="BBHV Upper", linewidth=1)
BBHVpb4 = plot(BBHVlower, color=color.green, transp=0,title="BBHV Lower", linewidth=1)
fill(BBHVpb3, BBHVpb4, color=color.aqua,title="Bollinger Bands Background - HangVu",transp=80)

//DMI HangVu
HVadxlen = input(14, title="HV ADX Smoothing")
HVdilen = input(14, title="HV DI Length")
HVadxlevel = input(20, title="HV ADX Level")
HVdirmov(HVlen) =>
    HVup = change(high)
    HVdown = -change(low)
    HVtruerange = rma(tr, HVlen)
    HVplus = fixnan(100 * rma(HVup > HVdown and HVup > 0 ? HVup : 0, HVlen) / HVtruerange)
    HVminus = fixnan(100 * rma(HVdown > HVup and HVdown > 0 ? HVdown : 0, HVlen) / HVtruerange)
    [HVplus, HVminus]

HVadx(HVdilen, HVadxlen) =>
    [HVplus, HVminus] = HVdirmov(HVdilen)
    HVsum = HVplus + HVminus
    HVadx = 100 * rma(abs(HVplus - HVminus) / (HVsum == 0 ? 1 : HVsum), HVadxlen)

HVadxHigh(HVdilen, HVadxlen) =>
    [HVplus, HVminus] = HVdirmov(HVdilen)
    HVplus
  
HVadxLow(HVdilen, HVadxlen) =>
    [HVplus, HVminus] = HVdirmov(HVdilen)
    HVminus
  
HVsig = HVadx(HVdilen, HVadxlen)
HVsigHigh = HVadxHigh(HVdilen, HVadxlen)
HVsigLow = HVadxLow(HVdilen, HVadxlen)
adx=HVsig
dip=HVsigHigh
dim=HVsigLow

//plot(HVsig, color=color.yellow, title="ADX", linewidth=2)
//hline(HVadxlevel, color=color.olive, title="ADX Level")
//plot(HVsigHigh, color=color.blue, title="DI+", linewidth=2)
//plot(HVsigLow, color=color.red, title="DI-", linewidth=2)

//ADX Between DI+, DI-
adxBT =
       (adx>dip and adx<dim)
       or
       (adx<dip and adx>dim)

//DI+, DI- Cross
dicross =
       cross(dip,dim)
       or
       cross(dim,dip)


//Out the band
Outup =
       (close>BBHVupper
       or high>BBHVupper)
       //and BBHVbbw>BBHVbbw[1]
Outlow =
       (close<BBHVlower
       or low<BBHVlower)
       //and BBHVbbw>BBHVbbw[1]

//ADX down
adxDn =
       highest(adx,14)>20
       and adx[0]<20
    

//Case 1
//Put Condition
x1=
       put1?
       Outlow
       and adx[1]<adx[2]
       and dim[1]>dip[1]
       and dip[1]>adx[1]
       and crossover(adx,dip)
       :false

//Call Condition
y1=
       call1?
       barssince(dicross)>0 and barssince(dicross)<5
       and adxBT
       and crossover(close,BBHVbasis)
       :false

//Case 2
//Put Condition
x2=
       put2?
       Outlow
       and adxDn
       and crossover(dim,adx)
       and dim[1]>dip[1]
       and adx>adx[1]
       and BBHVbbw>BBHVbbw[1]
       :false

//Call Condition
y2=
       call2?
       Outup
       and adx>adx[1]
       and dip[1]>dim[1]
       and dim[1]>adx[1]
       and crossover(adx,dim)
       :false
    

// - /FUNCTIONS

xDvM=
       x1
       or x2
    
    

yDvM=
       y1
       or y2
    
    

//--------------------------------------\\

// - /FUNCTIONS

//--------------------------------------\\

// Alert
CputcolDvM = xDvM ? color.red : na
CcallcolDvM = yDvM ? color.blue : na
plotshape(CTimeDvM?t0_DvM?xDvM:na:na, title='Put', text="Put", style=shape.labeldown, location=location.bottom, color=color.orange, textcolor=color.black, offset=1, transp=0)
plotshape(CTimeDvM?t0_DvM?yDvM:na:na, title='Call', text="Call", style=shape.labelup, location=location.bottom, color=color.orange, textcolor=color.black, offset=1, transp=0)
bgcolor(CTimeDvM?t0_DvM?CputcolDvM:na:na, transp=50, offset=1, title="Put Signal")
bgcolor(CTimeDvM?t0_DvM?CcallcolDvM:na:na, transp=50, offset=1, title="Call Signal")

//Backtesting
if (CTimeDvM)
    strategy.entry("Call", strategy.long, when=yDvM and window() and t0_DvM)
if (CTimeDvM)
    strategy.entry("Put", strategy.short, when=xDvM and window() and t0_DvM)

strategy.close_all(when=barstate.isnew)
  
//EOF
đúng là từ quan sát mắt thường, đến đưa vào lập trình nó khác nhau 1 trời, 1 vực. Tôi vẫn thường trade bằng tay, theo pp này. ko thắng tuyệt đối, nhưng vẫn tạm ổn. Và tôi nhận thấy trade theo pp này còn phụ thuộc khá nhiều vào tổng quan của chart khi đó, quan sát xem chart đang khu vực nào trend ra sao?
 
đúng là từ quan sát mắt thường, đến đưa vào lập trình nó khác nhau 1 trời, 1 vực. Tôi vẫn thường trade bằng tay, theo pp này. ko thắng tuyệt đối, nhưng vẫn tạm ổn. Và tôi nhận thấy trade theo pp này còn phụ thuộc khá nhiều vào tổng quan của chart khi đó, quan sát xem chart đang khu vực nào trend ra sao?
Cảm ơn bạn @anhnguyen14 nhiều nha
 
Cảm ơn bạn @anhnguyen14 nhiều nha
Haizz, không có gì mà, mình là một lão sói cô độc đi săn ý tưởng mà thôi :)
Trong thị trường tài chính thì khối lượng giao dịch volume là chúa tể, BO cũng không ngoại lệ, nếu đam mê, bạn nên tiếp tục nghiên cứu về volume. Trên tradingview hiện có duy nhất 1 chỉ báo khối lượng theo giá là VPRVN, nó là chỉ báo cực kỳ mạnh mẽ. Nhưng tác giả đã khoá code, chỉ cho dùng chứ ko cho xem code, họ phòng hờ những con sói lang thang săn code như mình, khả năng của mình thì chưa viết đc chỉ báo này nên chưa thể code backtest đc :)
 

BÌNH LUẬN MỚI NHẤT

AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

Back
Bên trên