Color Bars
The lessons laid the foundation for a program's structure,
variables, operators, expressions, procedures, and functions. Now let's turn our
efforts to creating useful scripts.Cut the following script from this page and paste it in the ESPL Script
Editor. Click on the RUN button to compile and run the script. Hopefully,
nothing happens. That means the script did not contain a compile
error. Now display any chart and click on the ESPL RUN button on the Chart
Controls toolbar. The following ESPL panel shows. Click button 42 in the Color Bars
column. This will execute the script
with the ESPL variable set to a value of 42. 
The bars on the chart will be
painted shades of red and green.
What does this script do? It performs seven tests that indicate upward
or downward strength by comparing a bar with its neighbor on the left.
This strength is then converted into a shade of red or green with the strongest
upward strength being a bright red and the strongest downward strength being a
bright green.
procedure ColorBar42;
var
i,j: integer;
c: longint;
iRed,iGreen: integer;
begin
for i:=BarBeginLeft to BarEnd do begin
j:=pred(i); {j will be the index for the neighboring bar}
iRed:=0; iGreen:=0;
if Open(i)>Last(j) then inc(iRed);
if Open(i)>High(j) then inc(iRed);
if High(i)>High(j) then inc(iRed);
if Low(i)>Low(j) then inc(iRed);
if Low(i)>High(j) then inc(iRed);
if Last(i)>Last(j) then inc(iRed);
if Last(i)>Open(i) then inc(iRed); if
Open(i)<=Last(j) then inc(iGreen);
if Open(i)<=Low(j) then inc(iGreen);
if High(i)<=High(j) then inc(iGreen);
if Low(i)<=Low(j) then inc(iGreen);
if High(i)<=Low(j) then inc(iGreen);
if Last(i)<=Last(j) then inc(iGreen);
if Last(i)<=Open(i) then inc(iGreen); j:=iRed-iGreen;
if j<-5 then c:=clLime
else if (j=-5) or (j=-4) then c:=clGreen
else if j<0 then c:=clDkGreen
else if j=0 then c:=clDkGray
else if j>5 then c:=clRed
else if (j=5) or (j=4) then c:=clDkRed
else c:=clMaroon;
SetBar(eColor,i,c);
end;
end; {----- MAIN PROGRAM -----}
begin
if ESPL=42 then ColorBar42;
end;
|