I'm looking for an elegant streamlined solution to plot lines based on values at specific dates on a chart from one timeframe into another whether it is a higher or lower timeframe from which the values have been derived.
At the moment I have been forced to use the addBand() function, although good, is not exactly what I want, and all I have come up with as an alternative, is horribly complex and ultimately cpu intensive. So if anyone has a nicer solution it would be much appreciated.
Requirements to plot data in any timeframe using drawLineRelative() function from the specific bar index where the value has been derived from to the current bar. If this is impossible because of intraday data only being available for 6 months, then from the first bar of the series to the current bar:-
1. End of Year Pivot
2. Quarterly Pivots
3. 52 Week High/Low
Here is a code fragment which works in daily charts for Requirements 1 and 2 above, but will not work in any other timeframe and addBand() has to be used:-
// ****************************************
if ( getBarState() == BARSTATE_ALLBARS ){
// ----------------------------------------
var nDateM, nBarIndexM;
// ----------------------------------------
return null;
} // END ALLBARS
// ========================================
...
...
// ****************************************
if ( getBarState() == BARSTATE_NEWBAR ){
// ----------------------------------------
if (isDaily() == true){
nDateM = new Date(getYear(0), 8, 30);
if ( nDateM != null ) {
nBarIndexM = getFirstBarIndexOfDay( nDateM );
if ( nBarIndexM != null ) {
//grab the closing price from that bar
nQtr3m = close( nBarIndexM );
}
}
drawLineRelative( nBarIndexM, nQtr3m, -0, nQtr3m, sQtrStyM, nQtrThkP, cAnnCurUpP, "qtr3B" );
}else{
nQtr3m = getValueAbsolute( "Close", -0+(9-nMthCurM), sMthSymG );
addBand(nQtr3m, sQtrStyM, nQtrThkP, cAnnCurUpP, "qtr3B");
}
// ----------------------------------------
} // end Newbar
// ========================================
Robert
At the moment I have been forced to use the addBand() function, although good, is not exactly what I want, and all I have come up with as an alternative, is horribly complex and ultimately cpu intensive. So if anyone has a nicer solution it would be much appreciated.
Requirements to plot data in any timeframe using drawLineRelative() function from the specific bar index where the value has been derived from to the current bar. If this is impossible because of intraday data only being available for 6 months, then from the first bar of the series to the current bar:-
1. End of Year Pivot
2. Quarterly Pivots
3. 52 Week High/Low
Here is a code fragment which works in daily charts for Requirements 1 and 2 above, but will not work in any other timeframe and addBand() has to be used:-
// ****************************************
if ( getBarState() == BARSTATE_ALLBARS ){
// ----------------------------------------
var nDateM, nBarIndexM;
// ----------------------------------------
return null;
} // END ALLBARS
// ========================================
...
...
// ****************************************
if ( getBarState() == BARSTATE_NEWBAR ){
// ----------------------------------------
if (isDaily() == true){
nDateM = new Date(getYear(0), 8, 30);
if ( nDateM != null ) {
nBarIndexM = getFirstBarIndexOfDay( nDateM );
if ( nBarIndexM != null ) {
//grab the closing price from that bar
nQtr3m = close( nBarIndexM );
}
}
drawLineRelative( nBarIndexM, nQtr3m, -0, nQtr3m, sQtrStyM, nQtrThkP, cAnnCurUpP, "qtr3B" );
}else{
nQtr3m = getValueAbsolute( "Close", -0+(9-nMthCurM), sMthSymG );
addBand(nQtr3m, sQtrStyM, nQtrThkP, cAnnCurUpP, "qtr3B");
}
// ----------------------------------------
} // end Newbar
// ========================================
Robert
Comment