I have the following in my preMain:
setPriceStudy(false);
setPlotType(PLOTTYPE_LINE);
setCursorLabelName("Close");
Then in my main, I have the following:
//get the rawtime value for the current bar
var nTime = getValue( "rawtime", 0 );
if (nTime != null)
{
//get the date value for the prior trading day, if any
var nPriorDay = getPreviousTradingDay(nTime);
if (nPriorDay != null)
{
//get the bar index to the first bar of the day in nTime.
var nFirstBarIndex = getFirstBarIndexOfDay(nTime);
debugPrintln("nFirstBarIndex = " + nFirstBarIndex);
//get the close value for the bar prior to the first bar of the day.
var yesterdaysClose = close(nFirstBarIndex - 1);
debugPrintln("yesterdays close = " + yesterdaysClose);
}
}
When I print out the debug info., the most recent closed bar produces the correct value for yesterday's close but all other's are close but not the same. They are all slightly different and don't seem to correspond with any value on the chart.
I have fixed this algorithm by getting the close value from a daily chart but I would still like to know why this does not work.
Thanks.
setPriceStudy(false);
setPlotType(PLOTTYPE_LINE);
setCursorLabelName("Close");
Then in my main, I have the following:
//get the rawtime value for the current bar
var nTime = getValue( "rawtime", 0 );
if (nTime != null)
{
//get the date value for the prior trading day, if any
var nPriorDay = getPreviousTradingDay(nTime);
if (nPriorDay != null)
{
//get the bar index to the first bar of the day in nTime.
var nFirstBarIndex = getFirstBarIndexOfDay(nTime);
debugPrintln("nFirstBarIndex = " + nFirstBarIndex);
//get the close value for the bar prior to the first bar of the day.
var yesterdaysClose = close(nFirstBarIndex - 1);
debugPrintln("yesterdays close = " + yesterdaysClose);
}
}
When I print out the debug info., the most recent closed bar produces the correct value for yesterday's close but all other's are close but not the same. They are all slightly different and don't seem to correspond with any value on the chart.
I have fixed this algorithm by getting the close value from a daily chart but I would still like to know why this does not work.
Thanks.
Comment