커뮤니티

문의드립니다

프로필 이미지
처음처럼22
2025-10-20 08:36:26
57
글번호 227022
답변완료

오류수정 부탁드립니다

// ===== Bollinger Re-Entry with Trend Filter (Strategy) =====

Inputs:

Length(100),

Mult(1.8),

TrendLen(120),

AllowShort(0); // 1=숏 허용, 0=롱만

Vars:

Basis(0), MeanSq(0), DevRaw(0), Dev(0),

Upper(0), Lower(0),

TrendMA(0),

BuySig(false), SellSig(false);

// --- 표준편차 수식 계산 ---

Basis = Average(Close, Length);

MeanSq = Average(Close * Close, Length);

DevRaw = SquareRoot(MaxList(0, MeanSq - Basis * Basis));

Dev = Mult * DevRaw;

Upper = Basis + Dev;

Lower = Basis - Dev;

TrendMA = Average(Close, TrendLen);

// --- 신호 ---

BuySig = CrossUp(Close, Lower) and (Close > TrendMA);

SellSig = CrossDown(Close, Upper) and (Close < TrendMA);

// --- 주문(전략) ---

// 롱 진입: 현재 포지션이 롱이 아닐 때만

If BuySig and MarketPosition <> 1 Then

Buy next bar at market;

// 숏 모드

If AllowShort = 1 Then begin

// 숏 진입: 현재 포지션이 숏이 아닐 때만

If SellSig and MarketPosition <> -1 Then

Short next bar at market;

end

Else begin

// 롱만: 롱 보유 중 & 매도 신호면 청산

If MarketPosition = 1 and SellSig Then

Sell next bar at market;

end;

TS수식변환
시스템
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-10-20 14:40:51

안녕하세요 예스스탁입니다. Inputs: Length(100), Mult(1.8), TrendLen(120), AllowShort(0); // 1=숏 허용, 0=롱만 Vars: Basis(0), MeanSq(0), DevRaw(0), Dev(0), Upper(0), Lower(0), TrendMA(0), BuySig(false), SellSig(false); // --- 표준편차 수식 계산 --- Basis = ma(Close, Length); MeanSq = ma(Close * Close, Length); DevRaw = SquareRoot(MaxList(0, MeanSq - Basis * Basis)); Dev = Mult * DevRaw; Upper = Basis + Dev; Lower = Basis - Dev; TrendMA = ma(Close, TrendLen); // --- 신호 --- BuySig = CrossUp(Close, Lower) and (Close > TrendMA); SellSig = CrossDown(Close, Upper) and (Close < TrendMA); // --- 주문(전략) --- // 롱 진입: 현재 포지션이 롱이 아닐 때만 If BuySig and MarketPosition <> 1 Then Buy("b",AtMarket); // 숏 모드 If AllowShort == 1 Then begin // 숏 진입: 현재 포지션이 숏이 아닐 때만 If SellSig and MarketPosition <> -1 Then Sell("s",AtMarket); end Else begin // 롱만: 롱 보유 중 & 매도 신호면 청산 If MarketPosition == 1 and SellSig Then ExitLong("bx",AtMarket); end; 즐거운 하루되세요