I am trying to use setBar() to change the indicator values of previous 50 bars when getCurrentBarIndex() == -20, however it seems setBar() did not work as I expected. I am expecting the test script shows a black line segment between bar -21 and -70, what was wrong?
- Clearpicks
var returnArray;
function preMain()
{
setPriceStudy(true);
setStudyTitle("TestSetBar");
}
function main()
{
if ( getBarState() == BARSTATE_ALLBARS ) {
returnArray = new Array(1);
returnArray[0] = close(0);
setDefaultBarThickness(4, 0);
setDefaultBarStyle(PS_DASH, 0);
setPlotType(PLOTTYPE_FLATLINES, 0);
setDefaultBarFgColor(Color.lime, 0);
}
if ( getCurrentBarIndex() == -20 ) {
var highColor = Color.RGB(255, 153, 0);
returnArray[1] = close(0);
setDefaultBarThickness(4, 1);
setDefaultBarStyle(PS_DASH, 1);
setPlotType(PLOTTYPE_FLATLINES, 1);
setDefaultBarFgColor(highColor, 1);
var j;
for ( j = 1; j < 50; j ++ ) {
setBar(Bar.Value, -j, 1, returnArray[1] );
setBar(Bar.FgColor, -j, 1, Color.black );
setBar(Bar.Thickness, -j, 1, 4 );
setBar(Bar.Style, -j, 1, PLOTTYPE_FLATLINES );
}
}
return returnArray;
}
- Clearpicks
var returnArray;
function preMain()
{
setPriceStudy(true);
setStudyTitle("TestSetBar");
}
function main()
{
if ( getBarState() == BARSTATE_ALLBARS ) {
returnArray = new Array(1);
returnArray[0] = close(0);
setDefaultBarThickness(4, 0);
setDefaultBarStyle(PS_DASH, 0);
setPlotType(PLOTTYPE_FLATLINES, 0);
setDefaultBarFgColor(Color.lime, 0);
}
if ( getCurrentBarIndex() == -20 ) {
var highColor = Color.RGB(255, 153, 0);
returnArray[1] = close(0);
setDefaultBarThickness(4, 1);
setDefaultBarStyle(PS_DASH, 1);
setPlotType(PLOTTYPE_FLATLINES, 1);
setDefaultBarFgColor(highColor, 1);
var j;
for ( j = 1; j < 50; j ++ ) {
setBar(Bar.Value, -j, 1, returnArray[1] );
setBar(Bar.FgColor, -j, 1, Color.black );
setBar(Bar.Thickness, -j, 1, 4 );
setBar(Bar.Style, -j, 1, PLOTTYPE_FLATLINES );
}
}
return returnArray;
}
Comment