Announcement

Collapse
No announcement yet.

Decimal precision of MACD

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

  • Decimal precision of MACD

    Does anybody know if its possible to increase the decimal places on the MACD Signal line and the MACD line from 2 to 4 places.

  • #2
    Is this what you wanted?

    PHP Code:
    /*************************************
    Alexis C. Montenegro © July 2003                          
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a 
    description of any changes you make.      


    Modifying Programmer:  Avery T. Horton, Jr.   
     
    Added inputs for decimals places and button
                    
    **********************************/

    var vMACD null;

    function 
    preMain() {
        
    setStudyTitle("TRO_MACD");
        
    setCursorLabelName("MACDHist",0);
        
    setCursorLabelName("MACD",1);
        
    setCursorLabelName("MACDSig",2);
        
    setDefaultBarFgColor(Color.magenta,0); 
        
    setDefaultBarFgColor(Color.blue,1); 
        
    setDefaultBarFgColor(Color.red,2); 
        
    setDefaultBarThickness(1,0);
        
    setDefaultBarThickness(1,1);
        
    setDefaultBarThickness(1,2);
        
    setPlotType(PLOTTYPE_HISTOGRAM); 
        

        var 
    iDecimals = new FunctionParameter("iDecimals"FunctionParameter.NUMBER);
        
    iDecimals.setDefault()


        var 
    iButtonX = new FunctionParameter("iButtonX"FunctionParameter.NUMBER);
        
    iButtonX.setDefault50 ); 

        var 
    iButtonY = new FunctionParameter("iButtonY"FunctionParameter.NUMBER);
        
    iButtonY.setDefault15 ); 


        var 
    iFontSize = new FunctionParameter("iFontSize"FunctionParameter.NUMBER);
        
    iFontSize.setDefault10 ); 

        var 
    fp1 = new FunctionParameter("Fast"FunctionParameter.NUMBER);
        
    fp1.setLowerLimit(1);        
        
    fp1.setDefault(12); //Edit this value to set a new default    
        
        
    var fp2 = new FunctionParameter("Slow"FunctionParameter.NUMBER);
        
    fp2.setLowerLimit(1);        
        
    fp2.setDefault(26); //Edit this value to set a new default    
        
        
    var fp3 = new FunctionParameter("Smoothing"FunctionParameter.NUMBER);
        
    fp3.setLowerLimit(1);        
        
    fp3.setDefault(9); //Edit this value to set a new default    
        
        
    var fp4 = new FunctionParameter("Source"FunctionParameter.STRING);
        
    fp4.setName("Source");
        
    fp4.addOption("Close");
        
    fp4.addOption("High");
        
    fp4.addOption("Low");
        
    fp4.addOption("Open");
        
    fp4.addOption("HL/2");
        
    fp4.addOption("HLC/3");
        
    fp4.addOption("OHLC/4");
        
    fp4.setDefault("Close"); //Edit this value to set a new default    
        
        
    var fp5 = new FunctionParameter("TypeOsc"FunctionParameter.BOOLEAN);
        
    fp5.setName("SMA (Oscillator)");
        
    fp5.setDefault(false); //Edit this value to set a new default    
        
        
    var fp5 = new FunctionParameter("TypeSig"FunctionParameter.BOOLEAN);
        
    fp5.setName("SMA (Signal)");
        
    fp5.setDefault(true); //Edit this value to set a new default    
            
    }

    function 
    main(FastSlowSmoothingSourceTypeOscTypeSig 
                  
    iDecimals iFontSizeiButtonXiButtonY) {

      
    // initialize upon first loading formula
        
    if(getBarState() == BARSTATE_ALLBARS) {
            
    drawTextPixel(iButtonXiButtonY" TRO_MACD @URL=EFS:editParameters"Color.whiteColor.green
                
    Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM|Text.ONTOP|Text.BOLD|Text.BUTTON
                
    "Comic Sans MS"13"UpExp"); 
            
    vDate = new Date();
            
    vInterval getInterval();
            
    vSymbol getSymbol().toUpperCase();
        
            
    // for RTH, eg, to convert, ES Z2 to ES Z2=2
            
    var rootSymbol vSymbol.substring(0,3);
            if (
    rootSymbol == "ES " || rootSymbol == "NQ "
                if ( 
    vSymbol.indexOf("=2") == -vSymbol += "=2";
        
            
    vSymbol += ",D";
            return 
    null;
        }

        if (
    vMACD == nullvMACD = new MACDStudy(FastSlowSmoothingSourceTypeOscTypeSig);
                
    /*********************************************
    Insert your code following this text block    
    Use vMACD.getValue(MACDStudy.HIST) and        
    vMACD.getValue(MACDStudy.MACD) and            
    vMACD.getValue(MACDStudy.SIGNAL) for your code
    **********************************************/


    //  return new Array(vMACD.getValue(MACDStudy.HIST),vMACD.getValue(MACDStudy.MACD),vMACD.getValue(MACDStudy.SIGNAL));


    var xHist rndvMACD.getValue(MACDStudy.HIST) , iDecimals);
    var 
    xMACD rndvMACD.getValue(MACDStudy.MACD) , iDecimals);
    var 
    xSIGNAL rndvMACD.getValue(MACDStudy.SIGNAL) , iDecimals);

    return new Array( 
    xHist xMACD xSIGNAL ) ;
       
    }


    function 
    editParameters() {
        
    askForInput("TRO_MACD");
        return;
    }


    // rnd function - round to iDecimals places
    function rnd(valueiDecimals ) {  

    value =  value Math.pow(10iDecimals);

        return 
    Math.round(valueiDecimals) / Math.pow(10iDecimals);

    Last edited by buzzhorton; 07-31-2006, 09:29 AM.

    Comment

    Working...
    X