anhnguyen14
Active Member
- 14,901
- 17,796
// BO - Woodies CCI - Backtesting
//anch.v43
// © inno14
//@version=4
strategy("BO - Woodies CCI - Backtesting", pyramiding=0)
// === INPUT PERIOD OF TIME ===
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 = 2020, 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 ===")
Time_zone = input(7,title="Time Zone")
FromHourDvM = input(defval = 07, title = "From Hour", minval = 00, maxval = 23)
FromMinuteDvM = input(defval = 00, title = "From Minute", minval = 00, maxval = 59)
ToHourDvM = input(defval = 18, title = "To Hour", minval = 00, maxval = 23)
ToMinuteDvM = input(defval = 00, title = "To Minute", minval = 00, maxval = 59)
GMT_FHDvM=FromHourDvM<Time_zone?FromHourDvM-Time_zone+24:FromHourDvM-Time_zone
GMT_THDvM=ToHourDvM<Time_zone?ToHourDvM-Time_zone+24:ToHourDvM-Time_zone
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)
htrtime = input(true,title="Highlight Trading Time")
bgcolor(htrtime? t0_DvM? color.gray : na:na, title="Trading Time", transp=90)
//Woodies CCI
cciTurboLength = input(title="CCI Turbo Length", type=input.integer, defval=6, minval=3, maxval=14)
cci14Length = input(title="CCI 14 Length", type=input.integer, defval=14, minval=7, maxval=20)
source = close
cciTurbo = cci(source, cciTurboLength)
cci14 = cci(source, cci14Length)
last5IsDown = cci14[5] < 0 and cci14[4] < 0 and cci14[3] < 0 and cci14[2] < 0 and cci14[1] < 0
last5IsUp = cci14[5] > 0 and cci14[4] > 0 and cci14[3] > 0 and cci14[2] > 0 and cci14[1] > 0
histogramColor = last5IsUp ? color.green : last5IsDown ? color.red : cci14 < 0 ? color.gray : color.gray
//Plot Woodies CCI
plot(cci14, title="CCI Histogram", color=histogramColor, style=plot.style_histogram, linewidth=2, transp=40)
plot(0, title="Zero Line", color=cciTurbo>100?color.blue:cciTurbo<-100?color.red:color.navy, style=plot.style_line, linewidth=6, transp=20)
hline(200, title="Hundred Line", color=color.black, linestyle=hline.style_dotted)
hline(-200, title="Minus Line", color=color.black, linestyle=hline.style_dotted)
//Plot lingreg CCI14
linreg_cci14=linreg(cci14, 5, 0)
plot(linreg_cci14, color=color.aqua, linewidth=4)
//peak & top
peak_cci= linreg_cci14[2]>linreg_cci14[3] and linreg_cci14[1]>linreg_cci14[2] and linreg_cci14[0]<linreg_cci14[1] and linreg_cci14[0]>0
bott_cci= linreg_cci14[2]<linreg_cci14[3] and linreg_cci14[1]<linreg_cci14[2] and linreg_cci14[0]>linreg_cci14[1] and linreg_cci14[0]<0
peak_cci_1= linreg_cci14[2]>linreg_cci14[3] and linreg_cci14[1]>linreg_cci14[2] and linreg_cci14[0]<linreg_cci14[1]
bott_cci_1= linreg_cci14[2]<linreg_cci14[3] and linreg_cci14[1]<linreg_cci14[2] and linreg_cci14[0]>linreg_cci14[1]
//
fil_len=input(6,title="Filter Length")
top_ext=highest(linreg_cci14,fil_len)
bot_ext=lowest(linreg_cci14,fil_len)
//Put signal
x1=
peak_cci
and cci14[0]>cciTurbo[0]
and cciTurbo[0]>60
and linreg_cci14[1]==top_ext[1]
and valuewhen(bott_cci_1,linreg_cci14[1],0)>=0
//Call signal
y1=
bott_cci
and cci14[0]<cciTurbo[0]
and cciTurbo[0]<-60
and linreg_cci14[1]==bot_ext[1]
and valuewhen(peak_cci_1,linreg_cci14[1],0)<=0
no_orders =
not x1[1]
and not x1[2]
and not x1[3]
and not x1[4]
and not x1[5]
and not y1[1]
and not y1[2]
and not y1[3]
and not y1[4]
and not y1[5]
//Function
xTech=
x1 and no_orders
yTech=
y1 and no_orders
//Plot Analyzing Signals
//hline1=hline(-1.2*300)
hline2=hline(-1.6*300)
hline0=hline(0)
sigtext=
xTech?"Put signal":yTech?"Call signal":
"Backtesting From: "+tostring(FromDay)+"/"+tostring(FromMonth)+"/"+tostring(FromYear)+" To: "+tostring(ToDay)+"/"+tostring(ToMonth)+"/"+tostring(ToYear)
+ " * Trading Time From: "+tostring(FromHourDvM)+":"+tostring(FromMinuteDvM)+" To "+tostring(ToHourDvM)+":"+tostring(ToMinuteDvM)
sig_col=xTech?color.new(color.red,10):yTech?color.new(color.blue,10):color.new(color.navy,10)
label_sig_text = label.new(bar_index[0], -1.5*300, text=sigtext, style=label.style_none, textcolor=sig_col, size=size.large)
label.delete(label_sig_text[1])
//plot Signal
putcol = xTech? color.red : na
callcol = yTech? color.blue : na
PutSignal= xTech and window() and t0_DvM?-1.2*300:na
CallSignal= yTech and window() and t0_DvM?-1.2*300:na
//plot(PutSignal, title='Put Signal', style=plot.style_columns, color=color.red, offset=1, transp=0)
//plot(CallSignal, title='Call Signal', style=plot.style_columns, color=color.blue, offset=1, transp=0)
plotshape(PutSignal, title='Put', text="Put", style=shape.circle, location=location.absolute, color=color.red, textcolor=color.black, offset=1, transp=0, size=size.large)
plotshape(CallSignal, title='Call', text="Call", style=shape.circle, location=location.absolute, color=color.blue, textcolor=color.black, offset=1, transp=0, size=size.large)
//plotchar(PutSignal, title='Put', char="◉", text="Put", location=location.absolute, color=color.red, textcolor=color.black, offset=1, transp=0, size=size.small)
//plotchar(CallSignal, title='Call', char="◉", text="Call", location=location.absolute, color=color.blue, textcolor=color.black, offset=1, transp=0, size=size.small)
//Backtesting
strategy.entry("Call", strategy.long, when=yTech and window() and t0_DvM)
strategy.entry("Put", strategy.short, when=xTech and window() and t0_DvM)
//strategy.close_all(when=barstate.isnew)
strategy.close_all(when=barssince(xTech)==6 or barssince(yTech)==6)
//EOF
@vĩnh0902 @Trương Nhật vẫn là con hàng Woddies CCI, chạy con EJ. Mỗi ngày 1 lệnh
View attachment 136382
Mã:// BO - Woodies CCI - Backtesting //anch.v43 // © inno14 //@version=4 strategy("BO - Woodies CCI - Backtesting", pyramiding=0) // === INPUT PERIOD OF TIME === 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 = 2020, 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 ===") Time_zone = input(7,title="Time Zone") FromHourDvM = input(defval = 07, title = "From Hour", minval = 00, maxval = 23) FromMinuteDvM = input(defval = 00, title = "From Minute", minval = 00, maxval = 59) ToHourDvM = input(defval = 18, title = "To Hour", minval = 00, maxval = 23) ToMinuteDvM = input(defval = 00, title = "To Minute", minval = 00, maxval = 59) GMT_FHDvM=FromHourDvM<Time_zone?FromHourDvM-Time_zone+24:FromHourDvM-Time_zone GMT_THDvM=ToHourDvM<Time_zone?ToHourDvM-Time_zone+24:ToHourDvM-Time_zone 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) htrtime = input(true,title="Highlight Trading Time") bgcolor(htrtime? t0_DvM? color.gray : na:na, title="Trading Time", transp=90) //Woodies CCI cciTurboLength = input(title="CCI Turbo Length", type=input.integer, defval=6, minval=3, maxval=14) cci14Length = input(title="CCI 14 Length", type=input.integer, defval=14, minval=7, maxval=20) source = close cciTurbo = cci(source, cciTurboLength) cci14 = cci(source, cci14Length) last5IsDown = cci14[5] < 0 and cci14[4] < 0 and cci14[3] < 0 and cci14[2] < 0 and cci14[1] < 0 last5IsUp = cci14[5] > 0 and cci14[4] > 0 and cci14[3] > 0 and cci14[2] > 0 and cci14[1] > 0 histogramColor = last5IsUp ? color.green : last5IsDown ? color.red : cci14 < 0 ? color.gray : color.gray //Plot Woodies CCI plot(cci14, title="CCI Histogram", color=histogramColor, style=plot.style_histogram, linewidth=2, transp=40) plot(0, title="Zero Line", color=cciTurbo>100?color.blue:cciTurbo<-100?color.red:color.navy, style=plot.style_line, linewidth=6, transp=20) hline(200, title="Hundred Line", color=color.black, linestyle=hline.style_dotted) hline(-200, title="Minus Line", color=color.black, linestyle=hline.style_dotted) //Plot lingreg CCI14 linreg_cci14=linreg(cci14, 5, 0) plot(linreg_cci14, color=color.aqua, linewidth=4) //peak & top peak_cci= linreg_cci14[2]>linreg_cci14[3] and linreg_cci14[1]>linreg_cci14[2] and linreg_cci14[0]<linreg_cci14[1] and linreg_cci14[0]>0 bott_cci= linreg_cci14[2]<linreg_cci14[3] and linreg_cci14[1]<linreg_cci14[2] and linreg_cci14[0]>linreg_cci14[1] and linreg_cci14[0]<0 peak_cci_1= linreg_cci14[2]>linreg_cci14[3] and linreg_cci14[1]>linreg_cci14[2] and linreg_cci14[0]<linreg_cci14[1] bott_cci_1= linreg_cci14[2]<linreg_cci14[3] and linreg_cci14[1]<linreg_cci14[2] and linreg_cci14[0]>linreg_cci14[1] // fil_len=input(6,title="Filter Length") top_ext=highest(linreg_cci14,fil_len) bot_ext=lowest(linreg_cci14,fil_len) //Put signal x1= peak_cci and cci14[0]>cciTurbo[0] and cciTurbo[0]>60 and linreg_cci14[1]==top_ext[1] and valuewhen(bott_cci_1,linreg_cci14[1],0)>=0 //Call signal y1= bott_cci and cci14[0]<cciTurbo[0] and cciTurbo[0]<-60 and linreg_cci14[1]==bot_ext[1] and valuewhen(peak_cci_1,linreg_cci14[1],0)<=0 no_orders = not x1[1] and not x1[2] and not x1[3] and not x1[4] and not x1[5] and not y1[1] and not y1[2] and not y1[3] and not y1[4] and not y1[5] //Function xTech= x1 and no_orders yTech= y1 and no_orders //Plot Analyzing Signals //hline1=hline(-1.2*300) hline2=hline(-1.6*300) hline0=hline(0) sigtext= xTech?"Put signal":yTech?"Call signal": "Backtesting From: "+tostring(FromDay)+"/"+tostring(FromMonth)+"/"+tostring(FromYear)+" To: "+tostring(ToDay)+"/"+tostring(ToMonth)+"/"+tostring(ToYear) + " * Trading Time From: "+tostring(FromHourDvM)+":"+tostring(FromMinuteDvM)+" To "+tostring(ToHourDvM)+":"+tostring(ToMinuteDvM) sig_col=xTech?color.new(color.red,10):yTech?color.new(color.blue,10):color.new(color.navy,10) label_sig_text = label.new(bar_index[0], -1.5*300, text=sigtext, style=label.style_none, textcolor=sig_col, size=size.large) label.delete(label_sig_text[1]) //plot Signal putcol = xTech? color.red : na callcol = yTech? color.blue : na PutSignal= xTech and window() and t0_DvM?-1.2*300:na CallSignal= yTech and window() and t0_DvM?-1.2*300:na //plot(PutSignal, title='Put Signal', style=plot.style_columns, color=color.red, offset=1, transp=0) //plot(CallSignal, title='Call Signal', style=plot.style_columns, color=color.blue, offset=1, transp=0) plotshape(PutSignal, title='Put', text="Put", style=shape.circle, location=location.absolute, color=color.red, textcolor=color.black, offset=1, transp=0, size=size.large) plotshape(CallSignal, title='Call', text="Call", style=shape.circle, location=location.absolute, color=color.blue, textcolor=color.black, offset=1, transp=0, size=size.large) //plotchar(PutSignal, title='Put', char="◉", text="Put", location=location.absolute, color=color.red, textcolor=color.black, offset=1, transp=0, size=size.small) //plotchar(CallSignal, title='Call', char="◉", text="Call", location=location.absolute, color=color.blue, textcolor=color.black, offset=1, transp=0, size=size.small) //Backtesting strategy.entry("Call", strategy.long, when=yTech and window() and t0_DvM) strategy.entry("Put", strategy.short, when=xTech and window() and t0_DvM) //strategy.close_all(when=barstate.isnew) strategy.close_all(when=barssince(xTech)==6 or barssince(yTech)==6) //EOF
Tks, hiệu suất là ưu tiên, kiên nhẫn quyết định sự thành bại, lệnh ít nhưng chất vẫn hơnmình có mò 1 tí để nâng hiệu suất của 2 tháng lên
View attachment 136441
đúng rồi bác ạ, hiệu suất cao 1 tí cũng đở hơn, mà bác pro quá. Code càng ngày càng xịnTks, hiệu suất là ưu tiên, kiên nhẫn quyết định sự thành bại, lệnh ít nhưng chất vẫn hơn
Trình code mình tàm tạm rùi, đang code cái script tính hiệu suất dựa vào stoploss và takeprofit cho BO đây keke, 3win take profit, 2 loss stoplossđúng rồi bác ạ, hiệu suất cao 1 tí cũng đở hơn, mà bác pro quá. Code càng ngày càng xịn
ua, mà bác ra nhiều code, ko có thời gian demo và cảm nhận đủ dài. Mình nghĩ vậy cũng chưa hẵn là tốt.Trình code mình tàm tạm rùi, đang code cái script tính hiệu suất dựa vào stoploss và takeprofit cho BO đây keke, 3win take profit, 2 loss stoploss
Ặc, mình là coder mà, có phải trader đâu, cảm nhận thì mỗi trader sử dụng có cảm nhận thế nào, phản hồi lại thì coder mới cải tiến sản phẩm được chứ, hihih Coder mà ko ra code thì treo bàn phím luôn íua, mà bác ra nhiều code, ko có thời gian demo và cảm nhận đủ dài. Mình nghĩ vậy cũng chưa hẵn là tốt.
ua, cũng đúng. Hehe vậy để mình phản hồi vậy, qua nay không thấy bác @vĩnh0902Ặc, mình là coder mà, có phải trader đâu, cảm nhận thì mỗi trader sử dụng có cảm nhận thế nào, phản hồi lại thì coder mới cải tiến sản phẩm được chứ, hihih Coder mà ko ra code thì treo bàn phím luôn í
Chắc bạn í đi công tác rùi, chỉ báo bửa giờ code nhìu rùi, sản phẩm lần này sẽ thiên về quản lý vốn, người dùng sẽ nhập stoploss và takeprofit trong ngày, chạm 2 ngưỡng này thì hệ thống sẽ ko xuất tín hiệu nữa, và thống kê được hiệu suất quá khứ cho từng giá trị stoploss và takeprofit. Ý tưởng là vậy, còn sản phẩm thì ko biết viết nổi ko, kakaua, cũng đúng. Hehe vậy để mình phản hồi vậy, qua nay không thấy bác @vĩnh0902
hjhj mong bác sớm chia sẻ sản phẩm nè keke chứ e cứ ngồi nhìn chart là ngứa tay .Chắc bạn í đi công tác rùi, chỉ báo bửa giờ code nhìu rùi, sản phẩm lần này sẽ thiên về quản lý vốn, người dùng sẽ nhập stoploss và takeprofit trong ngày, chạm 2 ngưỡng này thì hệ thống sẽ ko xuất tín hiệu nữa, và thống kê được hiệu suất quá khứ cho từng giá trị stoploss và takeprofit. Ý tưởng là vậy, còn sản phẩm thì ko biết viết nổi ko, kaka
Code được cái stoploss với takeprofit theo số trade thắng thua trong ngày rùi, nhưng chưa tìm được rule ngon để gắn vào, đánh kiểu này thì cần chuỗi thắng dài nếu đoán đúng, và chuỗi thua cũng phải dài nếu đoán sai, lúc đó thì nếu đoán sai sẽ cắt được dây bệt lỗ, nếu đoán đúng thì sẽ nối dài chuỗi win, vẫn chưa tìm ra rule nào như thếhjhj mong bác sớm chia sẻ sản phẩm nè keke chứ e cứ ngồi nhìn chart là ngứa tay .
Code được cái stoploss với takeprofit theo số trade thắng thua trong ngày rùi, nhưng chưa tìm được rule ngon để gắn vào, đánh kiểu này thì cần chuỗi thắng dài nếu đoán đúng, và chuỗi thua cũng phải dài nếu đoán sai, lúc đó thì nếu đoán sai sẽ cắt được dây bệt lỗ, nếu đoán đúng thì sẽ nối dài chuỗi win, vẫn chưa tìm ra rule nào như thế
// BO - Woodies CCI - Backtesting
//anch.v43
// © inno14
//@version=4
strategy("BO - Woodies CCI - Backtesting")
//strategy.risk.max_intraday_loss(1, strategy.cash)
// === INPUT PERIOD OF TIME ===
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 = 2020, 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 ===")
Time_zone = input(7,title="Time Zone")
FromHourDvM = input(defval = 07, title = "From Hour", minval = 00, maxval = 23)
FromMinuteDvM = input(defval = 00, title = "From Minute", minval = 00, maxval = 59)
ToHourDvM = input(defval = 18, title = "To Hour", minval = 00, maxval = 23)
ToMinuteDvM = input(defval = 00, title = "To Minute", minval = 00, maxval = 59)
GMT_FHDvM=FromHourDvM<Time_zone?FromHourDvM-Time_zone+24:FromHourDvM-Time_zone
GMT_THDvM=ToHourDvM<Time_zone?ToHourDvM-Time_zone+24:ToHourDvM-Time_zone
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)
htrtime = input(true,title="Highlight Trading Time")
bgcolor(htrtime? t0_DvM? color.gray : na:na, title="Trading Time", transp=90)
//
fh_ott= (GMT_FHDvM<10?"0"+tostring(GMT_FHDvM):tostring(GMT_FHDvM))
fm_ott= (FromMinuteDvM<10?"0"+tostring(FromMinuteDvM):tostring(FromMinuteDvM))
th_ott= fh_ott
tm_ott= (FromMinuteDvM+5<10?"0"+tostring(FromMinuteDvM+5):tostring(FromMinuteDvM+5))
trading_time_open = fh_ott+fm_ott+"-"+th_ott+tm_ott
t1 = time(timeframe.period, trading_time_open)
//Woodies CCI
cciTurboLength = input(title="CCI Turbo Length", type=input.integer, defval=6, minval=3, maxval=1400)
cci14Length = input(title="CCI 14 Length", type=input.integer, defval=14, minval=7, maxval=2000)
source = close
cciTurbo = cci(source, cciTurboLength)
cci14 = cci(source, cci14Length)
last5IsDown = cci14[5] < 0 and cci14[4] < 0 and cci14[3] < 0 and cci14[2] < 0 and cci14[1] < 0
last5IsUp = cci14[5] > 0 and cci14[4] > 0 and cci14[3] > 0 and cci14[2] > 0 and cci14[1] > 0
histogramColor = last5IsUp ? color.green : last5IsDown ? color.red : cci14 < 0 ? color.gray : color.gray
//Plot Woodies CCI
plot(cci14, title="CCI Histogram", color=histogramColor, style=plot.style_histogram, linewidth=2, transp=40)
plot(0, title="Zero Line", color=cciTurbo>100?color.blue:cciTurbo<-100?color.red:color.navy, style=plot.style_line, linewidth=6, transp=20)
hline(200, title="Hundred Line", color=color.black, linestyle=hline.style_dotted)
hline(-200, title="Minus Line", color=color.black, linestyle=hline.style_dotted)
//Plot lingreg CCI14
linreg_cci14=linreg(cci14, 5, 0)
plot(linreg_cci14, color=color.aqua, linewidth=4)
//peak & top
peak_cci= linreg_cci14[2]>linreg_cci14[3] and linreg_cci14[1]>linreg_cci14[2] and linreg_cci14[0]<linreg_cci14[1] and linreg_cci14[1]>150
bott_cci= linreg_cci14[2]<linreg_cci14[3] and linreg_cci14[1]<linreg_cci14[2] and linreg_cci14[0]>linreg_cci14[1] and linreg_cci14[1]<-150
peak_cci_1= linreg_cci14[2]>linreg_cci14[3] and linreg_cci14[1]>linreg_cci14[2] and linreg_cci14[0]<linreg_cci14[1]
bott_cci_1= linreg_cci14[2]<linreg_cci14[3] and linreg_cci14[1]<linreg_cci14[2] and linreg_cci14[0]>linreg_cci14[1]
//
fil_len=input(6,title="Filter Length")
top_ext=highest(linreg_cci14,fil_len)
bot_ext=lowest(linreg_cci14,fil_len)
//Put signal
x1=
peak_cci
and linreg_cci14[1]==top_ext[1]
and linreg_cci14[1]>valuewhen(peak_cci_1,linreg_cci14[1],1)
and close>low[1]
and cciTurbo<100
and cci14<linreg_cci14
//Call signal
y1=
bott_cci
and linreg_cci14[1]==bot_ext[1]
and linreg_cci14[1]<valuewhen(bott_cci_1,linreg_cci14[1],1)
and close<high[1]
and cciTurbo>-100
and cci14>linreg_cci14
no_orders =
not x1[1]
and not x1[2]
and not x1[3]
and not x1[4]
and not x1[5]
and not y1[1]
and not y1[2]
and not y1[3]
and not y1[4]
and not y1[5]
//Stoploss
stop_tt=input(true,"Stoploss Option By Loss Trades")
stop_val=input(2,"Number of loss trades")
stop_loss=strategy.losstrades-strategy.losstrades[barssince(t1)]==stop_val
//Function
xTech=
x1
and no_orders
and not stop_loss
yTech=
y1
and no_orders
and not stop_loss
//Plot Analyzing Signals
//hline1=hline(-1.2*300)
hline2=hline(-1.6*300)
hline0=hline(0)
sigtext=
xTech?"Put signal":yTech?"Call signal":
"Backtesting From: "+tostring(FromDay)+"/"+tostring(FromMonth)+"/"+tostring(FromYear)+" To: "+tostring(ToDay)+"/"+tostring(ToMonth)+"/"+tostring(ToYear)
+ " * Trading Time From: "+tostring(FromHourDvM)+":"+tostring(FromMinuteDvM)+" To "+tostring(ToHourDvM)+":"+tostring(ToMinuteDvM)
sig_col=xTech?color.new(color.red,10):yTech?color.new(color.blue,10):color.new(color.navy,10)
label_sig_text = label.new(bar_index[0], -1.5*300, text=sigtext, style=label.style_none, textcolor=sig_col, size=size.large)
label.delete(label_sig_text[1])
//plot Signal
putcol = xTech? color.red : na
callcol = yTech? color.blue : na
PutSignal= xTech and window() and t0_DvM?-1.2*300:na
CallSignal= yTech and window() and t0_DvM?-1.2*300:na
//plot(PutSignal, title='Put Signal', style=plot.style_columns, color=color.red, offset=1, transp=0)
//plot(CallSignal, title='Call Signal', style=plot.style_columns, color=color.blue, offset=1, transp=0)
plotshape(PutSignal, title='Put', text="Put", style=shape.circle, location=location.absolute, color=color.red, textcolor=color.black, offset=1, transp=0, size=size.large)
plotshape(CallSignal, title='Call', text="Call", style=shape.circle, location=location.absolute, color=color.blue, textcolor=color.black, offset=1, transp=0, size=size.large)
//plotchar(PutSignal, title='Put', char="◉", text="Put", location=location.absolute, color=color.red, textcolor=color.black, offset=1, transp=0, size=size.small)
//plotchar(CallSignal, title='Call', char="◉", text="Call", location=location.absolute, color=color.blue, textcolor=color.black, offset=1, transp=0, size=size.small)
//Backtesting
strategy.entry("Call", strategy.long, when=yTech and window() and t0_DvM)
strategy.entry("Put", strategy.short, when=xTech and window() and t0_DvM)
strategy.close_all(when=barssince(xTech)==6 or barssince(yTech)==6)
//EOF
// BO - Woodies CCI - Backtesting
//anch.v43
// © inno14
//@version=4
strategy("BO - Woodies CCI - Backtesting")
//strategy.risk.max_intraday_loss(1, strategy.cash)
// === INPUT PERIOD OF TIME ===
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 = 2020, 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 ===")
Time_zone = input(7,title="Time Zone")
FromHourDvM = input(defval = 07, title = "From Hour", minval = 00, maxval = 23)
FromMinuteDvM = input(defval = 00, title = "From Minute", minval = 00, maxval = 59)
ToHourDvM = input(defval = 18, title = "To Hour", minval = 00, maxval = 23)
ToMinuteDvM = input(defval = 00, title = "To Minute", minval = 00, maxval = 59)
GMT_FHDvM=FromHourDvM<Time_zone?FromHourDvM-Time_zone+24:FromHourDvM-Time_zone
GMT_THDvM=ToHourDvM<Time_zone?ToHourDvM-Time_zone+24:ToHourDvM-Time_zone
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)
htrtime = input(true,title="Highlight Trading Time")
bgcolor(htrtime? t0_DvM? color.gray : na:na, title="Trading Time", transp=90)
//
fh_ott= (GMT_FHDvM<10?"0"+tostring(GMT_FHDvM):tostring(GMT_FHDvM))
fm_ott= (FromMinuteDvM<10?"0"+tostring(FromMinuteDvM):tostring(FromMinuteDvM))
th_ott= fh_ott
tm_ott= (FromMinuteDvM+5<10?"0"+tostring(FromMinuteDvM+5):tostring(FromMinuteDvM+5))
trading_time_open = fh_ott+fm_ott+"-"+th_ott+tm_ott
t1 = time(timeframe.period, trading_time_open)
//Woodies CCI
cciTurboLength = input(title="CCI Turbo Length", type=input.integer, defval=6, minval=3, maxval=1400)
cci14Length = input(title="CCI 14 Length", type=input.integer, defval=14, minval=7, maxval=2000)
source = close
cciTurbo = cci(source, cciTurboLength)
cci14 = cci(source, cci14Length)
last5IsDown = cci14[5] < 0 and cci14[4] < 0 and cci14[3] < 0 and cci14[2] < 0 and cci14[1] < 0
last5IsUp = cci14[5] > 0 and cci14[4] > 0 and cci14[3] > 0 and cci14[2] > 0 and cci14[1] > 0
histogramColor = last5IsUp ? color.green : last5IsDown ? color.red : cci14 < 0 ? color.gray : color.gray
//Plot Woodies CCI
plot(cci14, title="CCI Histogram", color=histogramColor, style=plot.style_histogram, linewidth=2, transp=40)
plot(0, title="Zero Line", color=cciTurbo>100?color.blue:cciTurbo<-100?color.red:color.navy, style=plot.style_line, linewidth=6, transp=20)
hline(200, title="Hundred Line", color=color.black, linestyle=hline.style_dotted)
hline(-200, title="Minus Line", color=color.black, linestyle=hline.style_dotted)
//Plot lingreg CCI14
linreg_cci14=linreg(cci14, 5, 0)
plot(linreg_cci14, color=color.aqua, linewidth=4)
//peak & top
peak_cci= linreg_cci14[2]>linreg_cci14[3] and linreg_cci14[1]>linreg_cci14[2] and linreg_cci14[0]<linreg_cci14[1] and linreg_cci14[1]>150
bott_cci= linreg_cci14[2]<linreg_cci14[3] and linreg_cci14[1]<linreg_cci14[2] and linreg_cci14[0]>linreg_cci14[1] and linreg_cci14[1]<-150
peak_cci_1= linreg_cci14[2]>linreg_cci14[3] and linreg_cci14[1]>linreg_cci14[2] and linreg_cci14[0]<linreg_cci14[1]
bott_cci_1= linreg_cci14[2]<linreg_cci14[3] and linreg_cci14[1]<linreg_cci14[2] and linreg_cci14[0]>linreg_cci14[1]
//
fil_len=input(6,title="Filter Length")
top_ext=highest(linreg_cci14,fil_len)
bot_ext=lowest(linreg_cci14,fil_len)
//Put signal
x1=
peak_cci
and linreg_cci14[1]==top_ext[1]
and linreg_cci14[1]>valuewhen(peak_cci_1,linreg_cci14[1],1)
and close>low[1]
and cciTurbo<100
and cci14<linreg_cci14
//Call signal
y1=
bott_cci
and linreg_cci14[1]==bot_ext[1]
and linreg_cci14[1]<valuewhen(bott_cci_1,linreg_cci14[1],1)
and close<high[1]
and cciTurbo>-100
and cci14>linreg_cci14
no_orders =
not x1[1]
and not x1[2]
and not x1[3]
and not x1[4]
and not x1[5]
and not y1[1]
and not y1[2]
and not y1[3]
and not y1[4]
and not y1[5]
//Stoploss
stop_tt=input(true,"Stoploss Option By Loss Trades")
stop_val=input(1,"Number of loss trades")
stop_loss=strategy.losstrades-strategy.losstrades[barssince(t1)]==stop_val
//Function
xTech=
x1
and no_orders
and not stop_loss
yTech=
y1
and no_orders
and not stop_loss
//Plot Analyzing Signals
//hline1=hline(-1.2*300)
hline2=hline(-1.6*300)
hline0=hline(0)
sigtext=
xTech?"Put signal":yTech?"Call signal":
"Backtesting From: "+tostring(FromDay)+"/"+tostring(FromMonth)+"/"+tostring(FromYear)+" To: "+tostring(ToDay)+"/"+tostring(ToMonth)+"/"+tostring(ToYear)
+ " * Trading Time From: "+tostring(FromHourDvM)+":"+tostring(FromMinuteDvM)+" To "+tostring(ToHourDvM)+":"+tostring(ToMinuteDvM)
sig_col=xTech?color.new(color.red,10):yTech?color.new(color.blue,10):color.new(color.navy,10)
label_sig_text = label.new(bar_index[0], -1.5*300, text=sigtext, style=label.style_none, textcolor=sig_col, size=size.large)
label.delete(label_sig_text[1])
//plot Signal
putcol = xTech? color.red : na
callcol = yTech? color.blue : na
PutSignal= xTech and window() and t0_DvM?-1.2*300:na
CallSignal= yTech and window() and t0_DvM?-1.2*300:na
//plot(PutSignal, title='Put Signal', style=plot.style_columns, color=color.red, offset=1, transp=0)
//plot(CallSignal, title='Call Signal', style=plot.style_columns, color=color.blue, offset=1, transp=0)
plotshape(PutSignal, title='Put', text="Put", style=shape.circle, location=location.absolute, color=color.red, textcolor=color.black, offset=1, transp=0, size=size.large)
plotshape(CallSignal, title='Call', text="Call", style=shape.circle, location=location.absolute, color=color.blue, textcolor=color.black, offset=1, transp=0, size=size.large)
//plotchar(PutSignal, title='Put', char="◉", text="Put", location=location.absolute, color=color.red, textcolor=color.black, offset=1, transp=0, size=size.small)
//plotchar(CallSignal, title='Call', char="◉", text="Call", location=location.absolute, color=color.blue, textcolor=color.black, offset=1, transp=0, size=size.small)
//Backtesting
exp_tt=input(true,"Expiry Option by Bars")
exp_val=input(3,"Number of Bars")
strategy.entry("Call", strategy.long, when=yTech and window() and t0_DvM)
strategy.entry("Put", strategy.short, when=xTech and window() and t0_DvM)
strategy.close_all(when=barssince(xTech)==exp_val or barssince(yTech)==exp_val)
//EOF
vi e chua bật máy test code nên e tò mò hỏi bác là có phải khi ta đặt stoploss vidu là 2 thì có nghĩa là thua 2 lệnh liên tiếp trong 1 ngày thì cả ngày hôm đó k có lệnh nữa đúng k bác và cái thông kê winrate cũng thay đổi theo stoploss bác nhỉ@vĩnh0902 code này bổ sung đáo hạn tùy chỉnh, đáo hạn 3 nến M5,stoploss =1 loss
View attachment 136750
Mã:// BO - Woodies CCI - Backtesting //anch.v43 // © inno14 //@version=4 strategy("BO - Woodies CCI - Backtesting") //strategy.risk.max_intraday_loss(1, strategy.cash) // === INPUT PERIOD OF TIME === 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 = 2020, 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 ===") Time_zone = input(7,title="Time Zone") FromHourDvM = input(defval = 07, title = "From Hour", minval = 00, maxval = 23) FromMinuteDvM = input(defval = 00, title = "From Minute", minval = 00, maxval = 59) ToHourDvM = input(defval = 18, title = "To Hour", minval = 00, maxval = 23) ToMinuteDvM = input(defval = 00, title = "To Minute", minval = 00, maxval = 59) GMT_FHDvM=FromHourDvM<Time_zone?FromHourDvM-Time_zone+24:FromHourDvM-Time_zone GMT_THDvM=ToHourDvM<Time_zone?ToHourDvM-Time_zone+24:ToHourDvM-Time_zone 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) htrtime = input(true,title="Highlight Trading Time") bgcolor(htrtime? t0_DvM? color.gray : na:na, title="Trading Time", transp=90) // fh_ott= (GMT_FHDvM<10?"0"+tostring(GMT_FHDvM):tostring(GMT_FHDvM)) fm_ott= (FromMinuteDvM<10?"0"+tostring(FromMinuteDvM):tostring(FromMinuteDvM)) th_ott= fh_ott tm_ott= (FromMinuteDvM+5<10?"0"+tostring(FromMinuteDvM+5):tostring(FromMinuteDvM+5)) trading_time_open = fh_ott+fm_ott+"-"+th_ott+tm_ott t1 = time(timeframe.period, trading_time_open) //Woodies CCI cciTurboLength = input(title="CCI Turbo Length", type=input.integer, defval=6, minval=3, maxval=1400) cci14Length = input(title="CCI 14 Length", type=input.integer, defval=14, minval=7, maxval=2000) source = close cciTurbo = cci(source, cciTurboLength) cci14 = cci(source, cci14Length) last5IsDown = cci14[5] < 0 and cci14[4] < 0 and cci14[3] < 0 and cci14[2] < 0 and cci14[1] < 0 last5IsUp = cci14[5] > 0 and cci14[4] > 0 and cci14[3] > 0 and cci14[2] > 0 and cci14[1] > 0 histogramColor = last5IsUp ? color.green : last5IsDown ? color.red : cci14 < 0 ? color.gray : color.gray //Plot Woodies CCI plot(cci14, title="CCI Histogram", color=histogramColor, style=plot.style_histogram, linewidth=2, transp=40) plot(0, title="Zero Line", color=cciTurbo>100?color.blue:cciTurbo<-100?color.red:color.navy, style=plot.style_line, linewidth=6, transp=20) hline(200, title="Hundred Line", color=color.black, linestyle=hline.style_dotted) hline(-200, title="Minus Line", color=color.black, linestyle=hline.style_dotted) //Plot lingreg CCI14 linreg_cci14=linreg(cci14, 5, 0) plot(linreg_cci14, color=color.aqua, linewidth=4) //peak & top peak_cci= linreg_cci14[2]>linreg_cci14[3] and linreg_cci14[1]>linreg_cci14[2] and linreg_cci14[0]<linreg_cci14[1] and linreg_cci14[1]>150 bott_cci= linreg_cci14[2]<linreg_cci14[3] and linreg_cci14[1]<linreg_cci14[2] and linreg_cci14[0]>linreg_cci14[1] and linreg_cci14[1]<-150 peak_cci_1= linreg_cci14[2]>linreg_cci14[3] and linreg_cci14[1]>linreg_cci14[2] and linreg_cci14[0]<linreg_cci14[1] bott_cci_1= linreg_cci14[2]<linreg_cci14[3] and linreg_cci14[1]<linreg_cci14[2] and linreg_cci14[0]>linreg_cci14[1] // fil_len=input(6,title="Filter Length") top_ext=highest(linreg_cci14,fil_len) bot_ext=lowest(linreg_cci14,fil_len) //Put signal x1= peak_cci and linreg_cci14[1]==top_ext[1] and linreg_cci14[1]>valuewhen(peak_cci_1,linreg_cci14[1],1) and close>low[1] and cciTurbo<100 and cci14<linreg_cci14 //Call signal y1= bott_cci and linreg_cci14[1]==bot_ext[1] and linreg_cci14[1]<valuewhen(bott_cci_1,linreg_cci14[1],1) and close<high[1] and cciTurbo>-100 and cci14>linreg_cci14 no_orders = not x1[1] and not x1[2] and not x1[3] and not x1[4] and not x1[5] and not y1[1] and not y1[2] and not y1[3] and not y1[4] and not y1[5] //Stoploss stop_tt=input(true,"Stoploss Option By Loss Trades") stop_val=input(1,"Number of loss trades") stop_loss=strategy.losstrades-strategy.losstrades[barssince(t1)]==stop_val //Function xTech= x1 and no_orders and not stop_loss yTech= y1 and no_orders and not stop_loss //Plot Analyzing Signals //hline1=hline(-1.2*300) hline2=hline(-1.6*300) hline0=hline(0) sigtext= xTech?"Put signal":yTech?"Call signal": "Backtesting From: "+tostring(FromDay)+"/"+tostring(FromMonth)+"/"+tostring(FromYear)+" To: "+tostring(ToDay)+"/"+tostring(ToMonth)+"/"+tostring(ToYear) + " * Trading Time From: "+tostring(FromHourDvM)+":"+tostring(FromMinuteDvM)+" To "+tostring(ToHourDvM)+":"+tostring(ToMinuteDvM) sig_col=xTech?color.new(color.red,10):yTech?color.new(color.blue,10):color.new(color.navy,10) label_sig_text = label.new(bar_index[0], -1.5*300, text=sigtext, style=label.style_none, textcolor=sig_col, size=size.large) label.delete(label_sig_text[1]) //plot Signal putcol = xTech? color.red : na callcol = yTech? color.blue : na PutSignal= xTech and window() and t0_DvM?-1.2*300:na CallSignal= yTech and window() and t0_DvM?-1.2*300:na //plot(PutSignal, title='Put Signal', style=plot.style_columns, color=color.red, offset=1, transp=0) //plot(CallSignal, title='Call Signal', style=plot.style_columns, color=color.blue, offset=1, transp=0) plotshape(PutSignal, title='Put', text="Put", style=shape.circle, location=location.absolute, color=color.red, textcolor=color.black, offset=1, transp=0, size=size.large) plotshape(CallSignal, title='Call', text="Call", style=shape.circle, location=location.absolute, color=color.blue, textcolor=color.black, offset=1, transp=0, size=size.large) //plotchar(PutSignal, title='Put', char="◉", text="Put", location=location.absolute, color=color.red, textcolor=color.black, offset=1, transp=0, size=size.small) //plotchar(CallSignal, title='Call', char="◉", text="Call", location=location.absolute, color=color.blue, textcolor=color.black, offset=1, transp=0, size=size.small) //Backtesting exp_tt=input(true,"Expiry Option by Bars") exp_val=input(3,"Number of Bars") strategy.entry("Call", strategy.long, when=yTech and window() and t0_DvM) strategy.entry("Put", strategy.short, when=xTech and window() and t0_DvM) strategy.close_all(when=barssince(xTech)==exp_val or barssince(yTech)==exp_val) //EOF
Chính xác rùi, kakakavi e chua bật máy test code nên e tò mò hỏi bác là có phải khi ta đặt stoploss vidu là 2 thì có nghĩa là thua 2 lệnh liên tiếp trong 1 ngày thì cả ngày hôm đó k có lệnh nữa đúng k bác và cái thông kê winrate cũng thay đổi theo stoploss bác nhỉ
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.