예스스탁
예스스탁 답변
2023-06-12 10:28:17
안녕하세요
예스스탁입니다.
1
수식내 LRSsignal가 어떤 함수인지 알수 없습니다.
2
input: period(20), usefutures(false), printfile(true);
vars: nhigh(0), nlow(0), adate(" "),
totalPL(0), dailyPL(0), psignal(0), ATR(0), ATRperiod(20), size(0),
futuresinvestment(25000), stockinvestment(10000);;
if usefutures then
size = futuresinvestment/(atr(ATRperiod)*bigpointvalue);
else
size = stockinvestment/close[1];
if close > close[period] then
begin
Buy("b");
end;
if close < close[period] then begin
Sell("s");
end;
totalpl = netprofit + openpositionprofit;
dailyPL = psignal*CurrentContracts*(close - close[1]);
psignal = marketposition;
3
inputs: period(20), volfactor(2.0), usefutures(false);
vars: ATRv(0), change(0), sizeper(20), size(0),
stockinvestment(10000), futuresinvestment(25000);
ATRv = ATR(period);
change = close - close[1];
// size for new positions
if usefutures then
size = futuresinvestment/(ATR(sizeper)*bigpointvalue);
else
size = stockinvestment/close;
if marketposition <= 0 and change > volfactor*ATRv[1] then
buy("b",AtMarket);
if marketposition >= 0 and change < -volfactor*ATRv[1] then
sell("s",AtMarket);
4
inputs: period(20), factor(2.0);
vars: alpha(0), mt(0), ut(0), dt(0), mt2(0), ut2(0), dt2(0), but(0), blt(0);
alpha = 2/(period + 1);
mt = alpha*close + (1 - alpha)*mt;
ut = alpha*mt + (1 - alpha)*ut;
dt = ((2 - alpha)*mt - ut)/(1 - alpha);
mt2 = alpha*absvalue(close - dt) + (1 - alpha)*mt2;
ut2 = alpha*mt2 + (1 - alpha)*ut2;
dt2 = ((2 - alpha)*mt2 - ut2)/(1 - alpha);
but = dt + factor*dt2;
blt = dt - factor*dt2;
if CrossUp(c,but) Then
Buy();
if CrossDown(c,but) Then
Sell();
5
inputs: period(20), bandwidth(2.0);
vars: slope(0), lrvalue(0), resid(0), sdresid(0), angle(0),
intercept(0), upperband(0), lowerband(0), size(0), investment(25000);
lrvalue = LRL(close,period);
resid = Close - lrvalue;
If Currentbar > period then
begin
size = investment / (ATR(30)*bigpointvalue);
size = maxlist(size,1);
sdresid = std(close,period);
Upperband = lrvalue + slope + bandwidth*sdresid;
Lowerband = lrvalue + slope - bandwidth*sdresid;
End;
plot1(upperband,"UB");
Plot2(lowerband,"LB");
plot3(lrvalue,"LR");
6
input: type(0), swing(2.5), usefutures(false), printfile(true);
vars: pcswing(0), lastswing(0), curhigh(0), curlow(0), swhigh(0), swlow(0) , highbar(0),
lowbar(0), chighbar(0), clowbar(0), lowp(0), highp(0), xclose(0), xhigh(0),
xlow(0), divide(4), par(800), prevhigh(0), prevlow(0), adate(" "),
totalPL(0), dailyPL(0), psignal(0), ATR(0), ATRperiod(20), size(0),
futuresinvestment(25000), stockinvestment(10000);
pcswing = swing / 100.;
if usefutures then
size = futuresinvestment/(ATR(ATRperiod)*bigpointvalue);
else
size = stockinvestment/close[1];
if type == 0 then
{
xhigh = high;
xlow = low;
xclose = close;
}
else if type == 1 then
{
xhigh = 100 - low;
xlow = 100 - high;
xclose = 100 - close;
}
else if type == 2 then
{
xhigh = par / low;
xlow = par / high;
xclose = par / close;
}
if currentbar == 1 then
{
curhigh = xclose;
curlow = xclose;
}
if type == 0 then
{
if marketposition <= 0 and xhigh > swhigh then
{
Buy();
}
else if marketposition >= 0 and xlow < swlow then {
Sell();
}
}
else
{
if marketposition >= 0 and xhigh > swhigh then
{
Sell();
}
else if marketposition <= 0 and xlow < swlow then
{
Buy();
}
}
if lastswing<>1 then
{
if xlow < curhigh - curhigh*pcswing then
{
lastswing = 1;
swhigh = curhigh;
highbar = chighbar;
curlow = xlow;
lowp = xlow;
clowbar = currentbar;
}
else
{
if xhigh > curhigh then
{
curhigh = xhigh;
chighbar = currentbar;
}
}
}
if lastswing <> -1 then
{
if xhigh > curlow + curlow*pcswing then
{
lastswing = -1;
swlow = curlow;
lowbar = clowbar;
curhigh = xhigh;
highp = xhigh;
chighbar = currentbar;
}
else
{
if xlow < curlow then
{
curlow = xlow;
clowbar = currentbar;
}
}
}
totalpl = netprofit + openpositionprofit;
dailyPL = psignal*CurrentContracts*(close - close[1]);
psignal = marketposition;
7.
inputs: period(40);
vars: SD(0), SDV(0), stdavg(0);
SD = std(close,period);
SDV = (SD - SD[1])/SD;
StdAvg = ma(close,period/2) + .05*SDV;
plot1(stdavg,"StdAvg");
8.
input: usemovingaverage(true), usebreakout(false), useslope(false), useexponential(false), period(80),
entryoption(0), crossoption(0), longonly(false), exitvol(0), reentervol(0), stoploss(0),
usestocks(true),usefutures(false),variablesize(true), reinvest(false), futuresinvestment(25000),
stockinvestment(10000), printfiles(false);
vars: signal(0), price(0), size(1), investment(1000), slope(0), ATRper(20), smooth(1.0),
atrange(0), MAV(0), adate(" "), equity(0), PL(0), PLlong(0), PLshort(0), exposure(0),
expsmooth(0), tradeentry(0), tradeentrybar(0), tradeprice(0),dailyreturn(0), NAV(100),
volper(20), returns(0), vol(0), exitvolOK(true), reentervolOK(true), exitonstop(0),
bestprice(0);
If Currentbar == 1 then
{
if usestocks then
{
investment = stockinvestment;
if variablesize == false then
size = 100;
}
else
{
investment = futuresinvestment;
if variablesize == false then
size = 1;
}
if useexponential then smooth = 2/(period + 1);
}
if variablesize then
{
if usefutures then
{
atrange = ATr(ATRper);
if atrange == 0 then
size = 1;
else
if atrange <> 0 then size = investment/(atrange*bigpointvalue);
}
if usestocks then
{
if close[1] <> 0 then size = investment/close[1];
}
}
if usemovingaverage then
{
MAV = ma(close,period);
if crossoption == 0 then
{
if MAV > MAV[1] then signal = 1;
else if MAV < MAV[1] then signal = -1;
}
else if crossoption == 1 then
{
if close >= MAV then signal = 1;
else signal = -1;
}
}
else if usebreakout then
{
if high > highest(high[1],period) then signal = 1;
else if low < lowest(low[1],period) then signal = -1;
}
else if useslope then
{
slope = LRS(close,period);
if slope > 0 then signal = 1;
else if slope < 0 then signal = -1;
}
else if useexponential then
{
if currentbar == 1 then
expsmooth = close;
else
{
expsmooth = expsmooth + smooth*(close - expsmooth);
}
if expsmooth > expsmooth[1] then signal = 1;
else if expsmooth < expsmooth[1] then signal = -1;
}
// reset exit on stop
if exitonstop <> 0 then
{
if exitonstop > 0 and signal < 0 then exitonstop = 0;
else if exitonstop < 0 and signal > 0 then exitonstop = 0;
}
// exit percentage trailing stop-loss
if stoploss <> 0 and marketposition <> 0 then
{
if marketposition > 0 then
{
if close/entryprice - 1 < -stoploss then
{
ExitLong("XLstop",AtMarket);
exitonstop = marketposition;
}
}
else if marketposition < 0 then
{
bestprice = minlist(bestprice,low);
if bestprice/close - 1 < -stoploss then
{
ExitShort("XSstop",AtMarket);
exitonstop = marketposition;
}
}
}
if exitvol <> 0 then
{
returns = close/close[1] - 1;
vol = std(returns,volper)*squareroot(252.);
if reentervol <> 0 and vol < reentervol then exitvolOK = true;
if vol > exitvol then exitvolOK = false;
if marketposition <> 0 and exitvolOK == false then
{
if marketposition > 0 then ExitLong("XLvol",AtMarket);
else if marketposition < 0 then ExitShort("XSvol",AtMarket);
reentervolOK = false;
}
}
if marketposition == 0 and reentervolOK == false and vol < reentervol
then reentervolOK = true;
If entryoption == 0 and exitvolOK and exitonstop == 0 then
{
if signal == 1 and marketposition <> 1 then
{
if usemovingaverage then Buy ("BMA",OnClose,def,size);
else if usebreakout then Buy ("BBO",OnClose,def,size);
else if useslope then buy ("BLRS",OnClose,def,size);
else if useexponential then buy ("BEXP",OnClose,def,size);
tradeentry = date;
tradeentrybar = currentbar;
tradeprice = close;
bestprice = close;
}
else if signal == -1 and marketposition <> -1 then
{
if longonly then
{
if usemovingaverage then ExitLong("XMA");
else if usebreakout then ExitLong ("XBO");
else if useslope then ExitLong ("XLRS");
else if useexponential then ExitLong ("XEXP");
tradeentry = date;
tradeentrybar = currentbar;
tradeprice = close;
bestprice = close;
}
else
{
if usemovingaverage then sell("SMA",OnClose,def,size);
else if usebreakout then sell("SBO",OnClose,def,size);
else if useslope then sell("SLRS",OnClose,def,size);
else if useexponential then Sell("SEXP",OnClose,def,size);
tradeentry = date;
tradeentrybar = currentbar;
tradeprice = close;
bestprice = close;
}
}
}
else if entryoption == 1 and exitvolOK then
{
If signal == 1 and marketposition <> 1 then buy("b",OnClose,Def,size);
Else if signal == -1 and marketposition <> -1 then
{
if longonly then ExitLong("",AtMarket);
else sell("s",AtMarket,Def,size);
}
}
else if entryoption == 2 and exitvolOK then
{
If signal[1] == 1 and marketposition <> 1 then buy("",OnClose,Def,size);
Else if signal[1] == -1 and marketposition <> -1 then
{
if longonly then ExitLong("",AtMarket);
else sell("",AtMarket,Def,size);
}
}
if lastbaronchart then
if marketposition > 0 then ExitLong();
else if marketposition < 0 then ExitShort();
equity = netprofit + openpositionprofit;
PL = equity - equity[1];
dailyreturn = 0;
if investment <> 0 then dailyreturn = PL/investment;
NAV = NAV*(1 + dailyreturn);
if marketposition > 0 then
PLlong = PLlong + PL;
else if marketposition < 0 then
PLshort = PLshort + PL;
if reinvest then investment = stockinvestment + equity;
9.
수식내 TSMStdevStop가 어떤 함수인지 알수 없습니다.
10
input: period(20);
vars: change(0), noise(0), diff(0), ratio(0), signal(0), sumratio(0), avgratio(0);
ratio = 0;
diff = AbsValue(close - close[1]);
if currentbar > period then
{
change = close - close[period];
signal = AbsValue(change);
noise = AccumN(diff,period);
ratio = 0;
if noise <> 0 then ratio = signal/noise;
sumratio = sumratio + ratio;
}
if lastbaronchart then
avgratio = sumratio/(currentbar - period);
즐거운 하루되세요
> 고민중 님이 쓴 글입니다.
> 제목 : TS이지랭귀지를 예스랭귀지로 변환하고 싶습니다.
> 예스랭귀지로 변환해서 거래하고 싶습니다. 양이 좀 많아서 죄송합니다.
잘부탁드립니다.
1. 기울기관련수식
{ period = length of exponential trend
filter = whole percent trend change to give signal
lag = enter after a lag of "lag"
}
input: period(20), filter(0), lag(0);
vars: signal(0);
{ Linear regression slope }
signal = LRSsignal(period,filter,lag);
if signal = 1 then Buy This Bar on close;
if signal = -1 then Sell Short This Bar on close;
2. 모멘텀 관련 수식
{ period = length of calculation }
input: period(20), usefutures(false), printfile(true);
vars: nhigh(0), nlow(0), adate(" "),
totalPL(0), dailyPL(0), psignal(0), ATR(0), ATRperiod(20), size(0),
futuresinvestment(25000), stockinvestment(10000);;
if usefutures then begin
size = futuresinvestment/(avgtruerange(ATRperiod)*bigpointvalue);
end
else size = stockinvestment/close[1];
{ 매수, 매도 수식 }
if close > close[period] then begin
buy to cover all contracts this bar on close;
Buy size contracts This Bar on close;
end;
if close < close[period] then begin
sell all contracts this bar on close;
Sell Short size contracts This Bar on close;
end;
totalpl = netprofit + openpositionprofit;
dailyPL = psignal*currentshares*(close - close[1]);
psignal = marketposition;
end;
3. 변동성 시스템
inputs: period(20), volfactor(2.0), usefutures(false);
vars: ATR(0), change(0), sizeper(20), size(0),
stockinvestment(10000), futuresinvestment(25000);
ATR = avgtruerange(period);
change = close - close[1];
// size for new positions
if usefutures then begin
size = futuresinvestment/(avgtruerange(sizeper)*bigpointvalue);
end
else begin size = stockinvestment/close;
end;
if marketposition <= 0 and change > volfactor*ATR[1] then
buy size contracts next bar on open
else if marketposition >= 0 and change < -volfactor*ATR[1] then
sell short size contracts next bar on open;
4. 볼린저밴드관련 수식
inputs: period(20), factor(2.0);
vars: alpha(0), mt(0), ut(0), dt(0), mt2(0), ut2(0), dt2(0), but(0), blt(0);
{ smoothing constant }
alpha = 2/(period + 1);
mt = alpha*close + (1 - alpha)*mt;
ut = alpha*mt + (1 - alpha)*ut;
dt = ((2 - alpha)*mt - ut)/(1 - alpha);
mt2 = alpha*absvalue(close - dt) + (1 - alpha)*mt2;
ut2 = alpha*mt2 + (1 - alpha)*ut2;
dt2 = ((2 - alpha)*mt2 - ut2)/(1 - alpha);
but = dt + factor*dt2;
blt = dt - factor*dt2;
종가가 볼린저밴드 상단 돌파시 매수, 종가가 볼린저밴드 하단 돌파시 매도
5.선형회귀 밴드
inputs: period(20), bandwidth(2.0);
vars: slope(0), lrvalue(0), resid(0), sdresid(0), angle(0),
intercept(0), upperband(0), lowerband(0), size(0), investment(25000);
Value1 = LinearReg( close, period, currentbar, slope, angle, intercept,
lrvalue ) ;
{ slope = LinearRegSlope(close,period);
lrvalue = linearRegValue(close,period,currentbar);}
resid = Close - lrvalue;
If Currentbar > period then begin
{ position size }
size = investment / (avgtruerange(30)*bigpointvalue);
size = maxlist(size,1);
sdresid = stddev(close,period);
Upperband = lrvalue + slope + bandwidth*sdresid;
Lowerband = lrvalue + slope - bandwidth*sdresid;
{ plot1(upperband,"UB");
Plot2(lowerband,"LB");
} plot3(lrvalue,"LR");
{ If Close > upperband[1] then buy size contracts this bar on close
Else if Close < lowerband[1] then sell short size contracts this bar on close; }
end;
6. 스윙인덱스 관련 수식
Inputs for TSM SWING:
type = 0, normal price
= 1, 3-month rate
= 2, bond price at par
swing = price swing in whole % (e.g., 2% = 2.0) }
input: type(0), swing(2.5), usefutures(false), printfile(true);
vars: pcswing(0), lastswing(0), curhigh(0), curlow(0), swhigh(0), swlow(0) , highbar(0),
lowbar(0), chighbar(0), clowbar(0), lowp(0), highp(0), xclose(0), xhigh(0),
xlow(0), divide(4), par(800), prevhigh(0), prevlow(0), adate(" "),
totalPL(0), dailyPL(0), psignal(0), ATR(0), ATRperiod(20), size(0),
futuresinvestment(25000), stockinvestment(10000);
pcswing = swing / 100.;
if usefutures then begin
size = futuresinvestment/(avgtruerange(ATRperiod)*bigpointvalue);
end
else size = stockinvestment/close[1];
if type = 0 then begin
xhigh = high;
xlow = low;
xclose = close;
end
else if type = 1 then begin
xhigh = 100 - low;
xlow = 100 - high;
xclose = 100 - close;
end
else if type = 2 then begin
xhigh = par / low;
xlow = par / high;
xclose = par / close;
end;
{ INITIALIZE MOST RECENT HIGH AND LOW }
if currentbar = 1 then begin
curhigh = xclose; { current high }
curlow = xclose; { current low }
end;
{ Buy or sell signals }
if type = 0 then begin
if marketposition <= 0 and xhigh > swhigh then begin
Buy to cover all contracts this bar on close;
Buy size contracts This Bar on close;
end
else if marketposition >= 0 and xlow < swlow then begin
sell all contracts this bar on close;
Sell Short size contracts This Bar on close;
end;
end
else begin
if marketposition >= 0 and xhigh > swhigh then begin
sell all contracts this bar on close;
Sell Short size contracts This Bar on close;
end
else if marketposition <= 0 and xlow < swlow then begin
Buy to cover all contracts This Bar on close;
buy size contracts this bar on close;
end;
end;
{ SEARCH FOR A NEW HIGH -- favor reversals }
if lastswing<>1 then begin
{ REVERSE FROM HIGH IF MINIMUM % SWING }
if xlow < curhigh - curhigh*pcswing then begin
lastswing = 1; { lastswing high fixed }
swhigh = curhigh; { new verified high }
highbar = chighbar;
curlow = xlow; { initialize new lows }
lowp = xlow; { swing low for plot }
clowbar = currentbar;
end
else begin
if xhigh > curhigh then begin
curhigh = xhigh; { new current high }
chighbar = currentbar;
end;
end;
end;
{ SEARCH FOR A NEW LOW - favor reversal }
if lastswing <> -1 then begin
{ REVERSAL FROM LOW IF MINIMUM % SWING }
if xhigh > curlow + curlow*pcswing then begin
lastswing = -1;
swlow = curlow;
lowbar = clowbar;
curhigh = xhigh; { initialize current high }
highp = xhigh; { swing high for plot }
chighbar = currentbar;
end
else begin
if xlow < curlow then begin
curlow = xlow;
clowbar = currentbar;
end;
end;
end;
totalpl = netprofit + openpositionprofit;
dailyPL = psignal*currentshares*(close - close[1]);
psignal = marketposition;
end;
7. 표준편차 이동평균 관련 수식
inputs: period(40);
vars: SD(0), SDV(0), stdavg(0);
SD = stddev(close,period);
SDV = (SD - SD[1])/SD;
StdAvg = Average(close,period/2) + .05*SDV;
plot1(stdavg,"StdAvg");
8. 추세추종 시스템 관련 수식
{ period = length of calculaton
entryoption = 0 buy/sell on current close
= 1 buy/sell on next open
= 2 buy/sell next close
crossoption = 0 using trendline,
= 1 use price crossing trendline
longonly true then only long positions
high-vol filter
}
input: usemovingaverage(true), usebreakout(false), useslope(false), useexponential(false), period(80),
entryoption(0), crossoption(0), longonly(false), exitvol(0), reentervol(0), stoploss(0),
usestocks(true),usefutures(false),variablesize(true), reinvest(false), futuresinvestment(25000),
stockinvestment(10000), printfiles(false);
vars: signal(0), price(0), size(1), investment(1000), slope(0), ATRper(20), smooth(1.0),
atrange(0), MA(0), adate(" "), equity(0), PL(0), PLlong(0), PLshort(0), exposure(0),
expsmooth(0), tradeentry(0), tradeentrybar(0), tradeprice(0),dailyreturn(0), NAV(100),
volper(20), returns(0), vol(0), exitvolOK(true), reentervolOK(true), exitonstop(0),
bestprice(0);
If Currentbar = 1 then begin
if usestocks then begin
investment = stockinvestment;
if variablesize = false then size = 100;
end
else begin
investment = futuresinvestment;
if variablesize = false then size = 1;
end;
if useexponential then smooth = 2/(period + 1);
end;
if variablesize then begin
if usefutures then begin
atrange = avgtruerange(ATRper);
if atrange = 0 then
size = 1
else
if atrange <> 0 then size = investment/(atrange*bigpointvalue);
end;
if usestocks then begin
if close[1] <> 0 then size = investment/close[1];
end;
end;
if usemovingaverage then begin
MA = average(close,period);
if crossoption = 0 then begin
if MA > MA[1] then signal = 1
else if MA < MA[1] then signal = -1;
end
else if crossoption = 1 then begin
if close >= MA then signal = 1
else signal = -1;
end;
end
else if usebreakout then begin
if high > highest(high[1],period) then signal = 1
else if low < lowest(low[1],period) then signal = -1;
end
else if useslope then begin
slope = linearregslope(close,period);
if slope > 0 then signal = 1
else if slope < 0 then signal = -1;
end
else if useexponential then begin
if currentbar = 1 then
expsmooth = close
else begin
expsmooth = expsmooth + smooth*(close - expsmooth);
end;
if expsmooth > expsmooth[1] then signal = 1
else if expsmooth < expsmooth[1] then signal = -1;
end;
// reset exit on stop
if exitonstop <> 0 then begin
if exitonstop > 0 and signal < 0 then exitonstop = 0
else if exitonstop < 0 and signal > 0 then exitonstop = 0;
end;
// exit percentage trailing stop-loss
if stoploss <> 0 and marketposition <> 0 then begin
// return on trade as of close
// PL = marketposition*currentcontracts*(close - entryprice);
if marketposition > 0 then begin
// bestprice = maxlist(bestprice,high);
// if close/bestprice - 1 < -stoploss then begin
if close/entryprice - 1 < -stoploss then begin
sell ("XLstop") all contracts next bar on open;
exitonstop = marketposition;
end;
end
else if marketposition < 0 then begin
bestprice = minlist(bestprice,low);
if bestprice/close - 1 < -stoploss then begin
buy to cover ("XSstop") all contracts next bar on open;
exitonstop = marketposition;
end;
end;
end;
// exit volatility filter
if exitvol <> 0 then begin
returns = close/close[1] - 1;
vol = stddev(returns,volper)*squareroot(252.);
if reentervol <> 0 and vol < reentervol then exitvolOK = true;
if vol > exitvol then exitvolOK = false;
// exit on volatility filter
if marketposition <> 0 and exitvolOK = false then begin
if marketposition > 0 then sell ("XLvol") all contracts next bar on open
else if marketposition < 0 then buy to cover ("XSvol") all contracts next bar on open;
reentervolOK = false;
end;
end;
if marketposition = 0 and reentervolOK = false and vol < reentervol
then reentervolOK = true;
{ entry and entry options, always reverse position }
If entryoption = 0 and exitvolOK and exitonstop = 0 then begin
if signal = 1 and marketposition <> 1 then begin
if usemovingaverage then Buy ("BMA") size contracts this bar on close
else if usebreakout then Buy ("BBO") size contracts this bar on close
else if useslope then buy ("BLRS") size contracts this bar on close
else if useexponential then buy ("BEXP") size contracts this bar on close;
// adate = ELdatetostring(tradeentry);
// print(file("c:₩tradestation₩Trend_trade_length.csv"), adate, ",", currentbar - tradeentrybar:5:0,
// ",", size*(close - tradeprice):8:2);
tradeentry = date;
tradeentrybar = currentbar;
tradeprice = close;
bestprice = close;
end
else if signal = -1 and marketposition <> -1 then begin
if longonly then begin
if usemovingaverage then sell ("XMA") all contracts this bar on close
else if usebreakout then sell ("XBO") all contracts this bar on close
else if useslope then sell ("XLRS") all contracts this bar on close
else if useexponential then sell ("XEXP") all contracts this bar on close;
// adate = ELdatetostring(tradeentry);
// print(file("c:₩tradestation₩Trend_trade_length.csv"), adate, ",", currentbar - tradeentrybar:5:0,
// ",", size*(close - tradeprice):8:2);
tradeentry = date;
tradeentrybar = currentbar;
tradeprice = close;
bestprice = close;
end
else begin
if usemovingaverage then sell short ("SMA") size contracts this bar on close
else if usebreakout then sell short ("SBO") size contracts this bar on close
else if useslope then sell short ("SLRS") size contracts this bar on close
else if useexponential then sell short ("SEXP") size contracts this bar on close;
// adate = ELdatetostring(tradeentry);
// print(file("c:₩tradestation₩Trend_trade_length.csv"), adate, ",", currentbar - tradeentrybar:5:0,
// ",", size*(close - tradeprice):8:2);
tradeentry = date;
tradeentrybar = currentbar;
tradeprice = close;
bestprice = close;
end;
end;
end
else if entryoption = 1 and exitvolOK then begin
If signal = 1 and marketposition <> 1 then buy size contracts next bar on open
Else if signal = -1 and marketposition <> -1 then begin
if longonly then sell all contracts next bar on open
else sell short size contracts next bar on open;
end;
end
else if entryoption = 2 and exitvolOK then begin
If signal[1] = 1 and marketposition <> 1 then buy size contracts this bar on close
Else if signal[1] = -1 and marketposition <> -1 then begin
if longonly then sell all contracts next bar on open
else sell short size contracts next bar on open;
end;
end;
if lastbaronchart then
if marketposition > 0 then sell all contracts this bar on close
else if marketposition < 0 then buy to cover all contracts this bar on close;
equity = netprofit + openpositionprofit;
PL = equity - equity[1];
dailyreturn = 0;
if investment <> 0 then dailyreturn = PL/investment;
NAV = NAV*(1 + dailyreturn);
if marketposition > 0 then
PLlong = PLlong + PL
else if marketposition < 0 then
PLshort = PLshort + PL;
if reinvest then investment = stockinvestment + equity;
If printfiles then begin
adate = ELdatetostring(date);
// if currentbar = 1 then begin
// print(file("c:₩tradestation₩Trend_trade_length.csv"), "Enter,Days,PL");
// end;
// if usemovingaverage then begin
If Currentbar = 1 then begin
print(file("c:₩tradestation₩Trend_PL.csv"),"Date,TotalPL");
print(file("c:₩tradestation₩Trend_Detail.csv"),
"Date,Open,High,Low,Close,MA,size,marketposition,PLtoday,PLlong,",
"PLshort,TotalPL,Return,NAV");
end;
print(file("c:₩tradestation₩Trend_PL.csv"),adate, ",", PL:8:4);
print(file("c:₩tradestation₩Trend_Detail.csv"),adate, ",", open:8:4, ",", high:8:4, ",",
low:8:4, ",", close:8:4, ",", MA:8:4, ",", currentcontracts:6:2, ",",
marketposition:6:2, ",", PL:8:4, ",", PLlong:8:4, ",",
PLshort:8:4, ",", equity:8:4, ",", dailyreturn:6:5, ",", NAV:10:3);
// end
// else if usebreakout then begin
// If Currentbar = 1 then print(file("c:₩tradestation₩BO_PL.csv"), "Date,size,netPL,PLlong,PLshort,PLtoday");
// print(file("c:₩tradestation₩BO_PL.csv"),adate, ",", size:8:3, ",", equity:8:4, ",", PLlong:8:4, ",",
// PLshort:8:4, ",", PL:8:4);
// end
// else if useslope then begin
// If Currentbar = 1 then print(file("c:₩tradestation₩LRS_PL.csv"), "Date,size,netPL,PLlong,PLshort,PLtoday");
// print(file("c:₩tradestation₩LRS_PL.csv"),adate, ",", size:8:3, ",", equity:8:4, ",", PLlong:8:4, ",",
// PLshort:8:4, ",", PL:8:4);
// end;
end;
9.표준편차 청산수식
{ inputs: length = average true range calculation period
(normally 30 for intraday, 20 for daily)
factor = standard deviation value for stop }
inputs: length(20), factor1(2.06), factor2(3.2);
vars: up1(0), up2(0), dn1(0), dn2(0);
up1 = highest(high,length) - TSMStdevStop(length, factor1);
up2 = highest(high, length) - TSMStdevStop(length, factor2);
dn1 = lowest(low, length) + TSMStdevStop(length, factor1);
dn2 = lowest(low, length) + TSMStdevStop(length, factor2);
plot1(up1,"TSMup1");
plot2(up2,"TSMup2");
plot3(dn1,"TSMdn1");
plot4(dn2,"TSMdn2");
10. 효율비 관련 수식
input: period(20);
vars: change(0), noise(0), diff(0), ratio(0), signal(0), sumratio(0), avgratio(0);
ratio = 0;
diff = AbsValue(close - close[1]);
if currentbar > period then begin
change = close - close[period];
signal = AbsValue(change);
noise = summation(diff,period);
ratio = 0;
if noise <> 0 then ratio = signal/noise;
sumratio = sumratio + ratio;
end;
if lastbaronchart then begin
avgratio = sumratio/(currentbar - period);