EntropyMath.efs
EFSLibrary - Discussion Board
File Name: EntropyMath.efs
Description:
Entropy Math
Formula Parameters:
- Length : 14
- Upper : 0.0001
- Lower : -0.0001
Notes:
Download File:
EntropyMath.efs
EFS Code:
/********************************* Provided By: eSignal (Copyright c eSignal), a division of Interactive Data Corporation. 2009. All rights reserved. This sample eSignal Formula Script (EFS) is for educational purposes only and may be modified and saved under a new file name. eSignal is not responsible for the functionality once modified. eSignal reserves the right to modify and overwrite this EFS file with each new release. Description: Entropy Math Version: 1.0 08/26/2009 Formula Parameters: Default: Length 14 Upper 0.0001 Lower -0.0001 Notes: **********************************/ var fpArray = new Array(); var bInit = false; function preMain(){ setPriceStudy(false); setShowCursorLabel(true); setShowTitleParameters(false); setStudyTitle("Entropy Math"); setCursorLabelName("Entropy Math", 0); setDefaultBarFgColor(Color.blue, 0); setPlotType(PLOTTYPE_LINE, 0); var x = 0; fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER); with(fpArray[x++]) { setName("Length"); setLowerLimit(1); setDefault(14); } fpArray[x] = new FunctionParameter("Upper", FunctionParameter.NUMBER); with(fpArray[x++]) { setName("Upper"); setDefault(0.0001); } fpArray[x] = new FunctionParameter("Lower", FunctionParameter.NUMBER); with(fpArray[x++]) { setName("Lower"); setDefault(-0.0001); } } var xEntropy = null; function main(Length, Upper, Lower) { var nBarState = getBarState(); var nEntropy = 0; if (nBarState == BARSTATE_ALLBARS) { if(Length == null) Length = 14; } if (bInit == false) { addBand(Upper, PS_DASHDOT, 2, Color.black, "Upper"); addBand(Lower, PS_DASHDOT, 2, Color.black, "Lower"); xEntropy = efsInternal("Calc_EntropyMath", Length); bInit = true; } nEntropy = xEntropy.getValue(0); if (nEntropy == null) return; return nEntropy; } var bSecondInit = false; var xClose = null; function Calc_EntropyMath(Length) { var nRes = 0; var nR = 0; var sumx = 0; var sumx2 = 0; var avgx = 0; var rmsx = 0; var nP = 0; var i = 0; if (!bSecondInit) { xClose = close(); bSecondInit = true; } if (xClose.getValue(-Length) == null) return; for (i = 0; i < Length; i++) { nR = Math.log(xClose.getValue(-i) / xClose.getValue(-i-1)); sumx += nR; sumx2 += nR * nR; } avgx = sumx / Length; rmsx = Math.sqrt(sumx2/Length); nP = ((avgx / rmsx) + 1) / 2.0; nRes = nP * Math.log(1 + rmsx) + (1 - nP) * Math.log(1 - rmsx); return nRes; }