I am using the following efs to plot the pro rata volume on a 5min chart. The estimated volume for each complete bar is plotted in grey behind the actual volume bar.
If no data arrrives in the last 15 secs of a bar, the pro rata grey bar remains uncleared on "old" bars. Is there a way that I can ensure that the grey bar is cleared for all bars prior to the current bar? At present I clean up the chart every so often by doing a manual "reload".
/************************************************** *******
This eSignal script plots volume in a typical manner with
an underlay of the prorated volume until the end of the
five minute bar. The first plot is the prorated volume and
the second is the actual current volume. This is so the
actual volume plots on top of the prorated volume.
StephenR0
************************************************** ********/
function preMain() {
setPriceStudy(false); // so it gets its own section
setStudyTitle("prv5");
//set up the first plot
setCursorLabelName("Prorated", 0);
setDefaultBarFgColor(Color.lightgrey, 0);
setDefaultBarThickness(4,0);
setPlotType(PLOTTYPE_HISTOGRAM, 0);
// set up the second plot
setCursorLabelName("Volume", 1);
setDefaultBarFgColor(Color.black, 1); // this is changed below
setDefaultBarThickness(2,1);
setPlotType(PLOTTYPE_HISTOGRAM, 1);
setStudyMin (0);
}
/* The main function is called with each incoming data item. This
means that nothing will plot if no data comes in. */
function main() {
var Today = new Date ();
var Minutes = Today.getMinutes();
var Seconds = Today.getSeconds();
var BarSeconds = 0;
var Vol = 0;
var Open = 0;
var Close = 0;
var VolP = 0;
Vol = volume();
Open = open();
Close = close();
if(Vol == null){
return;
}
/* Set the volume bar color if higher or lower. */
if (Close >= Open)
setBarFgColor(Color.black, 1);
else
setBarFgColor(Color.red, 1);
// First, determine how many seconds we are into this bar.
Minutes = Minutes - (Math.floor(Minutes/5)*5);
BarSeconds = Minutes*60 + Seconds;
/* Now, prorate the current volume for the rest of the bar.
Don't plot for the first thirty seconds to try to dampen some of the
wild swings that would happen otherwise. In addition, don't plot
the prorated volume for the previous bars. */
if (BarSeconds <= 30 || BarSeconds > 285 || getCurrentBarIndex() < 0){
VolP = 0;
} else {
VolP = (Vol/BarSeconds)*300;
}
/* Limit the scaling of the prorated volume because wild swings
aren't real anyway. */
if (VolP >= 25000){
VolP = 25000;
setBarFgColor(Color.RGB(255,192,192), 0); // light pink
} else {
setBarFgColor(Color.lightgrey, 0);
}
// Return the array in the right order for our plots.
return new Array (VolP, Vol);
}
If no data arrrives in the last 15 secs of a bar, the pro rata grey bar remains uncleared on "old" bars. Is there a way that I can ensure that the grey bar is cleared for all bars prior to the current bar? At present I clean up the chart every so often by doing a manual "reload".
/************************************************** *******
This eSignal script plots volume in a typical manner with
an underlay of the prorated volume until the end of the
five minute bar. The first plot is the prorated volume and
the second is the actual current volume. This is so the
actual volume plots on top of the prorated volume.
StephenR0
************************************************** ********/
function preMain() {
setPriceStudy(false); // so it gets its own section
setStudyTitle("prv5");
//set up the first plot
setCursorLabelName("Prorated", 0);
setDefaultBarFgColor(Color.lightgrey, 0);
setDefaultBarThickness(4,0);
setPlotType(PLOTTYPE_HISTOGRAM, 0);
// set up the second plot
setCursorLabelName("Volume", 1);
setDefaultBarFgColor(Color.black, 1); // this is changed below
setDefaultBarThickness(2,1);
setPlotType(PLOTTYPE_HISTOGRAM, 1);
setStudyMin (0);
}
/* The main function is called with each incoming data item. This
means that nothing will plot if no data comes in. */
function main() {
var Today = new Date ();
var Minutes = Today.getMinutes();
var Seconds = Today.getSeconds();
var BarSeconds = 0;
var Vol = 0;
var Open = 0;
var Close = 0;
var VolP = 0;
Vol = volume();
Open = open();
Close = close();
if(Vol == null){
return;
}
/* Set the volume bar color if higher or lower. */
if (Close >= Open)
setBarFgColor(Color.black, 1);
else
setBarFgColor(Color.red, 1);
// First, determine how many seconds we are into this bar.
Minutes = Minutes - (Math.floor(Minutes/5)*5);
BarSeconds = Minutes*60 + Seconds;
/* Now, prorate the current volume for the rest of the bar.
Don't plot for the first thirty seconds to try to dampen some of the
wild swings that would happen otherwise. In addition, don't plot
the prorated volume for the previous bars. */
if (BarSeconds <= 30 || BarSeconds > 285 || getCurrentBarIndex() < 0){
VolP = 0;
} else {
VolP = (Vol/BarSeconds)*300;
}
/* Limit the scaling of the prorated volume because wild swings
aren't real anyway. */
if (VolP >= 25000){
VolP = 25000;
setBarFgColor(Color.RGB(255,192,192), 0); // light pink
} else {
setBarFgColor(Color.lightgrey, 0);
}
// Return the array in the right order for our plots.
return new Array (VolP, Vol);
}
Comment