커뮤니티

안녕하세요. 코딩 수정 부탁드립니다!

프로필 이미지
최태수
2025-08-06 21:32:42
155
글번호 193054
답변완료
Inputs: factor (3), // SuperTrend ATR 배수 AtrPeriod (14), // SuperTrend ATR 기간 shortLen (12), // EMA 단기 기간 longLen (26); // EMA 장기 기간 Vars: src (0), trv (0), atrv (0), upperBand (0), lowerBand (0), prevUB (0), prevLB (0), dir (0), supertrend (0), emaShort (0), emaLong (0); // === SuperTrend 계산 === if CurrentBar > 1 then { 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; if dir == 1 then supertrend = lowerBand; else supertrend = upperBand; } // === EMA 계산 === emaShort = EMA(Close, shortLen); emaLong = EMA(Close, longLen); // === 상태 기반 진입·청산 === // 롱 진입: 포지션 없고 EMA > & 가격 > SuperTrend if MarketPosition == 0 and emaShort > emaLong and Close > supertrend then { Buy("LongEntry"); } // 롱 청산: 롱 보유 중 EMA < & 가격 < SuperTrend if MarketPosition > 0 and emaShort < emaLong and Close < supertrend then { ExitLong("LongExit"); } // 숏 진입: 포지션 없고 EMA < & 가격 < SuperTrend if MarketPosition == 0 and emaShort < emaLong and Close < supertrend then { Sell("ShortEntry"); } // 숏 청산: 숏 보유 중 EMA > & 가격 > SuperTrend if MarketPosition < 0 and emaShort > emaLong and Close > supertrend then { ExitShort("ShortExit"); } 담당자님 안녕하세요. 항상 고생많으십니다. 현재 스위칭 진입,청산 전략을 사용하고 있습니다. 예를 들어 매수 후 매도 청산 -> 다음봉에서 다시 매도진입 이런식으로 되는데 혹시 청산하면서 그 봉에서 바로 스위칭 진입하는 코딩으로 만들어 주실 수 있으실까요?? 매수 후 매도 청산 -> 그 봉에 종가에서 바로 매도 진입 매도 후 매수 청산 -> 그 봉에 종가에서 바로 매수 진입 이렇게 부탁드리겠습니다! 감사합니다.
시스템
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-08-07 12:45:26

안녕하세요 예스스탁입니다. Inputs: factor (3), // SuperTrend ATR 배수 AtrPeriod (14), // SuperTrend ATR 기간 shortLen (12), // EMA 단기 기간 longLen (26); // EMA 장기 기간 Vars: src (0), trv (0), atrv (0), upperBand (0), lowerBand (0), prevUB (0), prevLB (0), dir (0), supertrend (0), emaShort (0), emaLong (0); // === SuperTrend 계산 === if CurrentBar > 1 then { 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; if dir == 1 then supertrend = lowerBand; else supertrend = upperBand; } // === EMA 계산 === emaShort = EMA(Close, shortLen); emaLong = EMA(Close, longLen); // === 상태 기반 진입·청산 === // 롱 진입: 포지션 없고 EMA > & 가격 > SuperTrend if MarketPosition <= 0 and emaShort > emaLong and Close > supertrend then { Buy("LongEntry"); } // 숏 진입: 포지션 없고 EMA < & 가격 < SuperTrend if MarketPosition >= 0 and emaShort < emaLong and Close < supertrend then { Sell("ShortEntry"); } 즐거운 하루되세요 > 최태수 님이 쓴 글입니다. > 제목 : 안녕하세요. 코딩 수정 부탁드립니다! > Inputs: factor (3), // SuperTrend ATR 배수 AtrPeriod (14), // SuperTrend ATR 기간 shortLen (12), // EMA 단기 기간 longLen (26); // EMA 장기 기간 Vars: src (0), trv (0), atrv (0), upperBand (0), lowerBand (0), prevUB (0), prevLB (0), dir (0), supertrend (0), emaShort (0), emaLong (0); // === SuperTrend 계산 === if CurrentBar > 1 then { 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; if dir == 1 then supertrend = lowerBand; else supertrend = upperBand; } // === EMA 계산 === emaShort = EMA(Close, shortLen); emaLong = EMA(Close, longLen); // === 상태 기반 진입·청산 === // 롱 진입: 포지션 없고 EMA > & 가격 > SuperTrend if MarketPosition == 0 and emaShort > emaLong and Close > supertrend then { Buy("LongEntry"); } // 롱 청산: 롱 보유 중 EMA < & 가격 < SuperTrend if MarketPosition > 0 and emaShort < emaLong and Close < supertrend then { ExitLong("LongExit"); } // 숏 진입: 포지션 없고 EMA < & 가격 < SuperTrend if MarketPosition == 0 and emaShort < emaLong and Close < supertrend then { Sell("ShortEntry"); } // 숏 청산: 숏 보유 중 EMA > & 가격 > SuperTrend if MarketPosition < 0 and emaShort > emaLong and Close > supertrend then { ExitShort("ShortExit"); } 담당자님 안녕하세요. 항상 고생많으십니다. 현재 스위칭 진입,청산 전략을 사용하고 있습니다. 예를 들어 매수 후 매도 청산 -> 다음봉에서 다시 매도진입 이런식으로 되는데 혹시 청산하면서 그 봉에서 바로 스위칭 진입하는 코딩으로 만들어 주실 수 있으실까요?? 매수 후 매도 청산 -> 그 봉에 종가에서 바로 매도 진입 매도 후 매수 청산 -> 그 봉에 종가에서 바로 매수 진입 이렇게 부탁드리겠습니다! 감사합니다.