Announcement

Collapse
No announcement yet.

setBar question

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • setBar question

    Hi,

    I wrote a script and want to draw just the last 10 values on the chart.

    When I have

    if (getCurrentBarIndex()>-10) return(v); else return(null);

    in the main, it normally keeps drawing the study when new bars are added.

    So I decided to use setBar(Bar.Value,-10,null) and this causes a crash.

    I just want to erase the -10th. bar's value from the chart on new bars.

    Any idea to do that?

    thanks,

  • #2
    Hello plucky,

    What's happening is that the setBar() function doesn't know what to do with the null value when used in this way. I think it's trying to interpret it as the series number. If you include 0 for the series number you won't crash anymore. However, null still isn't overwriting the value like you're expecting. It ignores the null value in this case. The only thing I could think of that might work for you is to change the foreground color of the line to match the charts background color. This would create the visual effect of what you're trying to accomplish. Try the following code example.

    PHP Code:
    function preMain() {
        
    setStudyTitle("test");
        
    setCursorLabelName("MA");
    }

    var 
    bEdit false;
    var 
    vMA = new MAStudy(100"Close"MAStudy.SIMPLE);

    function 
    main() {
        if (
    bEdit == false) {
            
    setChartBG(Color.white);
            
    bEdit true;
        }
        var 
    vMA.getValue(MAStudy.MA);
        if (
    == null) return;

        if (
    getCurrentBarIndex() <= -10) return;
        
        if (
    getBarState() == BARSTATE_NEWBARsetBar(Bar.FgColor, -100Color.white);
        
        return(
    v);

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment

    Working...
    X