커뮤니티

부탁드립니다

프로필 이미지
파생돌이
2025-10-26 20:44:07
86
글번호 227316
답변완료

수고하십니다 아래수식을 오류 없게 수정부탁드립니다
inputs: ShortLength(50), LongLength(150), RetestSignals(false), CandleColor(true), UpperColor(Magenta), LowerColor(Blue); variables: ATRValue(0), ShortKalman(0), LongKalman(0), // Kalman filter variables for short ShortEstimate(0), ShortErrorEst(1.0), ShortKalmanGain(0), ShortPrediction(0), ShortErrorMeas(0), ShortInitialized(false), // Kalman filter variables for long LongEstimate(0), LongErrorEst(1.0), LongKalmanGain(0), LongPrediction(0), LongErrorMeas(0), LongInitialized(false), TrendUp(false), PrevTrendUp(false), TrendColor(0), TrendColor1(0), CandleCol(0), UpperBoxTop(0), UpperBoxBottom(0), UpperBoxStart(0), LowerBoxTop(0), LowerBoxBottom(0), LowerBoxStart(0), BoxActive(false), R(0.01), Q(0.1); // Calculate ATR ATRValue = AvgTrueRange(200) * 0.5; // Kalman Filter for Short Length ShortErrorMeas = R * ShortLength; if not ShortInitialized then begin ShortEstimate = Close; ShortInitialized = true; end; ShortPrediction = ShortEstimate; ShortKalmanGain = ShortErrorEst / (ShortErrorEst + ShortErrorMeas); ShortEstimate = ShortPrediction + ShortKalmanGain * (Close - ShortPrediction); ShortErrorEst = (1 - ShortKalmanGain) * ShortErrorEst + Q / ShortLength; ShortKalman = ShortEstimate; // Kalman Filter for Long Length LongErrorMeas = R * LongLength; if not LongInitialized then begin LongEstimate = Close; LongInitialized = true; end; LongPrediction = LongEstimate; LongKalmanGain = LongErrorEst / (LongErrorEst + LongErrorMeas); LongEstimate = LongPrediction + LongKalmanGain * (Close - LongPrediction); LongErrorEst = (1 - LongKalmanGain) * LongErrorEst + Q / LongLength; LongKalman = LongEstimate; // Determine trend PrevTrendUp = TrendUp; TrendUp = ShortKalman > LongKalman; // Set colors if TrendUp then TrendColor = UpperColor else TrendColor = LowerColor; if ShortKalman > ShortKalman[2] then TrendColor1 = UpperColor else TrendColor1 = LowerColor; // Candle coloring if CandleColor then begin if TrendUp and ShortKalman > ShortKalman[2] then CandleCol = UpperColor else if not TrendUp and ShortKalman < ShortKalman[2] then CandleCol = LowerColor else CandleCol = DarkGray; end; // Plot Kalman filters Plot1(ShortKalman, "Short Kalman", TrendColor1); Plot2(LongKalman, "Long Kalman", TrendColor); // Trend change detection and signals if TrendUp and not PrevTrendUp then begin // Uptrend signal Text_New(Date, Time, Low, "UP"); // Create lower box LowerBoxStart = CurrentBar; LowerBoxTop = Low + ATRValue; LowerBoxBottom = Low; BoxActive = true; end; if not TrendUp and PrevTrendUp then begin // Downtrend signal Text_New(Date, Time, High, "DN"); // Create upper box UpperBoxStart = CurrentBar; UpperBoxTop = High; UpperBoxBottom = High - ATRValue; BoxActive = true; end; // Retest signals if RetestSignals then begin if not TrendUp and BoxActive then begin if High < UpperBoxBottom and High[1] >= UpperBoxBottom then Text_New(Date, Time, High[1], "x"); end; if TrendUp and BoxActive then begin if Low > LowerBoxTop and Low[1] <= LowerBoxTop then Text_New(Date, Time, Low[1], "+"); end; end; // Apply candle coloring if CandleColor then PlotPB(Open, High, Low, Close, CandleCol, CandleCol);

지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-10-27 16:57:17

안녕하세요. 예스스탁입니다. inputs: ShortLength(50), LongLength(150), RetestSignals(false), CandleColor(true), UpperColor(Magenta), LowerColor(Blue); variables: ATRValue(0), ShortKalman(0), LongKalman(0), // Kalman filter variables for short ShortEstimate(0), ShortErrorEst(1.0), ShortKalmanGain(0), ShortPrediction(0), ShortErrorMeas(0), ShortInitialized(false), // Kalman filter variables for long LongEstimate(0), LongErrorEst(1.0), LongKalmanGain(0), LongPrediction(0), LongErrorMeas(0), LongInitialized(false), TrendUp(false), PrevTrendUp(false), TrendColor(0), TrendColor1(0), CandleCol(0), UpperBoxTop(0), UpperBoxBottom(0), UpperBoxStart(0), LowerBoxTop(0), LowerBoxBottom(0), LowerBoxStart(0), BoxActive(false), R(0.01), Q(0.1); // Calculate ATR ATRValue = ATR(200) * 0.5; // Kalman Filter for Short Length ShortErrorMeas = R * ShortLength; if ShortInitialized == False then begin ShortEstimate = Close; ShortInitialized = true; end; ShortPrediction = ShortEstimate; ShortKalmanGain = ShortErrorEst / (ShortErrorEst + ShortErrorMeas); ShortEstimate = ShortPrediction + ShortKalmanGain * (Close - ShortPrediction); ShortErrorEst = (1 - ShortKalmanGain) * ShortErrorEst + Q / ShortLength; ShortKalman = ShortEstimate; // Kalman Filter for Long Length LongErrorMeas = R * LongLength; if LongInitialized == False then begin LongEstimate = Close; LongInitialized = true; end; LongPrediction = LongEstimate; LongKalmanGain = LongErrorEst / (LongErrorEst + LongErrorMeas); LongEstimate = LongPrediction + LongKalmanGain * (Close - LongPrediction); LongErrorEst = (1 - LongKalmanGain) * LongErrorEst + Q / LongLength; LongKalman = LongEstimate; // Determine trend PrevTrendUp = TrendUp; TrendUp = ShortKalman > LongKalman; // Set colors if TrendUp then TrendColor = UpperColor; else TrendColor = LowerColor; if ShortKalman > ShortKalman[2] then TrendColor1 = UpperColor; else TrendColor1 = LowerColor; // Candle coloring if CandleColor then begin if TrendUp and ShortKalman > ShortKalman[2] then CandleCol = UpperColor; else if TrendUp == False and ShortKalman < ShortKalman[2] then CandleCol = LowerColor; else CandleCol = DarkGray; end; // Plot Kalman filters Plot1(ShortKalman, "Short Kalman", TrendColor1); Plot2(LongKalman, "Long Kalman", TrendColor); // Trend change detection and signals if TrendUp and PrevTrendUp == False then begin // Uptrend signal Text_New(Date, Time, Low, "UP"); // Create lower box LowerBoxStart = CurrentBar; LowerBoxTop = Low + ATRValue; LowerBoxBottom = Low; BoxActive = true; end; if TrendUp == False and PrevTrendUp then begin // Downtrend signal Text_New(Date, Time, High, "DN"); // Create upper box UpperBoxStart = CurrentBar; UpperBoxTop = High; UpperBoxBottom = High - ATRValue; BoxActive = true; end; // Retest signals if RetestSignals then begin if TrendUp == False and BoxActive then begin if High < UpperBoxBottom and High[1] >= UpperBoxBottom then Text_New(Date, Time, High[1], "x"); end; if TrendUp and BoxActive then begin if Low > LowerBoxTop and Low[1] <= LowerBoxTop then Text_New(Date, Time, Low[1], "+"); end; end; 즐거운 하루되세요