예스스탁
예스스탁 답변
2020-05-08 11:36:05
안녕하세요
예스스탁입니다.
1
input : sl_type(1); #1:ATR, 2:Absolute, 3:"%"
input : sl_perc(4),atr_length(10),atr_mult(4),sl_absol(10);
input : startDate(20160101),finishDate(21000101);
var : time_cond(false),sl_val(0),ps(0),trailing_sl(0),long_signal(false),short_signal(false);
time_cond = sdate >= startDate and sdate <= finishDate;
sl_val = iff(sl_type == 1,atr_mult * atr(atr_length),iff(sl_type == 2, sl_absol,close * sl_perc / 100));
long_signal = ps != 1 and high > trailing_sl;
short_signal = ps != -1 and low < trailing_sl;
// Calculate SL
trailing_sl = iff(short_signal,high + sl_val,
iff(long_signal,low - sl_val,
iff(ps == 1 , max(low - sl_val, trailing_sl),
iff(ps == -1 , min(high + sl_val, trailing_sl),
trailing_sl))));
ps = iff(long_signal, 1 ,iff(short_signal ,-1 , ps));
plot1(trailing_sl,"trailing_sl",iff(ps == 1 ,green,red));
2
input : sl_type(1); #1:ATR, 2:Absolute, 3:"%"
input : sl_perc(4),atr_length(10),atr_mult(4),sl_absol(10);
input : startDate(20160101),finishDate(21000101);
var : time_cond(false),sl_val(0),ps(0),trailing_sl(0),long_signal(false),short_signal(false);
time_cond = sdate >= startDate and sdate <= finishDate;
sl_val = iff(sl_type == 1,atr_mult * atr(atr_length),iff(sl_type == 2, sl_absol,close * sl_perc / 100));
long_signal = ps != 1 and high > trailing_sl;
short_signal = ps != -1 and low < trailing_sl;
// Calculate SL
trailing_sl = iff(short_signal,high + sl_val,
iff(long_signal,low - sl_val,
iff(ps == 1 , max(low - sl_val, trailing_sl),
iff(ps == -1 , min(high + sl_val, trailing_sl),
trailing_sl))));
ps = iff(long_signal, 1 ,iff(short_signal ,-1 , ps));
if time_cond and ps != 1 then
buy("long");
if time_cond and ps != -1 then
sell("short");
즐거운 하루되세요
> as8282 님이 쓴 글입니다.
> 제목 : 문의드립니다.
> 아래식의 지표및 시스템식을 예스로 부탁합니다.
sl_type = input("%", options = ["%", "ATR", "Absolute"])
sl_perc = input(4, title = "% SL", type = input.float)
atr_length = input(10, title = "ATR Length")
atr_mult = input(4, title = "ATR Mult", type = input.float)
sl_absol = input(10, title = "Absolute SL", type = input.float)
// BACKTESTING RANGE
// From Date Inputs
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 = 2016, title = "From Year", minval = 1970)
// To Date Inputs
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 = 2100, title = "To Year", minval = 1970)
// Calculate start/end date and time condition
startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = time >= startDate and time <= finishDate
//////////////////
// CALCULATIONS //
// SL values
sl_val = sl_type == "ATR" ? atr_mult * atr(atr_length) :
sl_type == "Absolute" ? sl_absol :
close * sl_perc / 100
// Init Variables
pos = 0
trailing_sl = 0.0
// Signals
long_signal = nz(pos[1]) != 1 and high > nz(trailing_sl[1])
short_signal = nz(pos[1]) != -1 and low < nz(trailing_sl[1])
// Calculate SL
trailing_sl := short_signal ? high + sl_val :
long_signal ? low - sl_val :
nz(pos[1]) == 1 ? max(low - sl_val, nz(trailing_sl[1])) :
nz(pos[1]) == -1 ? min(high + sl_val, nz(trailing_sl[1])) :
nz(trailing_sl[1])
// Position var
pos := long_signal ? 1 : short_signal ? -1 : nz(pos[1])
//////////////
// PLOTINGS //
plot(trailing_sl, linewidth = 2, color = pos == 1 ? color.green : color.red)
//////////////
// STRATEGY //
if (time_cond and pos != 1)
strategy.entry("long", true, stop = trailing_sl)
if (time_cond and pos != -1)
strategy.entry("short", false, stop = trailing_sl)