커뮤니티

예스랭귀지 Q&A

글쓰기
답변완료

번호 추가 좀 요청 드림니다.

ㅇ 매번 도움에 고맙습니다. ㅇ 아래 수식에서 그림 처럼 선이 생기면 번호 부여좀 부탁 드림니다. ㅇ 글자크기 : 30 이상 상승 빨강색 하락 블루 ## 아래 수식 var : TX(0); input : P(20),n(5),틱(20), 굵기(5); var : cnt(0),LL(0),HH(0); Array : LTL[10](0),HTL[10](0),LI[10](0),HI[10](0),Lv[10](0),Hv[10](0);; var : LTL1(0),LTL2(0),LTL3(0),LTL4(0),LTL5(0),LTL6(0); var : HTL1(0),HTL2(0),HTL3(0),HTL4(0),HTL5(0),HTL6(0); if L < Lowest(L,P)[1] and (LL == 0 or (LL > 0 and abs(L-LL) >= PriceScale*틱)) Then { LL = L; For cnt = 9 DownTo 1 { LTL[cnt] = LTL[cnt-1]; Li[cnt] = Li[cnt-1]; Lv[cnt] = Lv[cnt-1]; } LTL[0] = TL_new(sDate,sTime,LL-PriceScale*0,NextBarSdate,NextBarStime,LL-PriceScale*0); Lv[0] = LL; Li[0] = Index; TL_SetColor(LTL[0],RgB(0,0,0)); TL_SetSize(LTL[0],굵기); TL_Delete(LTL[n]); } Else { TL_SetEnd(LTL[0],NextBarSdate,NextBarStime,LL[0]-PriceScale*0); } if H > highest(H,P)[1] and (HH == 0 or (HH > 0 and abs(H-HH) >= PriceScale*틱)) Then { HH = H; For cnt = 9 DownTo 1 { HTL[cnt] = HTL[cnt-1]; Hi[cnt] = Hi[cnt-1]; Hv[cnt] = Hv[cnt-1]; } HTL[0] = TL_new(sDate,sTime,HH+PriceScale*0,NextBarSdate,NextBarStime,HH+PriceScale*0); Hv[0] = HH+PriceScale*0; Hi[0] = Index; TL_SetColor(HTL[0],RgB(255,0,0)); TL_SetSize(HTL[0],굵기); TL_Delete(HTL[n]); } Else { TL_SetEnd(HTL[0],NextBarSdate,NextBarStime,HH+PriceScale*0); } For cnt = 1 to n-1 { if LL[cnt] > 0 and Index <= Li[cnt]+5 Then TL_SetEnd(LTL[cnt],NextBarSdate,NextBarStime,Lv[cnt]); if HH[cnt] > 0 and Index <= Hi[cnt]+5 Then TL_SetEnd(HTL[cnt],NextBarSdate,NextBarStime,Hv[cnt]); } ㅇ 고맙습니다.
프로필 이미지
요타
2025-10-26
94
글번호 227319
지표
답변완료

K-means 클러스터링(K-means clustering)

5일(기본입력값) 고가 돌파매수 저가 이탈매도 지표식을 AI(클러스터링) 방식으로 동적으로 선택하도록 설계한 예스트레이더용 구현 템플릿을 AI 질문했더니아래처럼 제공했습니다만 예스랭귀지에 사용 부적합인지라iM증권 예스트레이더에 부합하는 코드로 변환을 부탁드립니다.// === 입력값 ===input minN = 3input maxN = 10input stepN = 1input perfMemory = 10 // 지수평활(미사용 시 단순평가)input fromCluster = "Best" // "Best" / "Average" / "Worst"input maxIter = 100input maxBars = 1000 // 과거 평가용 봉 수input defaultN = 5 // 안전 기본값// === 후보 N 목록 생성 ===var array<int> candN = array.new()for n = minN to maxN step stepN array.push(candN, n)endfor// === 각 후보의 퍼포먼스 계산 (단순 누적 수익) ===var array<float> perfList = array.new()var array<int> factorList = array.new()// 현재 BAR_COUNT(플랫폼에 따라 이름 다를 수 있음)barsToEvaluate = min(barcount(), maxBars)// for each candidate N, 시뮬레이션for idx = 0 to array.size(candN)-1 N = array.get(candN, idx) cash = 0.0 position = 0 // 0=flat, 1=long entry_price = 0.0 // 시간 흐름: 오래된 -> 최신 (플랫폼 루프 방법에 따라 조정) // 여기서는 i는 과거 offset (barsToEvaluate downto 1) for offset = barsToEvaluate down to 1 // 전봉 기준 N기간 최고/최저 (함수명: HHV / LLV 또는 highest/lowest 로 바꿔서 사용) hh = HHV(high, N, offset) // = offset번째 시점에서의 N기간 최고 (함수명 확인 필요) ll = LLV(low, N, offset) // 현재 바의 종가 (offset 시점) c = ref(close, offset) // 진입: 종가가 전봉 기준 N기간 최고 돌파 (전략 규칙) if position == 0 and c > hh position = 1 entry_price = c endif // 청산: 포지션 중 저가 이탈 if position == 1 and c < ll profit = c - entry_price cash = cash + profit position = 0 entry_price = 0.0 endif endfor // 시뮬레이션 종료 시 미청산 포지션 정리(평가 목적) if position == 1 last_close = close // 최신 종가 cash = cash + (last_close - entry_price) endif array.push(perfList, cash) array.push(factorList, N)endfor// === 퍼포먼스 값에서 초기 centroid 계산 (25/50/75 percentile) ===// 플랫폼에 percentile 함수가 없다면 간단 정렬 후 인덱스로 대체 가능perf_sorted = array.copy(perfList)array.sort(perf_sorted) // 오름차순sizeP = array.size(perf_sorted)p25_idx = max(0, floor(0.25 * (sizeP - 1)))p50_idx = max(0, floor(0.50 * (sizeP - 1)))p75_idx = max(0, floor(0.75 * (sizeP - 1)))centroids = array.new()array.push(centroids, array.get(perf_sorted, p25_idx))array.push(centroids, array.get(perf_sorted, p50_idx))array.push(centroids, array.get(perf_sorted, p75_idx))// === K-means 1D 반복 ===for iter = 1 to maxIter // 초기화 clusters_perf = array.from(array.new(), array.new(), array.new()) clusters_factor = array.from(array.new(), array.new(), array.new()) // 할당 단계 for i = 0 to array.size(perfList)-1 val = array.get(perfList, i) // 거리 계산 d0 = abs(val - array.get(centroids, 0)) d1 = abs(val - array.get(centroids, 1)) d2 = abs(val - array.get(centroids, 2)) // 가장 작은 거리 인덱스 선택 idx_min = 0 if d1 < d0 idx_min = 1 if d2 < d1 idx_min = 2 endif else if d2 < d0 idx_min = 2 endif endif // 클러스터에 추가 array.push(array.get(clusters_perf, idx_min), val) array.push(array.get(clusters_factor, idx_min), array.get(factorList, i)) endfor // 중심 재계산 new_centroids = array.new() for k = 0 to 2 cperf = array.get(clusters_perf, k) if array.size(cperf) > 0 sumv = 0.0 for j = 0 to array.size(cperf)-1 sumv = sumv + array.get(cperf, j) endfor avgv = sumv / array.size(cperf) array.push(new_centroids, avgv) else // 빈 클러스터는 기존 centroid 유지 array.push(new_centroids, array.get(centroids, k)) endif endfor // 수렴 체크 (모두 같다면 종료) if array.get(new_centroids,0) == array.get(centroids,0) and array.get(new_centroids,1) == array.get(centroids,1) and array.get(new_centroids,2) == array.get(centroids,2) break endif centroids := new_centroidsendfor// === 선택 클러스터 매핑 ('Worst'=0, 'Average'=1, 'Best'=2) ===selIdx = 2if fromCluster == "Worst" then selIdx = 0 endifif fromCluster == "Average" then selIdx = 1 endif// 선택 클러스터의 평균 N 계산 (없으면 기본값)chosenN = defaultNsel_factors = array.get(clusters_factor, selIdx)if array.size(sel_factors) > 0 ssum = 0 for i = 0 to array.size(sel_factors)-1 ssum = ssum + array.get(sel_factors, i) endfor chosenN = round(ssum / array.size(sel_factors))endif// === 실시간 시그널: chosenN 사용 ===// 최신 N기간 최고/최저 계산 (함수명 HHV/LLV 사용)curr_hh = HHV(high, chosenN)curr_ll = LLV(low, chosenN)buySignal = close > curr_hhsellSignal = close < curr_ll// 출력(화면 및 알림용)plot_int("ChosenN", chosenN)plot_bool("Buy", buySignal)plot_bool("Sell", sellSignal)// 실제 주문/포지션 관리는 전략 엔진 규칙에 맞춰 작성
프로필 이미지
dedoyes
2025-10-26
90
글번호 227318
지표
답변완료

부탁드립니다

수고하십니다 아래수식을 오류 없게 수정부탁드립니다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 ATRATRValue = AvgTrueRange(200) * 0.5;// Kalman Filter for Short LengthShortErrorMeas = 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 LengthLongErrorMeas = 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 trendPrevTrendUp = TrendUp;TrendUp = ShortKalman > LongKalman;// Set colorsif TrendUp then TrendColor = UpperColorelse TrendColor = LowerColor;if ShortKalman > ShortKalman[2] then TrendColor1 = UpperColorelse TrendColor1 = LowerColor;// Candle coloringif 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 filtersPlot1(ShortKalman, "Short Kalman", TrendColor1);Plot2(LongKalman, "Long Kalman", TrendColor);// Trend change detection and signalsif 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 signalsif 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 coloringif CandleColor then PlotPB(Open, High, Low, Close, CandleCol, CandleCol);
프로필 이미지
파생돌이
2025-10-26
95
글번호 227316
지표
답변완료

키움수식 변환

항상 감사드립니다 아래 키움식을 변환해 주시기 바랍니다 *** 키움식*** 1_1.저점매수(단순) BB=BBandsDown(20,2); A20=ma(c,20,단순); A5=ma(c,5,단순); R=RSI(14); c(1)<BB(1) and c(1)<A5(1) and A20(1)>A5(1) and R(1)<30 and c>A5 and c>BB and R>=30 **시스템 :위조건 만족시 매수신호 **지표: 위조건 만족시 +1(돌파봉만) /기준선0**강조표시(YELLOW)1_2.저점매수(가중) BB=BBandsDown(20,2); A20=ma(c,20,가중); A5=ma(c,5,가중); R=RSI(14); c(1)<BB(1) and c(1)<A5(1) and A20(1)>A5(1) and R(1)<30 and c>A5 and c>BB and R>=30 **시스템 :위조건 만족시 매수신호 **지표: 위조건 만족시 +1(돌파봉만) /기준선0 2.super T (매도)S = supertrend(20, 3); M = ma(C, 20); 조건 = M>M(1) && CrossUp(S, M); bs = BarsSince(조건); bs > 0 && CrossDown(S, M) && M > M(1) && C(1) < S(1) **시스템 :위조건 만족시 매도신호 **지표: 위조건 만족시 -1(돌파봉만) /기준선0 3.추돌매수시그널 손 = ma(C, 5); 절 = ma(C, 20); 가 = CrossUp(손, 절); 최고 = HighestSince(1, 가, H); 최고가 = Valuewhen(1, 최고==최고(1) &&최고>H, 최고); 최저=if(절>L, 1, 0); 최저가 = sum(최저); 결론 = 최저가-valuewhen(1,가,최저가(1)); 조건 = crossup(c, 최고가) && 결론>0; 카운트 = countsince(가, 조건)==1; 카운트 && !카운트(1) **시스템 :위조건 만족시 매수신호 **지표: 위조건 만족시 +1(돌파봉만) /기준선0 4. 3분슈퍼추세전환 crossup(c,c(5)) and crossup(c,c(60)) and O<C and V(1)*5<=V **시스템 :위조건 만족시 매수신호 **지표: 위조건 만족시 +1(돌파봉만) /기준선05. 급등전 선취매S=sum(1);M=ma(C,기간);MH=valuewhen(1,M>M(1), M);HH=HighestSince(1, crossup(S, 전체봉수-표시봉수), MH);CrossUP(C,HH) &&HH=HH(1) && HH(1)==HH(2)-전체봉수:600-기간:25-표시봉수:120**시스템 :위조건 만족시 매수신호 **지표: 위조건 만족시 +1(돌파봉만) /기준선06.황금선라인 돌파시그널M = BBandsUP(30, 1.8);LL = Lowest(M, 기간);HH = Highest(M, 기간);NL = Valuewhen(1, M<LL(1),M);Valuewhen(1,BarsSince(M<LL(1))==(기간-k),NL);CrossUp(C,NL)-기간:5-k:2**시스템 :위조건 만족시 매수신호 **지표: 위조건 만족시 +1(돌파봉만) /기준선07.기준선매수a=(highest(high,midPeriod)+lowest(low,midPeriod))/2;shift(crossup(c,a),-1)midperiod:26**시스템 :위조건 만족시 매수신호 **지표: 위조건 만족시 +1(돌파봉만) /기준선0감사합니다
프로필 이미지
조민철
2025-10-26
206
글번호 227315
시스템
답변완료

질문 있습니다.

질문의 요점: 1분봉 차트에서 시간대별(진입 기준) 순수익 계산이 정확하지 않습니다안녕하세요저번주에 답변 주신 글번호 227224 NetProfit 차이 방식으로 시간대별 손익을 계산하고 있는데, 1분봉 차트에서 결과가 정확하지 않아 다시 문의드립니다.=== 현재 사용 중인 코드 ===Input : StartHour(8), EndHour(18);var : NP(0), NP1(0), dayPL(0);NP = NetProfit;// 8시 직전까지의 총손익 저장if CurrentHour == StartHour and CurrentHour != CurrentHour[1] Then { NP1 = NP[1];}// 8시~18시 사이 당일손익 계산if CurrentHour >= StartHour and CurrentHour <= EndHour Then { dayPL = (NP - NP1) / PriceScale;}Else { dayPL = dayPL[1]; // 거래 시간 외 이전 값 유지}// 19시 출력if CurrentHour == (EndHour + 1) and CurrentHour != CurrentHour[1] Then { Text_New(sDate, sTime, H + 2.0, NumToStr(dayPL, 0) + "T");}```>>문제 상황 1번 계산 오류 있습니다.차트는 1분봉 입니다.실제로 8-18시 진입 거래를 하면- 6회 진입: -31, +58, -37, +245, -43, +22 = +214틱로 계산 됩니다. (차트에 표시된 진입/청산 시 수익/손실 표시를 수동 계산했음)그러나 시스템 표시 결과를 보면 혼란스럽니다.- 19시 표시는 -299틱 으로 나왔고 순수익 +214 표시가 잘 되지 않습니다.NetProfit 흐름은 아래와 같습니다.- 8시 이전: -201틱- 19시 전체: -500틱- 계산: -500 - (-201) = -299틱로 이렇게 표시 된 것 같습니다.문제는 실제 8-18시 진입 거래는 +214틱인데 -299틱으로 표시되어서 그렇습니다.. ---------------------------------------------------------------------------->>문제 상황 2번 18시 이전 진입 → 19시 이후 청산 케이스인데더 복잡한 문제가 있습니다:예를 들면```17:55 매수 진입 (8-18시 거래 시간 내)18:00 거래 시간 종료 그러나 청산 조건 때문에 18:00 넘어 포지션 홀딩한 경우임19:15 청산 +50틱 (19시 이후)```질문입니다.- 진입은 8-18시 내, 청산은 19시 이후인 경우- 이 +50틱을 8-18시 손익에 포함해야 할까요?제 의도는 아래와 같습니다.- "8-18시 사이에 진입한 모든 거래의 최종 손익"을 계산하고 싶습니다- 청산 시간은 무관하게, 진입 시간 기준 으로 추적하고- 해당 거래들이 모두 청산 완료된 후 에 최종 손익 표시하고 싶습니다. === 원하는 동작 ===1. 8-18시 사이 진입한 거래만 추적2. 해당 거래들이 모두 청산될 때까지 대기3. 마지막 거래 청산 완료 시점에 → "8-18시(진입기준) 최종: +XXX틱" 표시=== 핵심 질문 ===1. 1분봉에서 "18시 마지막 봉" 구분 방법```18:00, 18:01, 18:02 ... 18:59 봉들이 모두 CurrentHour = 18인데,18시 구간의 마지막 봉(18:59)을 어떻게 정확히 잡나요?```2. 18시 이후 거래 제외 방법- 18시 이후(18-24시)에도 거래가 계속되는데, 18시까지의 NP만 저장하려면?- `if CurrentHour == 19 and CurrentHour[1] == 18` 조건으로 18:59의 NP[1]을 읽어야 하나요?3. 진입 시간 기준 손익 계산 방법```예시 코드:var : InTime_Entry(0); // 시간대 내 진입 플래그var : InTime_Count(0); // 시간대 내 진입한 미결제 건수// 진입 시 기록if Buy신호 and CurrentHour >= 8 and CurrentHour <= 18 Then { InTime_Entry = 1; InTime_Count = InTime_Count + 1;}// 청산 시 카운트 감소if 청산 and InTime_Entry == 1 Then { InTime_Count = InTime_Count - 1;}// 모든 포지션 청산 완료 후 표시if CurrentHour > 18 and InTime_Count == 0 and 미표시 Then { Text_New(..., "8-18시 최종: +XXX틱");}이런 방식이 가능한가요?4. 1분봉 차트에서 시간대별 손익 계산 시 주의사항이 있을까요?요약 하자면 아래와 같습니다.문제 1: 기본 NetProfit 차이 계산이 부정확 (-299 vs +214)문제 2: 18시 전 진입 → 19시 후 청산 케이스 처리 방법원하는 결과: 진입 시간 기준으로 모든 거래 청산 후 최종 손익 표시 희망구체적인 코드 예시와 함께 답변 부탁드립니다. ㅠㅠ감사합니다!!!!
프로필 이미지
스오어스
2025-10-26
88
글번호 227314
시스템
답변완료

Y축 표시 방법

안녕하세요.. 지표 지렁이를 옮기면 위와 같은 y축 표시 방법을 선택하라고 나오는데요.. 설명 좀 부탁드릴 수 있을까요?감사합니다. 주로 어떤 때 사용하는 것일까요? 스케일을 다르게 할 때 사용할까요? 사용예와 함께 설명해 주시면 더욱 감사하겠습니다..
프로필 이미지
랑랑
2025-10-26
72
글번호 227311
지표
답변완료

당일청산

수고하십니다. 다음 내용 시스템 수식 부탁드립니다. 1. 기본 가. 사용자개발지수 : '상방', '하방' 나. 당일청산, 따라서 개장시 포지션 없슴. 다. 조건 만족시(봉 완성시) 현재가 보다 a틱(변수, 최적화할 예정) 만큼 유리하게 진입. 즉, 매수조건이면 a틱만큼 낮게, 매도조건이면 a틱 만큼 높게 진입 라. 첫 거래 이후 청산조건에 이르면 청산과 동시에 반대포지션 진입 마. 첫 진입은 개장 후 000000(변수, 최적화할 예정, 기본값25분) 시간 경과하거나, 또는 정해진 시간(변수, 최적화할 예정, 기본값 09시10분 이후) 이후 진입 바. 2회에 걸쳐 물타기 사. 당일 청산, 시간은 000000(변수, 최적화할 예정,기본값, 3시20분) 2. 최초 진입 가. 최초 진입 (이 때 포시션은 0인 상태) 정해진 시간 경과 후, '상방' >'하방' 이면 매수 1계약 진입, 반대면 매도 한 계약 진입 나. 물타기 1) 기본 조건 : 최초 진입할 때 조건이 유지되어야 한다. 즉, 매수 1계약 상태이면 '상방'>'하방'이 유지되어야 하고, 매도 1계약 상태이면 '상방' < '하방'이 유지되고 있어야 한다. 2) 1차 물타기 : 반대로 00틱 (변수, 최적화 예정) 가면 1계약 추가 (위 1)의 기본 조건 충족하고 있어야 한다) 3) 2차 물타기 : 평단에서 00틱 (변수, 최적화 예정) 가면 1계약 추가 (위 1)의 기본 조건 충족하고 있어야 한다) 다. 포지션 청산 1) 물타기 되어 복수의 수량을 보유하고 있어도 분할 청산 없슴. 2) 손절 매수 조건('상방'>'하방')이어서 진입하였으나 매도 조건('상방'<'하방')으로 바뀌면 포지션 해당봉의 종가로 전부 손절. 즉, '상방'이 '하방'과 데드크로스하면 손절. 매도는 반대 3)본절 평단(1계약일때는 진입가) 대비 00틱(변수, 최적화 예정) 이익이 나다가 진입가(또는 평단) 오면 본절청산 4) 익절 가) 기본 트레일링 스탑 . 집입 후 00틱(변수, 최적화 예정) 이익이 나다 00틱 (변수, 최적화 예정) 줄어들면 청산. 나) 트레일링스탑으로 청산되지 않은 포지션 당일청산 조건으로 청산, 이후 무포지션 3. 두번째부터 진입 기존 포지션 손절과 동시에 반대편 포지션 진입하고 이후 물타기 및 청산 조건은 최초진입과 동일
프로필 이미지
가람봉
2025-10-26
107
글번호 227310
시스템

잼스딘 님에 의해서 삭제되었습니다.

프로필 이미지
잼스딘
2025-10-26
36
글번호 227300
종목검색
답변완료

수식 부탁드립니다

지표식 부탁 드립니다. //@version=5indicator('DFT', overlay=true)import jdehorty/KernelFunctions/2 as kernel// INPUTSN = input.int(10,"Fourier Period")xval = input.source(close,"Fourier X Series",tooltip = "i.e. the source of the discrete Fourier"+ " transform (with the Y Series being the bars through time.)")highlighting = input.bool(true,"Highlighting")smoothing = input.int(10,"Kernel Smoothing")DFT(x, y, Nx, _dir) => float _arg = 0.0 float _cos = 0.0 float _sin = 0.0 float xArr_i = 0.0 float yArr_i = 0.0 xArr = array.new_float(array.size(x)) yArr = array.new_float(array.size(y)) for i = 0 to Nx - 1 by 1 xArr_i := 0.0 yArr_i := 0.0 kx = float(i) / float(Nx) _arg := -_dir * 2 * math.pi * kx for k = 0 to Nx - 1 by 1 _cos := math.cos(k * _arg) _sin := math.sin(k * _arg) xArr_i += array.get(x, k) * _cos - array.get(y, k) * _sin yArr_i += array.get(x, k) * _sin + array.get(y, k) * _cos yArr_i array.set(xArr, i, xArr_i) array.set(yArr, i, yArr_i) if _dir == 1 for i = 0 to Nx - 1 by 1 array.set(x, i, array.get(xArr, i) / float(Nx)) array.set(y, i, array.get(yArr, i) / float(Nx)) else for i = 0 to Nx - 1 by 1 array.set(x, i, array.get(xArr, i)) array.set(y, i, array.get(yArr, i))// CALCULATIONS// Fourier transformx = array.new_float(N, 0.0)y = array.new_float(N, 0.0)for i = 0 to N - 1 array.set(x, i, xval[i]) array.set(y, i, 0.0)DFT(x, y, N, 1)mag = array.new_float(N, 0.0)for i = 0 to N - 1 mag_i = math.sqrt(math.pow(array.get(x, i), 2) + math.pow(array.get(y, i), 2)) array.set(mag, i, mag_i)dft = array.get(mag,0)dfts = kernel.rationalQuadratic(dft,25,1,smoothing)// DISPLAYft = plot(dft, "DFT", color= color.white)fts = plot(dfts, "Smoothing", color = dfts > dft ? color.red : color.lime)fill(ft,fts,color = highlighting and dfts > dft ? color.new(color.red,75) : highlighting and dfts < dft ? color.new(color.lime,75) : na)
프로필 이미지
사노소이
2025-10-25
229
글번호 227298
지표
답변완료

부탁드립니다

수고하십니다아래수식을 오류 없게 수정부탁드립니다Inputs: PivotLength(10), TrendLength(50), ShowProfile(true), ColorUp(Blue), ColorDn(Red);Variables: PH(0), PL(0), HighestH(0), LowestL(0), TrendLine(0), ATRValue(0), IsTrendUp(false), PivotDetected(false), StartBar(0), TopPrice(0), BotPrice(0), Levels(0), StepSize(0), i(0), k(0), MidPrice(0), POCPrice(0), POCVolume(0), CurrentColor(0);Arrays: VolumeBins[1000](0);// ATR 계산ATRValue = Average(TrueRange, 200) * 0.1;// Pivot 감지PH = 0;PL = 0;// Pivot High 감지if High[PivotLength] = Highest(High, 2 * PivotLength + 1) then PH = High[PivotLength];// Pivot Low 감지if Low[PivotLength] = Lowest(Low, 2 * PivotLength + 1) then PL = Low[PivotLength];// 트렌드 계산HighestH = Highest(High, TrendLength);LowestL = Lowest(Low, TrendLength);TrendLine = (HighestH + LowestL) / 2;// 트렌드 방향 결정if High = HighestH then IsTrendUp = true;if Low = LowestL then IsTrendUp = false;// 색상 설정if IsTrendUp = false then CurrentColor = ColorUpelse CurrentColor = ColorDn;// Pivot 감지PivotDetected = false;if IsTrendUp = false then begin if PH > 0 then PivotDetected = true;end else begin if PL > 0 then PivotDetected = true;end;// Volume Profile 계산if CurrentBar - PivotLength - StartBar > PivotLength then begin if PivotDetected then begin StartBar = CurrentBar - PivotLength; // 경계 설정 TopPrice = High; BotPrice = Low; for i = 0 to PivotLength * 2 begin if High[i] > TopPrice then TopPrice = High[i]; if Low[i] < BotPrice then BotPrice = Low[i]; end; // 레벨 계산 Levels = (TopPrice - BotPrice) / ATRValue; StepSize = (TopPrice - BotPrice) / Levels; // Volume Bins 초기화 for k = 0 to Levels begin VolumeBins[k] = 0; end; // Volume 수집 for i = 0 to PivotLength * 2 begin for k = 0 to Levels begin MidPrice = BotPrice + StepSize * k + StepSize / 2; if AbsValue(MidPrice - Close[i]) <= StepSize * 2 then VolumeBins[k] = VolumeBins[k] + Volume[i]; end; end; // POC (Point of Control) 찾기 POCVolume = 0; POCPrice = 0; for k = 0 to Levels begin if VolumeBins[k] > POCVolume then begin POCVolume = VolumeBins[k]; POCPrice = BotPrice + StepSize * k + StepSize / 2; end; end; end;end;// 플롯Plot1(TrendLine, "Trend");if ShowProfile thenPlot2(POCPrice, "POC Level");// 색상 적용SetPlotColor(1, CurrentColor);SetPlotWidth(1, 4);if ShowProfile then begin SetPlotColor(2, CurrentColor); SetPlotWidth(2, 1);end;
프로필 이미지
파생돌이
2025-10-25
108
글번호 227297
지표