Color Band

The following ESPL example will be executed on a 1-minute chart, but read Stochastic study values from a 5-minute chart.   The ESPL script for this example can be cut and pasted in the ESPL Editor window.

procedure Stochastic5Min;
var indx,handle,chrt,indx2,value,indxStart,indxStop: integer;
  indxStart:=BarBeginLeft; indxStop:=BarEnd;
  chrt:=FindWindow(eChart,'DEMO.5');  {find other chart}
  if chrt>0 then begin                {chart exists}
    handle:=FindStudy(eSTO);          {find study on other chart}
    if handle>0 then begin            {study exists}
      Window:=0;                      {switch back to calling chart}
      for indx:=indxStart to indxStop do begin
        Window:=chrt;                 {switch pointer to other chart}
        if indx2=0 then value:=0
        else value:=2-GetStudy(handle,5,indx2);
        if value=0 then value:=GetStudy(0,0,indx-1);  {use prior value}

begin {main program}
  if ESPL=63 then Stochastic5Min;

This ESPL code will be called by a custom Color Band tool with 63 for the ESPL variable.  Put the Color Band study on the chart and set its parameters as shown here.

The FINDWINDOW command is used to locate the 5-minute DEMO chart.  The 'chrt' variable is then used to reference values, bars, or studies, from the DEMO.5 chart.   The 1-minute chart is running this ESPL study which will look for values on the 5-minute chart.

If the 5-minute chart is found, then the FINDSTUDY command is used to find the Stochastic study on the 5-minute chart.   The 'handle' variable will point to the Stochastic study on the 5-minute chart.

The Window:=0 command causes the ESPL program to change its focus back to the 1-minute chart.

A FOR loop processes the bars on the 1-minute chart.  First an attempt is made to find a Bar Index on the 5-minute chart that matches the 1-minute charts DATE and TIME.   Example: a 10:00 bar is likely to be found on both charts.   If the RETURNED value is found then it can be used, otherwise a ZERO value will be returned.

The 'indx2' variable will now contain the INDEX position of the 10:00 bar (example) in the 5-minute chart, since we are supposedly pointing to the 10:00 bar on the 1-minute chart.   When we process the 10:01 bar, there won't be a matching bar on the 5-minute chart.

If you have multiple studies of the same type on a chart, use the Instance field to find the 2nd study. Example: FindStudy(eSto,1); or FindStudy(eSto,2);   This study allows you to determine the Stochastics values on the 5-minute chart and plot them on the 1-minute chart (at the same time).

The value of the Stochastic is assigned to the variable 'value'  The 'value' value is then plotted as a color band on the 1-minute chart.  The Color Band shows in red when the %K is below the %D on the 5-minute chart, and Green when %K is above %D.