Color BandThe 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.
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.