예스스탁
예스스탁 답변
2025-07-21 13:10:57
안녕하세요
예스스탁입니다.
Inputs:
factor (3), // SuperTrend ATR 배수
AtrPeriod (10), // SuperTrend ATR 기간
shortLen (12), // EMA 단기 기간
longLen (26); // EMA 장기 기간
Vars:
// SuperTrend용
src (0),
trv (0),
atrv (0),
upperBand (0),
lowerBand (0),
prevUB (0),
prevLB (0),
dir (0),
// EMA용
emaShort (0),
emaLong (0),
// 실제 SuperTrend 신호
supertrend (0);
// === 1) SuperTrend 계산 ===
If CurrentBar > 1 Then
Begin
// ATR 계산
src = (High + Low) / 2;
trv = MaxList( High - Low,
MaxList( Abs(High - Close[1]),
Abs(Low - Close[1]) ) );
atrv = EMA(trv, AtrPeriod);
// 밴드 산출
upperBand = src + factor * atrv;
lowerBand = src - factor * atrv;
prevUB = upperBand[1];
prevLB = lowerBand[1];
// 밴드 스무딩
If (lowerBand <= prevLB) And (Close[1] >= prevLB) Then
lowerBand = prevLB;
If (upperBand >= prevUB) And (Close[1] <= prevUB) Then
upperBand = prevUB;
// 추세 방향 판정
If Close > upperBand Then
dir = 1;
Else if Close < lowerBand Then
dir = -1;
// supertrend 값 결정
If dir == 1 Then
supertrend = lowerBand;
Else
supertrend = upperBand;
End;
// === 2) EMA 계산 ===
emaShort = EMA(Close, shortLen);
emaLong = EMA(Close, longLen);
// === 3) 롱/숏 진입·청산 ===
// 롱 진입: EMA 골든크로스 + price > supertrend
If MarketPosition == 0
And CrossUp(emaShort, emaLong)
And CrossUp(Close, supertrend)
Then
Buy("LongEntry");
// 롱 청산: EMA 데드크로스 + price < supertrend
If MarketPosition > 0
And CrossDown(emaShort, emaLong)
And CrossDown(Close, supertrend)
Then
ExitLong("LongExit");
// 숏 진입: EMA 데드크로스 + price < supertrend
If MarketPosition == 0
And CrossDown(emaShort, emaLong)
And CrossDown(Close, supertrend)
Then
Sell("ShortEntry");
// 숏 청산: EMA 골든크로스 + price > supertrend
If MarketPosition < 0
And CrossUp(emaShort, emaLong)
And CrossUp(Close, supertrend)
Then
ExitShort("ShortExit");
즐거운 하루되세요
> 최태수 님이 쓴 글입니다.
> 제목 : 코딩 해결 부탁드립니다!
> 담당자님 안녕하세요! 예스트레이더 슈퍼트렌드랑 12,26ema 교차를 합치고 싶습니다
롱 진입: 12,26 ema가 골든크로스 나면서 슈퍼트렌드도 롱 신호가 나올때
롱 청산: 12,26 ema가 데드크로스 나면서 슈퍼트렌드도 숏 신호가 나왔을때
숏 진입: 12,26 ema가 데드크로스 나면서 슈퍼트렌드도 숏 신호가 나올때
숏 청산: 12,26 ema가 골든크로스 나면서 슈퍼트렌드도 롱 신호가 나올때
감사합니다.
Inputs:
factor (3), // SuperTrend ATR 배수
AtrPeriod (10), // SuperTrend ATR 기간
shortLen (12), // EMA 단기 기간
longLen (26); // EMA 장기 기간
Vars:
// SuperTrend용
src (0),
trv (0),
atrv (0),
upperBand (0),
lowerBand (0),
prevUB (0),
prevLB (0),
dir (0),
// EMA용
emaShort (0),
emaLong (0),
// 실제 SuperTrend 신호
supertrend (0);
// === 1) SuperTrend 계산 ===
If CurrentBar > 1 Then
Begin
// ATR 계산
src = (High + Low) / 2;
trv = MaxList( High - Low,
MaxList( Abs(High - Close[1]),
Abs(Low - Close[1]) ) );
atrv = EMA(trv, AtrPeriod);
// 밴드 산출
upperBand = src + factor * atrv;
lowerBand = src - factor * atrv;
prevUB = upperBand[1];
prevLB = lowerBand[1];
// 밴드 스무딩
If (lowerBand <= prevLB) And (Close[1] >= prevLB) Then
lowerBand = prevLB;
If (upperBand >= prevUB) And (Close[1] <= prevUB) Then
upperBand = prevUB;
// 추세 방향 판정
If Close > upperBand Then
dir = 1
ElseIf Close < lowerBand Then
dir = -1;
// supertrend 값 결정
If dir = 1 Then
supertrend = lowerBand
Else
supertrend = upperBand;
End;
// === 2) EMA 계산 ===
emaShort = EMA(Close, shortLen);
emaLong = EMA(Close, longLen);
// === 3) 롱/숏 진입·청산 ===
// 롱 진입: EMA 골든크로스 + price > supertrend
If MarketPosition = 0
And CrossUp(emaShort, emaLong)
And CrossUp(Close, supertrend)
Then
Buy("LongEntry");
// 롱 청산: EMA 데드크로스 + price < supertrend
If MarketPosition > 0
And CrossDown(emaShort, emaLong)
And CrossDown(Close, supertrend)
Then
ExitLong("LongExit");
// 숏 진입: EMA 데드크로스 + price < supertrend
If MarketPosition = 0
And CrossDown(emaShort, emaLong)
And CrossDown(Close, supertrend)
Then
SellShort("ShortEntry");
// 숏 청산: EMA 골든크로스 + price > supertrend
If MarketPosition < 0
And CrossUp(emaShort, emaLong)
And CrossUp(Close, supertrend)
Then
ExitShort("ShortExit");