커뮤니티

아래 내용 수정 부탁합니다. 실행이 안됩니다

프로필 이미지
호시우보
2025-11-26 15:39:57
106
글번호 228436
답변완료

// ─────────────────────────────────────────────

// 고변동성 최적화 버전 (SMA20 / RSI5)

// 1차 진입 → 실패 시 역추세 마틴 진입(2배)

// ─────────────────────────────────────────────

// 사용자 설정값

input : P(20); // SMA 기간

input : RSIlen(5); // RSI 기간

input : StopPoint(1.0); // 기본 손절 1.0pt

input : TakePoint(1.0); // 기본 익절 1.0pt

// 변수 선언

var : sma20(0), rsi5(0), atr14(0);

var : longCond(false), shortCond(false);

var : entryPrice(0), martin(false);

// ─────────────────────────────

// 계산식

// ─────────────────────────────

sma20 = average(Close, P);

rsi5 = RSI(Close, RSIlen);

atr14 = AvgTrueRange(14);

// ─────────────────────────────

// 변동성 필터 (전일 대비 40%↑)

// ─────────────────────────────

if (atr14 > atr14[1] * 1.40) then begin

// 변동성 과다 → 트레이딩 중단

longCond = false;

shortCond = false;

end

else begin

// 정상 구간에서만 신호 활성화

// ─────────────────────────────

// 1차 진입 조건

// ─────────────────────────────

// 상승 매수 조건

longCond = (Close > sma20) and

(Close > Highest(High, 3)[1]) and // 직전 3봉 고점 돌파 종가 기준

(rsi5 > 45 and rsi5 < 70); // RSI 중립 구간 진입 시만

// 하락 매도 조건

shortCond = (Close < sma20) and

(Close < Lowest(Low, 3)[1]) and // 직전 3봉 저점 돌파

(rsi5 < 55 and rsi5 > 30);

end;

// ─────────────────────────────

// 1차 진입 로직

// ─────────────────────────────

if (marketposition = 0 and not martin) then begin

if longCond then begin

buy(1) next bar at market;

entryPrice = Close;

end;

if shortCond then begin

sellshort(1) next bar at market;

entryPrice = Close;

end;

end;

// ─────────────────────────────

// 1차 손절·익절

// 손절폭은 변동성 장 대응으로 1.8배

// ─────────────────────────────

if (marketposition = 1 and not martin) then begin

sell("1_LS") next bar at entryPrice - StopPoint*1.8 stop;

sell("1_LTP") next bar at entryPrice + TakePoint limit;

end;

if (marketposition = -1 and not martin) then begin

buytocover("1_SS") next bar at entryPrice + StopPoint*1.8 stop;

buytocover("1_STP") next bar at entryPrice - TakePoint limit;

end;

// ─────────────────────────────

// 1차 손절 후 2차 (마틴) 역추세 진입

// RSI 반전 + 반대방향 돌파 조합

// ─────────────────────────────

if (marketposition = 0 and martin = false) then begin

// 1차가 매수였을 경우 → 매도 마틴

if (Close < entryPrice - StopPoint*1.8) and (rsi5 < 50) then begin

sellshort(2) next bar at market;

martin = true;

entryPrice = Close;

end;

// 1차가 매도였을 경우 → 매수 마틴

if (Close > entryPrice + StopPoint*1.8) and (rsi5 > 50) then begin

buy(2) next bar at market;

martin = true;

entryPrice = Close;

end;

end;

// ─────────────────────────────

// 2차 마틴 손절·익절 (손절폭 2.2배)

// 수량은 2배 진입이므로 리스크 관리 주의

// ─────────────────────────────

if (marketposition = 1 and martin) then begin

sell("2_LS") next bar at entryPrice - StopPoint*2.2 stop;

sell("2_LTP") next bar at entryPrice + TakePoint limit;

end;

if (marketposition = -1 and martin) then begin

buytocover("2_SS") next bar at entryPrice + StopPoint*2.2 stop;

buytocover("2_STP") next bar at entryPrice - TakePoint limit;

end;

// ─────────────────────────────

// 포지션 종료 시 마틴 초기화

// ─────────────────────────────

if (marketposition = 0) then martin = false;

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

예스스탁 예스스탁 답변

2025-11-26 16:00:32

안녕하세요 예스스탁입니다. 예스랭귀지 시스템으로 변환해 드립니다. // ───────────────────────────────────────────── // 고변동성 최적화 버전 (SMA20 / RSI5) // 1차 진입 → 실패 시 역추세 마틴 진입(2배) // ───────────────────────────────────────────── // 사용자 설정값 input : P(20); // SMA 기간 input : RSIlen(5); // RSI 기간 input : StopPoint(1.0); // 기본 손절 1.0pt input : TakePoint(1.0); // 기본 익절 1.0pt // 변수 선언 var : sma20(0), rsi5(0), atr14(0); var : longCond(false), shortCond(false); var : ep(0), martin(false); // ───────────────────────────── // 계산식 // ───────────────────────────── sma20 = ma(Close, P); rsi5 = RSI(RSIlen); atr14 = ATR(14); // ───────────────────────────── // 변동성 필터 (전일 대비 40%↑) // ───────────────────────────── if (atr14 > atr14[1] * 1.40) then begin // 변동성 과다 → 트레이딩 중단 longCond = false; shortCond = false; end else begin // 정상 구간에서만 신호 활성화 // ───────────────────────────── // 1차 진입 조건 // ───────────────────────────── // 상승 매수 조건 longCond = (Close > sma20) and (Close > Highest(High, 3)[1]) and // 직전 3봉 고점 돌파 종가 기준 (rsi5 > 45 and rsi5 < 70); // RSI 중립 구간 진입 시만 // 하락 매도 조건 shortCond = (Close < sma20) and (Close < Lowest(Low, 3)[1]) and // 직전 3봉 저점 돌파 (rsi5 < 55 and rsi5 > 30); end; // ───────────────────────────── // 1차 진입 로직 // ───────────────────────────── if (marketposition == 0 and martin == False) then begin if longCond then begin buy("b",AtMarket); ep = Close; end; if shortCond then begin sell("s",AtMarket); ep = Close; end; end; // ───────────────────────────── // 1차 손절·익절 // 손절폭은 변동성 장 대응으로 1.8배 // ───────────────────────────── if (marketposition == 1 and martin == False) then begin ExitLong("1_LS",AtStop,ep - StopPoint*1.8); ExitLong("1_LTP",AtLimit,ep + TakePoint); end; if (marketposition == -1 and martin == False) then begin ExitShort("1_SS",AtStop,ep + StopPoint*1.8); ExitShort("1_STP",AtLimit,ep - TakePoint); end; // ───────────────────────────── // 1차 손절 후 2차 (마틴) 역추세 진입 // RSI 반전 + 반대방향 돌파 조합 // ───────────────────────────── if (marketposition == 0 and martin == false) then begin // 1차가 매수였을 경우 → 매도 마틴 if (Close < ep - StopPoint*1.8) and (rsi5 < 50) then begin sell("s2",atmarket); martin = true; ep = Close; end; // 1차가 매도였을 경우 → 매수 마틴 if (Close > ep + StopPoint*1.8) and (rsi5 > 50) then begin buy("b2",atmarket); martin = true; ep = Close; end; end; // ───────────────────────────── // 2차 마틴 손절·익절 (손절폭 2.2배) // 수량은 2배 진입이므로 리스크 관리 주의 // ───────────────────────────── if (marketposition == 1 and martin) then begin ExitLong("2_LS",AtStop,ep - StopPoint*2.2); ExitLong("2_LTP",AtLimit,ep + TakePoint); end; if (marketposition == -1 and martin) then begin ExitShort("2_SS",AtStop,ep + StopPoint*2.2); ExitShort("2_STP",AtStop,ep - TakePoint); end; // ───────────────────────────── // 포지션 종료 시 마틴 초기화 // ───────────────────────────── if (marketposition == 0) then martin = false; 즐거운 하루되세요