답변완료
봉 움직임의 가정 오류에 대한 도움을 부탁드립니다.
안녕하세요?
저는 전략 스크립트를 작성할때에 손절을 위하여
setstoploss 를 사용하지않고
If MarketPosition == 1 Then
ExitLong("손절매수",AtStop,EntryPrice-(stop_loss_point));
If MarketPosition == -1 Then
Exitshort("손절매도",AtStop,EntryPrice+(stop_loss_point));
와 같은 방식을 사용하고 있습니다.
이렇게 하면, "조건만족시 즉시"의 경우와 "봉 완성시"의 경우에 차이가 발생하지 않습니다.
setstoploss를 사용하면, "조건만족시 즉시"의 경우와 "봉 완성시"의 경우에 차이가 발생합니다.
진입봉에서 청산도 됩니다.
진입봉에서 청산이 되지 않을 만큼 큰 포인트로 SetStoploss를 적용하면 진입봉에서 청산되는 것을 피할 수 있을 것 같기는 한데, 그렇게 되면 손절 포인트가 너무 커져서 손절의 의미가 퇴색되지 않을까 하는 추측도 해봅니다.(손절 포인트가 너무 적어져도, 너무 커져도 문제가 될 것 같습니다.)
제가 AtStop으로 손절을 설정하는 것은 위와 같은 문제들을 피하면서 동시에 혹시라도 봉 움직임 가정의 오류가 발생할수 있지않을까 하는 우려때문입니다.
굳이 이렇게 하지 않고 단순히 Setstoploss를 사용하면서, "조건만족시 즉시"를 선택하여 백테스트와 전진분석을 하고, 실제 거래도 그렇게 한다고 했을때에 봉 움직임의 가정의 오류는 없을지, 어떤 방식을 더 추천하시는지에 대한 조언을 부탁드립니다.
항상 감사드립니다.
답변완료
수식 부탁드립니다
지표식 부탁 드립니다.
//@version=4
study(title="CTI", overlay=true)
src = close
sm = input(100, title="Smoothing Period")
cd = input(0.7, title="Constant D")
di = (sm - 1.0) / 2.0 + 1.0
c1 = 2 / (di + 1.0)
c2 = 1 - c1
c3 = 3.0 * (cd * cd + cd * cd * cd)
c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
var float i1 = na
var float i2 = na
var float i3 = na
var float i4 = na
var float i5 = na
var float i6 = na
i1 := c1*src + c2*nz(i1[1])
i2 := c1*i1 + c2*nz(i2[1])
i3 := c1*i2 + c2*nz(i3[1])
i4 := c1*i3 + c2*nz(i4[1])
i5 := c1*i4 + c2*nz(i5[1])
i6 := c1*i5 + c2*nz(i6[1])
bfr = -cd*cd*cd*i6 + c3*i5 + c4*i4 + c5*i3
bfrColor = bfr > nz(bfr[1]) ? color.green : bfr < nz(bfr[1]) ? color.red : color.blue
plot(bfr, title="Trend", linewidth=2, color=bfrColor)
2025-08-28
101
글번호 193553
지표
답변완료
수식검토 부탁드립니다.
안녕하세요. 운영자님
보내주신 수식 검토 결과 수정이 필요한 부분이 있어 추가 요청 드립니다.
거래시간이 가령 20시00에 시작하여 다음날 오전 05시00분 (나스닥 기준)에 종료되도록 하려고 하니 잘되지 않습니다. 수정 좀 부탁 드립니다.
====================================================================================
Inputs:
ShortMAPeriod(10),
LongMAPeriod(30),
RSIPeriod(14),
StochKPeriod(14),
StochDPeriod(3),
MACDFast(12),
MACDSlow(26),
MACDSignal(9),
BBLength(20),
NumDevs(2),
ProfitTarget(20),
StopLoss(10),
TrailStop(15),
TradeStartTime(93000),
TradeEndTime(150000);
Vars:
ShortMA(0), LongMA(0), RSIVal(0), SlowKVal(0), SlowDVal(0),
MACDVal(0), MACDSignalVal(0),
BBMid(0), BBUpper(0), BBLower(0),
EntryPrice(0), MaxProfit(0);
ShortMA = ma(Close, ShortMAPeriod);
LongMA = ma(Close, LongMAPeriod);
RSIVal = RSI(RSIPeriod);
SlowKVal = SlowK(StochKPeriod,3);
SlowDVal = ma(SlowKVal, StochDPeriod);
// MACD
MACDVal = Ema(Close, MACDFast) - Ema(Close, MACDSlow);
MACDSignalVal = Ema(MACDVal, MACDSignal);
// Bollinger Bands
BBMid = ma(Close, BBLength);
BBUpper = BBMid + Std(Close, BBLength) * NumDevs;
BBLower = BBMid - Std(Close, BBLength) * NumDevs;
If (sTime >= TradeStartTime) and (sTime <= TradeEndTime) Then Begin
// ==== 롱 진입 ====
If (ShortMA > LongMA) and (RSIVal > 50) and
(SlowKVal > SlowDVal) and (SlowKVal > 50) and
(MACDVal > MACDSignalVal) and (Close > BBMid) Then
Begin
If MarketPosition <= 0 Then Begin
Buy("b",AtMarket);
EntryPrice = Close;
MaxProfit = Close;
End;
End;
// ==== 숏 진입 ====
If (ShortMA < LongMA) and (RSIVal < 50) and
(SlowKVal < SlowDVal) and (SlowKVal < 50) and
(MACDVal < MACDSignalVal) and (Close < BBMid) Then
Begin
If MarketPosition >= 0 Then Begin
Sell("s",AtMarket);
EntryPrice = Close;
MaxProfit = Close;
End;
End;
End;
If MarketPosition == 1 Then Begin
MaxProfit = MaxList(MaxProfit, Close);
If (Close - EntryPrice) >= ProfitTarget Then
ExitLong("bx1",AtMarket);
If (EntryPrice - Close) >= StopLoss Then
ExitLong("bx2",AtMarket);
If (MaxProfit - Close) >= TrailStop Then
ExitLong("bx3",AtMarket);
End;
If MarketPosition == -1 Then Begin
MaxProfit = MinList(MaxProfit, Close);
If (EntryPrice - Close) >= ProfitTarget Then
exitshort("sx1",atmarket);
If (Close - EntryPrice) >= StopLoss Then
exitshort("sx2",atmarket);
If (Close - MaxProfit) >= TrailStop Then
exitshort("sx3",atmarket);
End;