커뮤니티
시스템수식 오류 가르침 요청
아래시스템트레이딩 코드에
/=========================================== // 1. 지표 계산 //
============== RSI_Current := RSI(Close, RSI_Period); 에 잘못된 문법이라고 합니다.
수정 후 전체코드를 다시 주시길 간곡히 부탁을 드립니다.
Inputs:
RSI_Period(14),
MACD_Fast(12),
MACD_Slow(26),
MACD_Signal(9),
BB_Period(20),
BB_Dev(2),
DivBars(5),
RSI_BuyLevel(30),
RSI_SellLevel(70);
Variables:
// RSI
RSI_Current(0), RSI_PrevLow(0), RSI_PrevHigh(0),
// MACD
MACD_Main(0), MACD_Signal_Line(0),
MACD_Main_Prev(0), MACD_Signal_Prev(0),
// Bollinger Bands
BB_Upper(0), BB_Lower(0),
BB_Upper_Prev(0), BB_Lower_Prev(0),
// Divergence Detection
Price_Low1(0), Price_Low2(0), RSI_Low1(0), RSI_Low2(0), Bullish_Div(0),
Price_High1(0), Price_High2(0), RSI_High1(0), RSI_High2(0), Bearish_Div(0),
// Index for Lowest/Highest
Low1_Idx(0), Low2_Idx(0), High1_Idx(0), High2_Idx(0),
// Conditions
MACD_Cross_Up(0), MACD_Cross_Down(0),
Touch_Lower_BB(0), Touch_Upper_BB(0),
Buy_Signal(0), Sell_Signal(0);
//===================================================================
// 1. 지표 계산
//===================================================================
RSI_Current := RSI(Close, RSI_Period);
MACD_Main := MACD(Close, MACD_Fast, MACD_Slow, MACD_Signal, 0);
MACD_Signal_Line := MACD(Close, MACD_Fast, MACD_Slow, MACD_Signal, 1);
MACD_Main_Prev := MACD(Close, MACD_Fast, MACD_Slow, MACD_Signal, 0)[1];
MACD_Signal_Prev := MACD(Close, MACD_Fast, MACD_Slow, MACD_Signal, 1)[1];
BB_Upper := BollingerBand(Close, BB_Period, BB_Dev, 1);
BB_Lower := BollingerBand(Close, BB_Period, BB_Dev, 2);
BB_Upper_Prev := BollingerBand(Close, BB_Period, BB_Dev, 1)[1];
BB_Lower_Prev := BollingerBand(Close, BB_Period, BB_Dev, 2)[1];
//===================================================================
// 2. 다이버전스 감지 (Bullish & Bearish)
//===================================================================
// Bullish Divergence: 가격은 낮은 저점, RSI는 높은 저점
Low1_Idx := LowestBar(Low, DivBars, 1);
Low2_Idx := LowestBar(Low, DivBars, DivBars+1);
Price_Low1 := Low[Low1_Idx];
Price_Low2 := Low[Low2_Idx];
RSI_Low1 := RSI(Close, RSI_Period)[Low1_Idx];
RSI_Low2 := RSI(Close, RSI_Period)[Low2_Idx];
Bullish_Div := (Price_Low1 < Price_Low2) And (RSI_Low1 > RSI_Low2);
// Bearish Divergence: 가격은 높은 고점, RSI는 낮은 고점
High1_Idx := HighestBar(High, DivBars, 1);
High2_Idx := HighestBar(High, DivBars, DivBars+1);
Price_High1 := High[High1_Idx];
Price_High2 := High[High2_Idx];
RSI_High1 := RSI(Close, RSI_Period)[High1_Idx];
RSI_High2 := RSI(Close, RSI_Period)[High2_Idx];
Bearish_Div := (Price_High1 > Price_High2) And (RSI_High1 < RSI_High2);
//===================================================================
// 3. MACD 크로스
//===================================================================
MACD_Cross_Up := (MACD_Main_Prev <= MACD_Signal_Prev) And (MACD_Main > MACD_Signal_Line);
MACD_Cross_Down := (MACD_Main_Prev >= MACD_Signal_Prev) And (MACD_Main < MACD_Signal_Line);
//===================================================================
// 4. 볼린저 밴드 터치 후 반등/하락
//===================================================================
Touch_Lower_BB := (Low[1] <= BB_Lower_Prev) And (Close[1] > BB_Lower_Prev);
Touch_Upper_BB := (High[1] >= BB_Upper_Prev) And (Close[1] < BB_Upper_Prev);
//===================================================================
// 5. 최종 매수/매도 신호
//===================================================================
Buy_Signal := (RSI_Current > RSI_BuyLevel) And MACD_Cross_Up And Touch_Lower_BB And Bullish_Div;
Sell_Signal := (RSI_Current < RSI_SellLevel) And MACD_Cross_Down And Touch_Upper_BB And Bearish_Div;
//===================================================================
// 6. 주문 실행 (자동매매 연동용)
//===================================================================
If Buy_Signal Then
Begin
Buy("BTC_5M_BULL");
End;
If Sell_Signal Then
Begin
Sell("BTC_5M_BEAR");
End;
답변 1
예스스탁 예스스탁 답변
2025-10-24 18:17:16