Average Tick Size

This script will plot an Average Tick size on a chart.

procedure AverageTick;
var i,period: integer;
begin
  period:=GetUser(eParm1);
  RegisterStudy('Average Net',51);
  SetUser(ePlot1,True);      {plot 1st array}
  SetUser(eShow1,True);      {show 1st array}
  SetUser(ePercent,True);
  for i:=BarBegin to BarEnd do begin
    SetUser(2,Abs(Bar(eNet,i)),i);
    SetUser(1,Average(2,i,Period),i);
  end;  
end;

{----- MAIN PROGRAM -----}
begin
  if ESPL=51 then AverageTick;
end;

To use this script, cut it from this e-mail and paste it as the only code in the ESPL editor.  The editor is opened by clicking the light bulb button on the main button bar.  The editor window is the left hand side of the form.  Then save it under a name you like.  To execute, display your SP tick chart.  Click on the study button to display the drop down list of studies.  Click on the #1 button on the bottom of the study panel. 

Your chart will have an average tick line added, and a scale 0..100 plotted on the left side.   The average ticks on my chart run between 20 to 40 points, which plots well on the 0 to 100 scale.   The study gets registered as a name, so that you can add it to other charts by using the Average Tick name that you will find added to the list of studies.

Now I will comment on the script itself.

var i,period: integer;
All variables used in the script must be declared in a var section.

begin
  if ESPL=51 then AverageTick;
end;

The Who=51 test restricts this script to execute only when the #1 button on the Study panel is clicked.

period:=GetUser(eParm1);

This statement reads the 1st parameter value from the study's parameter form.

SetUser(ePlot1,True);      {plot 1st array}
SetUser(eShow1,True);      {show 1st array}

These statements set the parameters to plot the 1st study line and show the 1st study line value in the study window on the left side of the chart.   Other possible lines and values are not shown.

SetUser(ePercent,True);

This statement sets the parameter to plot the study values on the percent scale.  So, the study values are expected to be in the range of 0..100.

for i:=BarBegin to BarEnd do begin

This loop will perform a calculation for all bars in the data set used by this chart.   i is the index for each bar.

SetUser(2,Abs(Bar(eNet,i)),i);

Here we retrieve the Net for each bar, get its Absolute value, and put it in the 2nd study array.  To set up the average, I used a little trick of storing the absolute value of the Net, (ie. Tick size) in a 2nd temporary study array.   Then I use the Average function to operate on this study array so I do not have to continually reestablish the last Period absolute net values.   The 2nd study array could be plotted if you want to see it.   The SetUser(eUser,1+16) tells the program to show just the 1st study array, but not the 2nd  which holds the raw absolute nets.

SetUser(1,Average(2,i,Period),i);

Here we perform a simple moving average calculation on the data in the 2nd study array, which is the Absolute of the Net value from the previous statement.   The average is put in the 1st study array, which we said earlier we would plot.   That's all you have to do.   Make the calculation and put it in a study array and Ensign Windows will take care of plotting it for you on the chart.