Announcement

Collapse
No announcement yet.

Is it possible to display this indicator as a bar chart?

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

  • Is it possible to display this indicator as a bar chart?

    Hi,

    After struggling for hours (I hope this new documentation will come soon!), I managed to program the Value Chart Indicator.

    However, it is now displayed as lines (see attachment), and I would like to display the output as a barchart, with the current values which make up the blue, red and green lines making up the bar.

    Please see the formula below, never mind the large amount of comments. This was my first!! Any tips on how to do things more economical, are very welcome! Especially I wasn't able to use study.getValue(ATRStudy.ATR) to use the built-in ATR Study to calculate the 5 day MA. So I did the ATR manually
    If anybody can explain to me how I can use the built-in study, that would be most helpful.

    Hope to hear from you about the bar chart option.

    Cheers,

    Edo.


    /************************************************** ****************************************
    Description: This Indicator plots Value Chart Index, as described by Mark Helweg & David Stendahl, and explained
    by René van Mourik in the Dutch magazine: Technische en Kwantitatieve Analyse, november 2002
    The Value Chart Index is a statistical indicator, which indicates overbought and oversold situation

    Provided By: Edo van der Zouwen. Copyright © 2002
    ************************************************** ****************************************/

    /*
    Explanation to the syntaxis:
    Variable Axis = 5 day MA of (hi+lo)/2
    Volatility Unit = 5 day MA of ATR / 5
    Value Chart High = (high - Variable Axis) / Volatility Unit
    Value Chart Low = (low - Variable Axis) / Volatility Unit
    Value Chart Close = (close - Variable Axis) / Volatility Unit

    Contrary to the original description by Helweg & Stendahl, Van Mourik uses ATR to calculate the Volatiliy Unit.
    Originally only high and low were used

    */


    function preMain() {
    setStudyTitle("Value Chart Indicator");

    setCursorLabelName("VC high", 0);
    setCursorLabelName("VC low", 1);
    setCursorLabelName("VC close", 2);
    setDefaultBarFgColor(Color.green, 0);
    setDefaultBarFgColor(Color.red, 1);
    setDefaultBarFgColor(Color.blue, 2);
    addBand (8, PS_DOT, 1, Color.grey);
    addBand (4, PS_DOT, 1, Color.grey);
    addBand (0, PS_DOT, 1, Color.grey);
    addBand (-4, PS_DOT, 1, Color.grey);
    addBand (-8, PS_DOT, 1, Color.grey);

    setPlotType(PLOTTYPE_LINE);
    }


    function main(nInputLength) {
    //Check inputlength - default is 5
    if(nInputLength == null)
    nInputLength = 5;

    //Variable definition
    var nLength = nInputLength;
    var varAxis = 0.0; //Variable Axis
    var volUnit = 0.0; //Volatility Unit
    var valChartHigh = 0.0; //Value chart high
    var valChartLow = 0.0; //Value chart low
    var valChartClose = 0.0; //Value chart close


    var dayhigh; //array dayhigh of nLength period
    var daylow; //array dayhigh of nLength period
    var closey; //array dayhigh of nLength period
    var hilo = 0.0; //Range high - low
    var hicy = 0.0; //Range hi - close yesterday
    var locy = 0.0; //Range lo - close yesterday

    var i;
    var sumhilo = 0.0;
    var sumATR = 0.0;


    //Calculation of Variable Axis

    //load arrays with values
    var dayhigh = getValue("High", 0, -nLength);
    var daylow = getValue("Low", 0, -nLength);
    var closey = getValue("Close", 0, -nLength-1);

    for(i = 0; i < nLength; i++) {
    sumhilo += (dayhigh[i] + daylow[i])/2;
    }
    varAxis = sumhilo / nLength;


    //Calculation MA of ATR and volatility Unit


    for(i = 0; i < nLength; i++) {

    hilo = dayhigh[i] - daylow[i];
    hicy = Math.abs(dayhigh[i] - closey[i+1]);
    locy = Math.abs(daylow[i] - closey[i+1]);

    sumATR += Math.max(hilo, hicy, locy);
    }

    volUnit = sumATR / Math.pow(nLength, 2);


    //Actual Value Chart Index calculation

    var valChartHigh = (dayhigh[0] - varAxis) / volUnit;
    var valChartLow = (daylow[0] - varAxis) / volUnit;
    var valChartClose = (closey[0] - varAxis) / volUnit;


    //Output
    return new Array(valChartHigh, valChartLow, valChartClose);


    }
    Attached Files
    Last edited by EdKoF; 12-10-2002, 10:35 AM.

  • #2
    Hello Edo,

    To change your lines into bars for a histogram, change setPlotType() in preMain():

    Code:
    // setPlotType(PLOTTYPE_LINE);
    
    setPlotType(PLOTTYPE_HISTOGRAM,0);
    setPlotType(PLOTTYPE_HISTOGRAM,1);
    setPlotType(PLOTTYPE_HISTOGRAM,2);
    Where you were trying to use getValue(ATRStudy.ATR), did you var a study object for an ATRStudy(length)? If you follow the example below you should be able to use your getValue(ATRStudy.ATR) statement.

    Code:
    var study = new ATRStudy(14);
    
    function main() {
    
        // return study.getValue(ATRStudy.ATR);
        // or
        
        var myATR = study.getValue(ATRStudy.ATR);
        return myATR;
    }
    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


    • #3
      Thanks Jason!

      Concerning the bars, please see the attachment for the result. I have used FLATLINES for the 3rd value (CLose). It looks better, but not yet great. Is it possible to make a Hi-Lo-Close kind of Barchart, which looks more traditional?

      Concerning the built-in ATR, I run into the problem that eSignal's ATR calculation is rather different than my manual calculation which, by the way, is the same as Metastock's calculation.


      For those who are interested:

      It seems eSignal is using a very sophisticated version. The manual says:
      Because there must be a beginning, the first ATR value in a series is simply the high minus the low and the first xx-day
      However, in a rolling calculation, there is always a previous close, execept for the first day of trade of the stock.

      Also, eSignal seems to smooth the calculation (I can't reproduce this however) by calculating the next xx-day ATR from the previous value. See manual page 21-28 for this).



      Well not too much you can do with this, just I'll stick to my manual calculation for the time being. Hope it was informative

      Cheers,

      Edo.
      Attached Files

      Comment

      Working...
      X