커뮤니티

수정 바랍니다.

프로필 이미지
하리마우
2026-07-22 11:57:55
51
글번호 232929
답변완료

예스나를 이용하여 수식을 만들어 보았는데 원하는 수정이 되지 않아 부탁드립니다. 매수 진입후 골든크로스가 발생하면 재진입이 계속 되어야 하며 진입후 데드크로스가 발생하면 청산하는데 세금을 제외한 0.5%이상일 경우에만 청산되도록 수정 부탁드립니다.


// 6/20 이동평균 골든데드 전략 (체결 시점에 평균가 갱신 및 엄격한 청산 조건 적용)

input : ShortLen(6), LongLen(20), StopLossTicks(0), ProfitTargetTicks(0);

input : TotalTaxPercent(0.0); // 세금/수수료 합계(%)

var : maShort(0), maLong(0);

var : LastEntryPrice(0), AvgEntryPrice(0);

var : EntryCount(0);

var : PrevMarketPos(0);

var : netPct(0), requiredPct(0);

var : orderPlaced(false);


// 이동평균 계산

maShort = MA(C, ShortLen);

maLong = MA(C, LongLen);


// 필요한 최소 세후 수익률

requiredPct = TotalTaxPercent + 0.5; // 백분율 기준


// 골든크로스 발생 시 주문만 넣음

If CrossUp(maShort, maLong) Then

{

If MarketPosition <= 0 Then

{

// 재진입(추가진입)은 직전 진입가보다 낮을 때만 허용

If PrevMarketPos == 1 Then

{

If C < LastEntryPrice Then

{

Buy("B_MA6_20_ADD", onclose, Def);

orderPlaced = true;

}

}

Else

{

Buy("B_MA6_20_NEW", onclose, Def);

orderPlaced = true;

}

}

}


// 데드크로스 진입(숏)

If CrossDown(maShort, maLong) Then

Sell("S_MA6_20", onclose, Def);


// 포지션 체결(포지션이 0 또는 숏에서 롱으로 변경) 감지 후 평균가 갱신

If PrevMarketPos <= 0 And MarketPosition == 1 And orderPlaced == true Then

{

// 체결 가격을 현재 봉의 종가(C)로 간주

EntryCount = EntryCount + 1;

AvgEntryPrice = (AvgEntryPrice * (EntryCount - 1) + C) / EntryCount;

LastEntryPrice = C;

orderPlaced = false;

}


// 롱 청산: 데드크로스 시 평균매입가(재진입 포함 평균) 기준 세후 +0.5% 이상일 때만 청산

If MarketPosition == 1 And CrossDown(maShort, maLong) Then

{

If AvgEntryPrice > 0 Then

{

netPct = (C / AvgEntryPrice - 1) * 100; // 현재까지 총수익률(%)

// 엄격 비교: 세후 기준을 만족해야 청산

If netPct >= requiredPct Then

ExitLong("XL_MA6_20", onclose, Def);

}

}


// 숏 포지션 청산(골든크로스 발생시)

If MarketPosition == -1 And CrossUp(maShort, maLong) Then

ExitShort("XS_MA6_20", onclose, Def);


// 롱이 청산되어 플랫이 된 경우 평균가 초기화

If PrevMarketPos == 1 And MarketPosition == 0 Then

{

AvgEntryPrice = 0;

EntryCount = 0;

LastEntryPrice = 0;

orderPlaced = false;

}


// PrevMarketPos 업데이트

PrevMarketPos = MarketPosition;


// 손절/익절 설정 (틱 단위 입력, 0이면 미사용)

If StopLossTicks > 0 Then

SetStopLoss(StopLossTicks * PriceScale, PointStop);

Else

SetStopLoss(0, PointStop);


If ProfitTargetTicks > 0 Then

SetStopProfitTarget(ProfitTargetTicks * PriceScale, PointStop);

Else

SetStopProfitTarget(0, PointStop);





시스템
답변 2
프로필 이미지

예스스탁

2026-07-22 14:09:02

관리자님에 의해 삭제된 답변입니다.
프로필 이미지

예스스탁 예스스탁 답변

2026-07-22 14:20:45

안녕하세요 예스스탁입니다. 피라미딩은 모든진입신호 허용으로 설정하고 적용하셔야 합니다. 세금/수수료는 랭귀지에 리턴되지 않으므로 증권사 홈페이지에서 수수료를 확인하시고 TotalTaxPercent에 0.15%(거래세) 더해서 지정하시면 됩니다. input : ShortLen(6), LongLen(20), StopLossTicks(0), ProfitTargetTicks(0); input : TotalTaxPercent(0.0); // 세금/수수료 합계(%) var : maShort(0), maLong(0); var : requiredPct(0); // 이동평균 계산 maShort = MA(C, ShortLen); maLong = MA(C, LongLen); // 필요한 최소 세후 수익률 requiredPct = TotalTaxPercent + 0.5; // 백분율 기준 //매수진입 If CrossUp(maShort, maLong) Then { If MarketPosition == 0 or (MarketPosition == 1 and C < LatestEntryPrice(0)) Then Buy("B"); } //롱포지션 청산 If MarketPosition == 1 And CrossDown(maShort, maLong) and C >= AvgEntryPrice*(1+(requiredPct)/100) Then ExitLong("BX"); //매도진입 If CrossDown(maShort, maLong) Then { If MarketPosition == 0 or (MarketPosition == -1 and C > LatestEntryPrice(0)) Then Sell("S"); } //숏포지션 청산 If MarketPosition == -1 And CrossUp(maShort, maLong) and C >= AvgEntryPrice*(1-(requiredPct)/100) Then ExitShort("SX"); // 손절/익절 설정 (틱 단위 입력, 0이면 미사용) If StopLossTicks > 0 Then SetStopLoss(StopLossTicks * PriceScale, PointStop); Else SetStopLoss(0, PointStop); If ProfitTargetTicks > 0 Then SetStopProfitTarget(ProfitTargetTicks * PriceScale, PointStop); Else SetStopProfitTarget(0, PointStop); 즐거운 하루되세요