커뮤니티
부탁드립니다
수고하십니다
아래수식을 오류 없게 수정부탁드립니다
//※※==>내부함수의입력값 2개 필요 수정요망??? 오류부분
Inputs:
PivotLength(10),
TrendLength(50),
ShowProfile(true),
ColorUp(Blue),
ColorDn(Red);
Variables:
i(0), j(0), k(0),
PH(0), PL(0),
HighestH(0), LowestL(0),
TrendLine(0),
ATRValue(0),
IsTrendUp(false),
PivotDetected(false),
StartBar(0),
// Volume Profile 관련
TopPrice(0), BotPrice(0),
Levels(0),
StepSize(0),
MidPrice(0),
// POC 관련
POCPrice(0),
POCVolume(0),
POCBar(0),
// Drawing Objects
TLRef(0),
TextRef(0),
POCLineRef(0),
PivotTextRef(0),
// 색상
CurrentColor(0),
ProfileColor(0),
// Pivot 라벨 위치
PivotY(0),
// Volume Profile 바 너비
BarWidth(0);
Arrays:
VolumeBins[1000](0),
VPLines[1000](0),
VPStartBars[100](0),
VPEndBars[100](0);
// ATR 계산
ATRValue = ATR(200) * 0.1;
// Pivot 감지
PH = 0;
PL = 0;
// Pivot High 감지
if CurrentBar > PivotLength * 2 then begin
if High[PivotLength] == Highest(High, 2 * PivotLength + 1) then
PH = High[PivotLength];
end;
// Pivot Low 감지
if CurrentBar > PivotLength * 2 then begin
if Low[PivotLength] == Lowest(Low, 2 * PivotLength + 1) then
PL = Low[PivotLength];
end;
// 트렌드 계산
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 = ColorUp;
else
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
// 이전 POC 라인 연장
if POCLineRef > 0 then begin
TL_SetEnd(POCLineRef, Date[PivotLength], Time[PivotLength], POCPrice);
end;
StartBar = CurrentBar - PivotLength;
// 경계 설정
TopPrice = High[PivotLength];
BotPrice = Low[PivotLength];
for i = 0 to PivotLength * 2 begin
if High[i] > TopPrice then
TopPrice = High[i];
if Low[i] < BotPrice then
BotPrice = Low[i];
end;
// 레벨 계산
if ATRValue > 0 and (TopPrice - BotPrice) > 0 then begin
Levels = IntPortion((TopPrice - BotPrice) / ATRValue);
if Levels < 1 then Levels = 1;
if Levels > 999 then Levels = 999;
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;
POCBar = 0;
for k = 0 to Levels begin
if VolumeBins[k] > POCVolume then begin
POCVolume = VolumeBins[k];
MidPrice = BotPrice + StepSize * k + StepSize / 2;
POCPrice = MidPrice;
// POC 바 위치 계산 (Volume 비율에 따라)
if POCVolume > 0 then
POCBar = Round((VolumeBins[k] / POCVolume) * PivotLength); //※※==>내부함수의입력값 2개 필요 수정요망???
else
POCBar = 0;
end;
end;
// Volume Profile 시각화 (Profile이 켜져 있을 때만)
if ShowProfile then begin
// 이전 Volume Profile 라인 삭제
for k = 0 to Levels begin
if VPLines[k] > 0 then begin
TL_Delete(VPLines[k]);
VPLines[k] = 0;
end;
end;
// Volume Profile 히스토그램 그리기
for k = 0 to Levels begin
if VolumeBins[k] > 0 then begin
MidPrice = BotPrice + StepSize * k + StepSize / 2;
// 바 너비 계산 (최대 Volume 대비 비율)
if POCVolume > 0 then
BarWidth = Round((VolumeBins[k] / POCVolume) * PivotLength); //※※==>내부함수의입력값 2개 필요 수정요망???
else
BarWidth = 0;
// Volume Profile 바 그리기
if BarWidth > 0 then begin
VPLines[k] = TL_New(
Date[PivotLength],
Time[PivotLength],
MidPrice,
Date[PivotLength - BarWidth],
Time[PivotLength - BarWidth],
MidPrice
);
TL_SetColor(VPLines[k], CurrentColor);
TL_SetSize(VPLines[k], 3);
end;
end;
end;
// POC 라인 그리기
if POCPrice > 0 and POCBar > 0 then begin
if POCLineRef > 0 then
TL_Delete(POCLineRef);
POCLineRef = TL_New(
Date[PivotLength - POCBar],
Time[PivotLength - POCBar],
POCPrice,
Date[PivotLength - POCBar - 15],
Time[PivotLength - POCBar - 15],
POCPrice
);
TL_SetColor(POCLineRef, CurrentColor);
TL_SetSize(POCLineRef, 2);
TL_SetExtRight(POCLineRef, false);
// POC 라벨
if TextRef > 0 then
Text_Delete(TextRef);
TextRef = Text_New(
Date[PivotLength - POCBar],
Time[PivotLength - POCBar],
POCPrice,
NumToStr(POCVolume, 0)
);
Text_SetColor(TextRef, CurrentColor);
end;
// Pivot 마커
if PivotTextRef > 0 then
Text_Delete(PivotTextRef);
if IsTrendUp == false then begin
// Pivot High
PivotY = PH;
PivotTextRef = Text_New(
Date[PivotLength],
Time[PivotLength],
PivotY,
"●"
);
Text_SetColor(PivotTextRef, CurrentColor);
Text_SetLocation(PivotTextRef,
Date[PivotLength],
Time[PivotLength],
PivotY + StepSize);
end else begin
// Pivot Low
PivotY = PL;
PivotTextRef = Text_New(
Date[PivotLength],
Time[PivotLength],
PivotY,
"●"
);
Text_SetColor(PivotTextRef, CurrentColor);
Text_SetLocation(PivotTextRef,
Date[PivotLength],
Time[PivotLength],
PivotY - StepSize);
end;
end;
end;
end;
end;
// POC 라인을 현재 바까지 계속 연장
if POCLineRef > 0 and POCPrice > 0 then begin
TL_SetEnd(POCLineRef, Date, Time, POCPrice);
end;
// 트렌드 라인 플롯
Plot1(TrendLine, "Trend", CurrentColor, Def, 4);
// POC 레벨 플롯 (Profile이 꺼져 있을 때)
if ShowProfile == False and POCPrice > 0 then
Plot2(POCPrice, "POC Level", CurrentColor, Def, 2);
else
NoPlot(2);
답변 1
예스스탁 예스스탁 답변
2025-10-28 12:27:47