[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RT] Value Area as it evolves during the day



PureBytes Links

Trading Reference Links

/Greg

{ INDICATOR: PriceDistribution }

input: date1(-1), TimeStart(930), TimeEnd(1600), HistColor(darkgray), 
ValueArea(.4), ValueColor(blue), HistBarSiz(0);
input: EveryMins(15), MinsBack(0);
input: ShoHist(true);
input: Cumulative(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 dates if its 0, 
LastCalcDate if its -1
     TimeStart, TimeEnd - 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 "0", the same 
as EveryMins
     ShoHist - if false, just the Value Area is plotted like a bar
     Cumulative - if false, shows the distribution for the past interval 
only; if true,
        shows the cumulative distribution during the day
}

{ author: Gregory Wood (swissfranc@xxxxxxxxxxx)
    rev 0: 2001 - initial release
    rev 1: 2003-02-14 - added Cumulative to show how the distribution 
evolves during the day;
       automated Base for use with minmove and pricescale, making it 
usable for other contracts
}

array: v[20000](0);
var: base(0);
var: ControlPoint(0), hVA(0), lVA(0);

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), loop(0), 
totv(0), vmaxpc(0);
var: PriceFac(0), InvPriceFac(0);

if currentbar = 1 then begin
    hh = h;
    ll = l;
    base = close * InvPriceFac;
    value1 = c[200]; {for autolookback}
    PriceFac = minmove/pricescale;
    InvPriceFac = pricescale/minmove;
end;
mins = 
EveryMins*intportion((timetominutes(time)-timetominutes(TimeStart))/EveryMins);

{ new day, so show yesterday's range and Value Area as single bar}
if hh > 0 and ll > 0 and hVA > 0 and lVA > 0 and ControlPoint > 0 then
if time >= TimeStart and (time[1] < TimeStart or date <> date[1]) then begin
    han1 = 
tl_new(date,time,PriceFac*ControlPoint+.5*PriceFac,date,time,PriceFac*ControlPoint-.5*PriceFac);
    tl_setcolor(han1,cyan);
    tl_setsize(han1,5);
    han1 = tl_new(date,time,PriceFac*hVA,date,time,PriceFac*lVA);
    tl_setcolor(han1,blue);
    tl_setsize(han1,5);
    han1 = tl_new(date,time,hh,date,time,ll);
    tl_setcolor(han1,darkgray);
    tl_setsize(han1,5);
end;

{ clear v array at the start of the day }
if Mins = EveryMins and Mins[1] <> EveryMins then begin
    cbPrev = currentbar;
    for ii = ll * InvPriceFac  - base to hh * InvPriceFac - base begin
       v[ii] = 0;
    end;
    hh = h;
    ll = l;
end;

{ whenever its time to show a new histogram }
if time <> time[1] then
if (date1 = date or date1 = 0 or date1 = -1) and
    ((time >= TimeStart and time <= TimeEnd) or TimeStart = 0 or TimeEnd 
= 0 or time = Sess1EndTime) and
    (mins <> mins[1] or time = Sess1EndTime) then begin

    { clear v array at start of interval, unless its cumulative }
    if Cumulative = false then
    for ii = ll * InvPriceFac  - base to hh * InvPriceFac - base begin
       v[ii] = 0;
    end;

    { find start of interval }
    cb = 0;
    Sanity = true;
    targ = timetominutes(time) - iff(MinsBack=0,EveryMins,MinsBack);
    while Sanity and targ <= timetominutes(time[cb]) 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;
    cbprev = currentbar - cb;

    { add bars (or tick) to list }
    if Cumulative = false then begin
       hh = h;
       ll = l;
    end;
    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] + PriceFac then m1 = c[ij+1] + PriceFac
       else if m2 < c[ij+1] - PriceFac then m2 = c[ij+1] - PriceFac;
       for ii = m1 * InvPriceFac - base to m2 * InvPriceFac - base begin
          v[ii] = v[ii] + 1;
       end;
    end;

    { find Value Area }
    maxv = 0;
    totv = 0;
    for ii = ll * InvPriceFac to hh * InvPriceFac begin
       { identify the point of control }
       totv = totv + v[ii - base];
       if maxv < v[ii - base] then begin
          maxv = v[ii - base];
          ControlPoint = ii;
       end;
    end;
    vmaxpc = maxv;
    hVA = ControlPoint;
    lVA = ControlPoint;
    loop = 0;
    if maxV > 0 then
    while loop < 500 and vmaxpc / totv < ValueArea begin
       loop = loop + 1;
       if v[hVA + 1 - base] > v[lVA - 1 - base] then begin
          hVA = hVA + 1;
          vmaxpc = vmaxpc + v[hVA - base];
       end else begin
          lVA = lVA - 1;
          vmaxpc = vmaxpc + v[lVA - base];
       end;
    end;
	
    { display the list }
    if ShoHist then
    if date1 <> -1 or date = lastcalcdate then
    if date = date[1] then
    for ii = ll * InvPriceFac to hh * InvPriceFac begin
       if maxV > 0 then begin
          bb = maxlist(1, v[ii - base] * (currentbar - cbPrev) / maxV);
          if time[bb] <> time then begin
             han1 = 
tl_new(date[bb],time[bb],ii*PriceFac,date,time,ii*PriceFac);
             tl_setextleft(han1,false);
             tl_setextright(han1,false);
             tl_setcolor(han1,HistColor);
             tl_setsize(han1,HistBarSiz);
             if ii >= lVA and ii <= hVA then tl_setcolor(han1,ValueColor);
             if ii = ControlPoint then tl_setcolor(han1,cyan);
          end;
       end;
    end;
end;

if false then begin
    plot1(0,"");
    plot2(0,"");
    plot3(0,"");
    plot4(0,"");
end;

To unsubscribe from this group, send an email to:
realtraders-unsubscribe@xxxxxxxxxxxxxxx

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




Attachment: Description: "Description: Binary data"

Attachment: Description: "PRICEDISTRIBUTION.ELS"

Attachment: Description: "Attachment:"