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.
Announcement
Collapse
No announcement yet.
Decimal precision of MACD
Collapse
X
-
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(4 )
var iButtonX = new FunctionParameter("iButtonX", FunctionParameter.NUMBER);
iButtonX.setDefault( 50 );
var iButtonY = new FunctionParameter("iButtonY", FunctionParameter.NUMBER);
iButtonY.setDefault( 15 );
var iFontSize = new FunctionParameter("iFontSize", FunctionParameter.NUMBER);
iFontSize.setDefault( 10 );
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(Fast, Slow, Smoothing, Source, TypeOsc, TypeSig ,
iDecimals , iFontSize, iButtonX, iButtonY) {
// initialize upon first loading formula
if(getBarState() == BARSTATE_ALLBARS) {
drawTextPixel(iButtonX, iButtonY, " TRO_MACD @URL=EFS:editParameters", Color.white, Color.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") == -1 ) vSymbol += "=2";
vSymbol += ",D";
return null;
}
if (vMACD == null) vMACD = new MACDStudy(Fast, Slow, Smoothing, Source, TypeOsc, TypeSig);
/*********************************************
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 = rnd( vMACD.getValue(MACDStudy.HIST) , iDecimals);
var xMACD = rnd( vMACD.getValue(MACDStudy.MACD) , iDecimals);
var xSIGNAL = rnd( vMACD.getValue(MACDStudy.SIGNAL) , iDecimals);
return new Array( xHist , xMACD , xSIGNAL ) ;
}
function editParameters() {
askForInput("TRO_MACD");
return;
}
// rnd function - round to iDecimals places
function rnd(value, iDecimals ) {
value = value * Math.pow(10, iDecimals);
return Math.round(value, iDecimals) / Math.pow(10, iDecimals);
}
Last edited by buzzhorton; 07-31-2006, 10:29 AM.
Comment