diff --git a/BitgetApi/IndicatorConditionSetup/SMABandConditionSetup.cs b/BitgetApi/IndicatorConditionSetup/SMABandConditionSetup.cs index 6b80c64..d0c22e9 100644 --- a/BitgetApi/IndicatorConditionSetup/SMABandConditionSetup.cs +++ b/BitgetApi/IndicatorConditionSetup/SMABandConditionSetup.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Media.Media3D; using static BitgetAPI.CommonProperty; using static DevExpress.Utils.Diagnostics.GUIResources; using static System.Windows.Forms.VisualStyles.VisualStyleElement.ToolTip; @@ -72,7 +73,7 @@ namespace BitgetApi.IndicatorConditionSetup bool isSideways = IsSideways(high, low, i); - var ichmok = GetIchimokuCloud(candles, i); + var ichmok = GetIchimokuCloud(candles, i - 25); var cloudTopNow = Math.Max(ichmok.SenkouSpanA, ichmok.SenkouSpanB); var cloudBottomNow = Math.Min(ichmok.SenkouSpanA, ichmok.SenkouSpanB); @@ -167,64 +168,56 @@ namespace BitgetApi.IndicatorConditionSetup private IchimokuResult GetIchimokuCloud(List candles, int i) { - int lastIndex = i; - - int tenkanPeriod = 9; - int kijunPeriod = 26; - int senkouBPeriod = 52; - int displacement = 26; - - var result = new IchimokuResult(); + var highs = candles.Select(t => t.High).ToList(); + var lows = candles.Select(t => t.Low).ToList(); + var closes = candles.Select(t => t.Close).ToList(); - // 전환선 계산 (현재봉 기준 9봉 범위) - if (lastIndex + 1 >= tenkanPeriod) + var result = new IchimokuResult(); + + double tenkan = 0; + double kijun = 0; + double senkouA = 0; + double senkouB = 0; + double chikou = 0; + + // Tenkan-sen (9) + if (i >= 8) { - var tenkanHigh = candles.GetRange(lastIndex + 1 - tenkanPeriod, tenkanPeriod).Max(c => c.High); - var tenkanLow = candles.GetRange(lastIndex + 1 - tenkanPeriod, tenkanPeriod).Min(c => c.Low); - result.TenkanSen = (tenkanHigh + tenkanLow) / 2; + double max9 = highs.GetRange(i - 8, 9).Max(); + double min9 = lows.GetRange(i - 8, 9).Min(); + tenkan = (max9 + min9) / 2.0; } - // 기준선 계산 (현재봉 기준 26봉 범위) - if (lastIndex + 1 >= kijunPeriod) + // Kijun-sen (26) + if (i >= 25) { - var kijunHigh = candles.GetRange(lastIndex + 1 - kijunPeriod, kijunPeriod).Max(c => c.High); - var kijunLow = candles.GetRange(lastIndex + 1 - kijunPeriod, kijunPeriod).Min(c => c.Low); - result.KijunSen = (kijunHigh + kijunLow) / 2; + double max26 = highs.GetRange(i - 25, 26).Max(); + double min26 = lows.GetRange(i - 25, 26).Min(); + kijun = (max26 + min26) / 2.0; } - // 선행스팬 A 계산: '현재봉 시점'에 표시하려면 26봉 전 값(미래 26봉이 아니라)으로 계산 - if (lastIndex + 1 >= kijunPeriod && lastIndex + 1 >= tenkanPeriod && lastIndex - displacement >= 0) + // Senkou Span A (현재 시점에서 계산만, 시프트는 X) + if (tenkan != 0 && kijun != 0) { - // 26봉 전(과거) 봉 기준으로 전환선과 기준선 다시 계산 - var spanIndex = lastIndex - displacement; - - var spanTenkanHigh = candles.GetRange(spanIndex + 1 - tenkanPeriod, tenkanPeriod).Max(c => c.High); - var spanTenkanLow = candles.GetRange(spanIndex + 1 - tenkanPeriod, tenkanPeriod).Min(c => c.Low); - var spanTenkan = (spanTenkanHigh + spanTenkanLow) / 2; - - var spanKijunHigh = candles.GetRange(spanIndex + 1 - kijunPeriod, kijunPeriod).Max(c => c.High); - var spanKijunLow = candles.GetRange(spanIndex + 1 - kijunPeriod, kijunPeriod).Min(c => c.Low); - var spanKijun = (spanKijunHigh + spanKijunLow) / 2; - - result.SenkouSpanA = (spanTenkan + spanKijun) / 2; + senkouA = (tenkan + kijun) / 2.0; } - // 선행스팬 B 계산 (26봉 전 기준 52봉 범위) - if (lastIndex + 1 >= senkouBPeriod && lastIndex - displacement >= senkouBPeriod - 1) + // Senkou Span B (52) + if (i >= 51) { - int spanIndex = lastIndex - displacement; - var spanBHigh = candles.GetRange(spanIndex + 1 - senkouBPeriod, senkouBPeriod).Max(c => c.High); - var spanBLow = candles.GetRange(spanIndex + 1 - senkouBPeriod, senkouBPeriod).Min(c => c.Low); - result.SenkouSpanB = (spanBHigh + spanBLow) / 2; + double max52 = highs.GetRange(i - 51, 52).Max(); + double min52 = lows.GetRange(i - 51, 52).Min(); + senkouB = (max52 + min52) / 2.0; } - - // 후행스팬은 26봉 전 종가 (시간 그대로) - if (lastIndex - displacement >= 0) + return new IchimokuResult { - result.ChikouSpan = candles[lastIndex - displacement].Close; - } - - return result; + TenkanSen = tenkan, + KijunSen = kijun, + SenkouSpanA = senkouA, + SenkouSpanB = senkouB, + ChikouSpan = chikou + }; + } } }