커뮤니티

부탁드립니다

프로필 이미지
파생돌이
2025-10-28 00:47:40
140
글번호 227383
답변완료

수고하십니다

아래수식을 오류 없게 수정부탁드립니다


Inputs:

Period(200),

VPResolution(50),

ShowPoC(true),

ShowPivots(true),

PivotLength(10),

PivotFilter(20);

Variables:

i(0), j(0), k(0),

HighestPrice(0), LowestPrice(0),

BinSize(0),

BinLow(0), BinHigh(0), BinMid(0),

BinValue(0), MaxBinValue(0),

VolPercent(0),

Left(0), Right(0),

PocPrice(0), PocVolume(0),

TotalDelta(0),

CurrentDelta(0),

// Pivot 관련

PH(0), PL(0),

PivotPrice(0),

PivotBar(0),

PivotIndex(0),

// Drawing Objects

TLRef(0),

TextRef(0),

RectRef(0),

// 색상

ProfileColor(0),

BarColor(0);

Arrays:

VolumeBins[100](0),

DeltaBins[100](0),

PivotPrices[500](0),

PivotBars[500](0),

PivotTypes[500](0), // 1 = High, -1 = Low

PivotProcessed[500](0), // 0 = not processed, 1 = processed

VPTrendLines[100](0),

VPLabels[100](0);

// 이전 Drawing Objects 삭제 (마지막 바에서만)

if Date <> Date[1] or Time <> Time[1] then begin

for i = 0 to VPResolution - 1 begin

if VPTrendLines[i] > 0 then begin

TL_Delete(VPTrendLines[i]);

VPTrendLines[i] = 0;

end;

if VPLabels[i] > 0 then begin

Text_Delete(VPLabels[i]);

VPLabels[i] = 0;

end;

end;

end;

// Pivot High 감지

PH = 0;

if CurrentBar > PivotLength * 2 then begin

if High[PivotLength] == Highest(High, 2 * PivotLength + 1) then

PH = High[PivotLength];

end;

// Pivot Low 감지

PL = 0;

if CurrentBar > PivotLength * 2 then begin

if Low[PivotLength] == Lowest(Low, 2 * PivotLength + 1) then

PL = Low[PivotLength];

end;

// Pivot 저장 및 처리

if PH > 0 then begin

PivotIndex = -1;

// 빈 슬롯 찾기

for i = 0 to 499 begin

if PivotBars[i] = 0 then begin

PivotIndex = i;

break;

end;

end;

if PivotIndex >= 0 then begin

PivotPrices[PivotIndex] = PH;

PivotBars[PivotIndex] = CurrentBar - PivotLength;

PivotTypes[PivotIndex] = 1; // High

PivotProcessed[PivotIndex] = 0;

end;

end;

if PL > 0 then begin

PivotIndex = -1;

// 빈 슬롯 찾기

for i = 0 to 499 begin

if PivotBars[i] = 0 then begin

PivotIndex = i;

break;

end;

end;

if PivotIndex >= 0 then begin

PivotPrices[PivotIndex] = PL;

PivotBars[PivotIndex] = CurrentBar - PivotLength;

PivotTypes[PivotIndex] = -1; // Low

PivotProcessed[PivotIndex] = 0;

end;

end;

// Volume Profile 계산 및 시각화

if CurrentBar >= Period then begin

// 범위 계산

HighestPrice = Highest(High, Period);

LowestPrice = Lowest(Low, Period);

if HighestPrice > LowestPrice then begin

BinSize = (HighestPrice - LowestPrice) / VPResolution;

// Bins 초기화

for i = 0 to VPResolution - 1 begin

VolumeBins[i] = 0;

DeltaBins[i] = 0;

end;

// Volume 데이터 수집

for j = 0 to Period - 1 begin

for i = 0 to VPResolution - 1 begin

BinLow = LowestPrice + BinSize * i;

BinHigh = BinLow + BinSize;

if Close[j] >= BinLow - BinSize and Close[j] < BinHigh + BinSize then begin

VolumeBins[i] = VolumeBins[i] + Volume[j];

// Delta 계산

if Close[j] > Open[j] then

DeltaBins[i] = DeltaBins[i] + Volume[j];

else

DeltaBins[i] = DeltaBins[i] - Volume[j];

end;

end;

end;

// 최대 Volume 찾기

MaxBinValue = 0;

for i = 0 to VPResolution - 1 begin

if VolumeBins[i] > MaxBinValue then

MaxBinValue = VolumeBins[i];

end;

// PoC 및 Total Delta 계산

PocVolume = 0;

PocPrice = 0;

TotalDelta = 0;

for i = 0 to VPResolution - 1 begin

TotalDelta = TotalDelta + DeltaBins[i];

if VolumeBins[i] > PocVolume then begin

PocVolume = VolumeBins[i];

BinLow = LowestPrice + BinSize * i;

BinHigh = BinLow + BinSize;

PocPrice = (BinLow + BinHigh) / 2;

end;

end;

// 색상 결정 (Delta 기반)

if TotalDelta > 0 then

ProfileColor = Cyan;

else

ProfileColor = Red;

// Volume Profile 히스토그램 그리기 (마지막 바에서만)

if LastBarOnChart then begin

Left = CurrentBar - Period;

for i = 0 to VPResolution - 1 begin

BinLow = LowestPrice + BinSize * i;

BinHigh = BinLow + BinSize;

BinMid = (BinLow + BinHigh) / 2;

BinValue = VolumeBins[i];

if MaxBinValue > 0 then begin

VolPercent = (BinValue / MaxBinValue) * 100;

Right = Left + Round((BinValue / MaxBinValue) * 50);

// Delta 기반 색상

if DeltaBins[i] > 0 then

BarColor = Cyan

else

BarColor = Red;

// Volume Profile 바 그리기 (TrendLine 사용)

if VPTrendLines[i] > 0 then

TL_Delete(VPTrendLines[i]);

VPTrendLines[i] = TL_New(Date[Period], Time[Period], BinMid,

Date[Period - Right + Left], Time[Period - Right + Left], BinMid);

TL_SetColor(VPTrendLines[i], BarColor);

TL_SetSize(VPTrendLines[i], 4);

// Pivot과 Volume Profile 교차점 표시

if ShowPivots then begin

for k = 0 to 499 begin

if PivotBars[k] > 0 and PivotProcessed[k] = 0 then begin

PivotPrice = PivotPrices[k];

PivotBar = PivotBars[k];

// Pivot이 Volume Profile 범위 내에 있고 필터 조건 만족

if AbsValue(BinMid - PivotPrice) <= BinSize and

VolPercent >= PivotFilter and

CurrentBar - Period <= PivotBar then begin

// Pivot 라인 그리기

if PivotTypes[k] = 1 then begin // Pivot High

TLRef = TL_New(Date[CurrentBar - PivotBar + PivotLength],

Time[CurrentBar - PivotBar + PivotLength],

PivotPrice,

Date[CurrentBar - PivotBar - PivotLength],

Time[CurrentBar - PivotBar - PivotLength],

PivotPrice);

TL_SetColor(TLRef, DarkRed);

TL_SetSize(TLRef, 2);

// 라벨 추가

TextRef = Text_New(Date[CurrentBar - PivotBar],

Time[CurrentBar - PivotBar],

PivotPrice,

NumToStr(BinValue, 0) + " (" + NumToStr(VolPercent, 0) + "%)");

Text_SetColor(TextRef, DarkRed);

Text_SetLocation(TextRef, Date[CurrentBar - PivotBar],

Time[CurrentBar - PivotBar],

PivotPrice + BinSize);

// 연장선 그리기 (Dotted)

TLRef = TL_New(Date[CurrentBar - PivotBar],

Time[CurrentBar - PivotBar],

PivotPrice,

Date, Time, PivotPrice);

TL_SetColor(TLRef, DarkRed);

TL_SetStyle(TLRef, Tool_Dotted);

TL_SetExtRight(TLRef, True);

end else begin // Pivot Low

TLRef = TL_New(Date[CurrentBar - PivotBar + PivotLength],

Time[CurrentBar - PivotBar + PivotLength],

PivotPrice,

Date[CurrentBar - PivotBar - PivotLength],

Time[CurrentBar - PivotBar - PivotLength],

PivotPrice);

TL_SetColor(TLRef, DarkGreen);

TL_SetSize(TLRef, 2);

// 라벨 추가

TextRef = Text_New(Date[CurrentBar - PivotBar],

Time[CurrentBar - PivotBar],

PivotPrice,

NumToStr(VolPercent, 0) + "% (" + NumToStr(BinValue, 0) + ")");

Text_SetColor(TextRef, DarkGreen);

Text_SetLocation(TextRef, Date[CurrentBar - PivotBar],

Time[CurrentBar - PivotBar],

PivotPrice - BinSize);

// 연장선 그리기 (Dotted)

TLRef = TL_New(Date[CurrentBar - PivotBar],

Time[CurrentBar - PivotBar],

PivotPrice,

Date, Time, PivotPrice);

TL_SetColor(TLRef, DarkGreen);

TL_SetStyle(TLRef, Tool_Dotted);

TL_SetExtRight(TLRef, True);

end;

PivotProcessed[k] = 1;

end;

end;

end;

end;

end;

end;

end;

end;

end;

// 오래된 Pivot 제거

for i = 0 to 499 begin

if PivotBars[i] > 0 and CurrentBar - PivotBars[i] > Period then begin

PivotBars[i] = 0;

PivotPrices[i] = 0;

PivotTypes[i] = 0;

PivotProcessed[i] = 0;

end;

end;

// PoC 레벨 표시

if ShowPoC and PocPrice > 0 then begin

Plot1(PocPrice, "PoC Level", ProfileColor, Default, 2);

// PoC 라벨 (마지막 바에서만)

if LastBarOnChart then begin

TextRef = Text_New(Date, Time, PocPrice, "POC: " + NumToStr(PocVolume, 0));

Text_SetColor(TextRef, ProfileColor);

Text_SetLocation(TextRef, Date, Time, PocPrice);

end;

end;

지표
답변 1
프로필 이미지

예스스탁 예스스탁 답변

2025-10-28 12:25:58

안녕하세요. 예스스탁입니다. Inputs: Period(200), VPResolution(50), ShowPoC(true), ShowPivots(true), PivotLength(10), PivotFilter(20); Variables: i(0), j(0), k(0), HighestPrice(0), LowestPrice(0), BinSize(0), BinLow(0), BinHigh(0), BinMid(0), BinValue(0), MaxBinValue(0), VolPercent(0), Left(0), Right(0), PocPrice(0), PocVolume(0), TotalDelta(0), CurrentDelta(0), // Pivot 관련 PH(0), PL(0), PivotPrice(0), PivotBar(0), PivotIndex(0), // Drawing Objects TLRef(0), TextRef(0), RectRef(0), // 색상 ProfileColor(0), BarColor(0); Arrays: VolumeBins[100](0), DeltaBins[100](0), PivotPrices[500](0), PivotBars[500](0), PivotTypes[500](0), // 1 = High, -1 = Low PivotProcessed[500](0), // 0 = not processed, 1 = processed VPTrendLines[100](0), VPLabels[100](0); // 이전 Drawing Objects 삭제 (마지막 바에서만) if Date <> Date[1] or Time <> Time[1] then begin for i = 0 to VPResolution - 1 begin if VPTrendLines[i] > 0 then begin TL_Delete(VPTrendLines[i]); VPTrendLines[i] = 0; end; if VPLabels[i] > 0 then begin Text_Delete(VPLabels[i]); VPLabels[i] = 0; end; end; end; // Pivot High 감지 PH = 0; if CurrentBar > PivotLength * 2 then begin if High[PivotLength] == Highest(High, 2 * PivotLength + 1) then PH = High[PivotLength]; end; // Pivot Low 감지 PL = 0; if CurrentBar > PivotLength * 2 then begin if Low[PivotLength] == Lowest(Low, 2 * PivotLength + 1) then PL = Low[PivotLength]; end; // Pivot 저장 및 처리 if PH > 0 then begin PivotIndex = -1; // 빈 슬롯 찾기 for i = 0 to 499 begin if PivotIndex == -1 and PivotBars[i] == 0 then begin PivotIndex = i; end; end; if PivotIndex >= 0 then begin PivotPrices[PivotIndex] = PH; PivotBars[PivotIndex] = CurrentBar - PivotLength; PivotTypes[PivotIndex] = 1; // High PivotProcessed[PivotIndex] = 0; end; end; if PL > 0 then begin PivotIndex = -1; // 빈 슬롯 찾기 for i = 0 to 499 begin if PivotIndex == -1 and PivotBars[i] == 0 then begin PivotIndex = i; end; end; if PivotIndex >= 0 then begin PivotPrices[PivotIndex] = PL; PivotBars[PivotIndex] = CurrentBar - PivotLength; PivotTypes[PivotIndex] = -1; // Low PivotProcessed[PivotIndex] = 0; end; end; // Volume Profile 계산 및 시각화 if CurrentBar >= Period then begin // 범위 계산 HighestPrice = Highest(High, Period); LowestPrice = Lowest(Low, Period); if HighestPrice > LowestPrice then begin BinSize = (HighestPrice - LowestPrice) / VPResolution; // Bins 초기화 for i = 0 to VPResolution - 1 begin VolumeBins[i] = 0; DeltaBins[i] = 0; end; // Volume 데이터 수집 for j = 0 to Period - 1 begin for i = 0 to VPResolution - 1 begin BinLow = LowestPrice + BinSize * i; BinHigh = BinLow + BinSize; if Close[j] >= BinLow - BinSize and Close[j] < BinHigh + BinSize then begin VolumeBins[i] = VolumeBins[i] + Volume[j]; // Delta 계산 if Close[j] > Open[j] then DeltaBins[i] = DeltaBins[i] + Volume[j]; else DeltaBins[i] = DeltaBins[i] - Volume[j]; end; end; end; // 최대 Volume 찾기 MaxBinValue = 0; for i = 0 to VPResolution - 1 begin if VolumeBins[i] > MaxBinValue then MaxBinValue = VolumeBins[i]; end; // PoC 및 Total Delta 계산 PocVolume = 0; PocPrice = 0; TotalDelta = 0; for i = 0 to VPResolution - 1 begin TotalDelta = TotalDelta + DeltaBins[i]; if VolumeBins[i] > PocVolume then begin PocVolume = VolumeBins[i]; BinLow = LowestPrice + BinSize * i; BinHigh = BinLow + BinSize; PocPrice = (BinLow + BinHigh) / 2; end; end; // 색상 결정 (Delta 기반) if TotalDelta > 0 then ProfileColor = Cyan; else ProfileColor = Red; // Volume Profile 히스토그램 그리기 (마지막 바에서만) //if LastBarOnChart then //begin Left = CurrentBar - Period; for i = 0 to VPResolution - 1 begin BinLow = LowestPrice + BinSize * i; BinHigh = BinLow + BinSize; BinMid = (BinLow + BinHigh) / 2; BinValue = VolumeBins[i]; if MaxBinValue > 0 then begin VolPercent = (BinValue / MaxBinValue) * 100; Right = Left + Round((BinValue / MaxBinValue) * 50,0); // Delta 기반 색상 if DeltaBins[i] > 0 then BarColor = Cyan; else BarColor = Red; // Volume Profile 바 그리기 (TrendLine 사용) if VPTrendLines[i] > 0 then TL_Delete(VPTrendLines[i]); VPTrendLines[i] = TL_New(Date[Period], Time[Period], BinMid, Date[Period - Right + Left], Time[Period - Right + Left], BinMid); TL_SetColor(VPTrendLines[i], BarColor); TL_SetSize(VPTrendLines[i], 4); // Pivot과 Volume Profile 교차점 표시 if ShowPivots then begin for k = 0 to 499 begin if PivotBars[k] > 0 and PivotProcessed[k] == 0 then begin PivotPrice = PivotPrices[k]; PivotBar = PivotBars[k]; // Pivot이 Volume Profile 범위 내에 있고 필터 조건 만족 if AbsValue(BinMid - PivotPrice) <= BinSize and VolPercent >= PivotFilter and CurrentBar - Period <= PivotBar then begin // Pivot 라인 그리기 if PivotTypes[k] == 1 then // Pivot High begin TL_Delete(TLRef); TLRef = TL_New(Date[CurrentBar - PivotBar + PivotLength], Time[CurrentBar - PivotBar + PivotLength], PivotPrice, Date[CurrentBar - PivotBar - PivotLength], Time[CurrentBar - PivotBar - PivotLength], PivotPrice); TL_SetColor(TLRef, DarkRed); TL_SetSize(TLRef, 2); Text_Delete(TextRef); // 라벨 추가 TextRef = Text_New(Date[CurrentBar - PivotBar], Time[CurrentBar - PivotBar], PivotPrice, NumToStr(BinValue, 0) + " (" + NumToStr(VolPercent, 0) + "%)"); Text_SetColor(TextRef, DarkRed); Text_SetLocation(TextRef, Date[CurrentBar - PivotBar], Time[CurrentBar - PivotBar], PivotPrice + BinSize); TL_Delete(TLRef); // 연장선 그리기 (Dotted) TLRef = TL_New(Date[CurrentBar - PivotBar], Time[CurrentBar - PivotBar], PivotPrice, Date, Time, PivotPrice); TL_SetColor(TLRef, DarkRed); TL_SetStyle(TLRef, 3); TL_SetExtRight(TLRef, True); end else // Pivot Low begin TL_Delete(TLRef); TLRef = TL_New(Date[CurrentBar - PivotBar + PivotLength], Time[CurrentBar - PivotBar + PivotLength], PivotPrice, Date[CurrentBar - PivotBar - PivotLength], Time[CurrentBar - PivotBar - PivotLength], PivotPrice); TL_SetColor(TLRef, DarkGreen); TL_SetSize(TLRef, 2); Text_Delete(TextRef); // 라벨 추가 TextRef = Text_New(Date[CurrentBar - PivotBar], Time[CurrentBar - PivotBar], PivotPrice, NumToStr(VolPercent, 0) + "% (" + NumToStr(BinValue, 0) + ")"); Text_SetColor(TextRef, DarkGreen); Text_SetLocation(TextRef, Date[CurrentBar - PivotBar], Time[CurrentBar - PivotBar], PivotPrice - BinSize); TL_Delete(TLRef); // 연장선 그리기 (Dotted) TLRef = TL_New(Date[CurrentBar - PivotBar], Time[CurrentBar - PivotBar], PivotPrice, Date, Time, PivotPrice); TL_SetColor(TLRef, DarkGreen); TL_SetStyle(TLRef, 3); TL_SetExtRight(TLRef, True); end; PivotProcessed[k] = 1; end; end; end; end; end; //end; end; end; end; // 오래된 Pivot 제거 for i = 0 to 499 begin if PivotBars[i] > 0 and CurrentBar - PivotBars[i] > Period then begin PivotBars[i] = 0; PivotPrices[i] = 0; PivotTypes[i] = 0; PivotProcessed[i] = 0; end; end; // PoC 레벨 표시 Text_Delete(textRef); if ShowPoC and PocPrice > 0 then begin Plot1(PocPrice, "PoC Level", ProfileColor, Def, 2); // PoC 라벨 (마지막 바에서만) TextRef = Text_New(Date, Time, PocPrice, "POC: " + NumToStr(PocVolume, 0)); Text_SetColor(TextRef, ProfileColor); Text_SetLocation(TextRef, Date, Time, PocPrice); end; 즐거운 하루되세요