Price Distribution

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
Fra
Posts: 6
Joined: 31 Jan 2007

Price Distribution

Postby Fra » 12 Feb 2007

i have downloaded from internet this code that works fine on TS2000. Trying to import and compile it i get errors

Code: Select all

[LegacyColorValue = TRUE];

input: date1(0), time1(930), time2(1600), HistColor(darkgray), ValueArea(.6), ValueColor(blue);
input: EveryMins(15), MinsBack(15);
input: ShoHist(true);

{ This displays price histograms EveryMins. The lookback period is MinsBack.

It works for both minute and tick bars, even 1-tick bars. Try with S&P 1-minute bars
or S&P 1-tick bars.

Inputs:
date1 - draws histrograms for this date; all date if its 0
time1, time2 - draws histograms within this date range
HistColor - the color of the histogram
ValueColor - the color of the value area
ValueArea - portion of the prices that will be colored; range 0 to 1
EveryMins - draw a histogram every, say, 15 minutes
MinsBack - how far back to analyze prices, typically the same as EveryMins
ShoHist - if false, just the value area is plotted like a bar
}

array: v[5000](0);
var: base(10000);

var: ii(0), ij(0), hh(0), ll(0), cbStart(0), bb(0), maxv(0), han1(0), m1(0), m2(0);
var: mins(0), cb(0), cbPrev(0), targ(0), Sanity(false);
var: iivmax(0), totv(0), vmaxpc(0), vhh(0),vll(0), loop(0);

if currentbar = 1 then begin
hh = h;
ll = l;
end;
mins = EveryMins*intportion(timetominutes(time)/EveryMins);

if (date1 = date or date1 = 0) and ((time >= time1 and time <= time2) or time1 = 0 or time2 = 0) and
mins <> mins[1] then begin

{ plot1(c,"",red,default,5);}

{ clear v array }
for ii = ll * 10 - base to hh * 10 - base begin
v[ii] = 0;
end;

{ find start of interval }
cb = 0;
Sanity = true;
targ = timetominutes(time) - MinsBack;
while targ <= timetominutes(time[cb]) and Sanity begin
cb = cb+1;
if cb >= currentbar then Sanity = false;
if date[cb] <> date then Sanity = false;
if cb > 1000 then Sanity = false;
end;
cb = cb - 1;

{ add bars to list }
hh = h;
ll = l;
for ij = cb - 1 downto 0 begin
m1 = l[ij];
m2 = h[ij];
if hh < m2 then hh = m2;
if ll > m1 then ll = m1;
if m1 > c[ij+1] + .10 then m1 = c[ij+1] + .10
else if m2 < c[ij+1] - .10 then m2 = c[ij+1] - .10;
for ii = m1 * 10 - base to m2 * 10 - base begin
v[ii] = v[ii] + 1;
end;
end;

{ find value area }
maxv = 0;
totv = 0;
for ii = ll * 10 to hh * 10 begin
totv = totv + v[ii - base];
if maxv < v[ii - base] then begin
maxv = v[ii - base];
iivmax = ii;
end;
end;
vmaxpc = maxv;
vhh = iivmax;
vll = iivmax;
sanity = true;
loop = 0;
if maxV > 0 then
while sanity and vmaxpc / totv < ValueArea begin
loop = loop + 1;
if loop > 50 then sanity = false;
if v[vhh + 1 - base] > v[vll - 1 - base] then begin
vhh = vhh + 1;
vmaxpc = vmaxpc + v[vhh - base];
end else begin
vll = vll - 1;
vmaxpc = vmaxpc + v[vll - base];
end;
end;



{ display the list }
if ShoHist then
for ii = ll * 10 to hh * 10 begin
if maxV > 0 then begin
bb = v[ii - base] * (currentbar - cbPrev) / maxV;
if time[bb] <> time then begin
han1 = tl_new(date[bb],time[bb],ii*.1,date,time,ii*.1);
tl_setextleft(han1,false);
tl_setextright(han1,false);
tl_setcolor(han1,HistColor);
if ii >= vll and ii <= vhh then tl_setcolor(han1,ValueColor);
if ii = iivmax then tl_setcolor(han1,cyan);
end;
end;
end;
{ plot2(iivmax*.1,"",cyan,default,4);}
plot3(vhh*.1,"",ValueColor,default,0);
plot4(vll*.1,"",ValueColor,default,0);
cbPrev = currentbar;
end;





if false then begin
plot1(0,"");
plot2(0,"");
plot3(0,"");
plot4(0,"");
end;
12.02.07 16:15:46
------ Build started: ------
Study: "PriceDistribution" (Indicator)
Please wait ....
------ Compiled with error(s): ------
this word has already been defined
errLine 23, errColumn 7, errLineEnd 23, errColumnEnd 8

User avatar
Stanley Miller
Posts: 556
Joined: 26 Jul 2005
Has thanked: 3 times

Postby Stanley Miller » 12 Feb 2007

You can't use v as an array name because this is a reserved word which means volume. Please rename it.

Fra
Posts: 6
Joined: 31 Jan 2007

Postby Fra » 12 Feb 2007

Thank you Stanley

i did it...and i put X instead of v

compiled it...ok

but using the ela i have "Array bounds.Wrong index value: -1985"

User avatar
Stanley Miller
Posts: 556
Joined: 26 Jul 2005
Has thanked: 3 times

Postby Stanley Miller » 12 Feb 2007

I can't make it work in TS as well. Could you please post the screenshot of this indicator in TS?

Fra
Posts: 6
Joined: 31 Jan 2007

Postby Fra » 12 Feb 2007

sorry stanley

i doen't work to me too. before i haven't plotted it, but only importing and testing.

anyway i am intested to this ela, there is something similar anywhere?


Return to “User Contributed Studies and Indicator Library”