MovingAverageRibbon.efs
EFSLibrary - Discussion Board
File Name: MovingAverageRibbon.efs
Description:
Moving Average Ribbon
Formula Parameters:
- Base Length: 10
- Arithmetic Or Geometric 1 Or 2: 1
- Increment Or Multiplier: 10
- Line Thickness: 2
- Display Title Value: False
Notes:
Plots a "Moving Average Ribbon" using the gradient color system V it is created using a series of exponential moving averages of various lengths. The lengths of the averages are calculated based on the length of the first moving average line which is set by the input BaseLength.
Each subsequent length is calculated based on the ArithOrGeom_1or2 input.
Download File:
MovingAverageRibbon.efs
EFS Code:
/********************************* Provided By: eSignal (Copyright c eSignal), a division of Interactive Data Corporation. 2008. 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: Moving Average Ribbon Version: 1.0.0 22/09/2008 Formula Parameters: Default: * Base Length 10 * Arithmetic Or Geometric 1 Or 2 1 * Increment Or Multiplier 10 * Line Thickness 2 * Display Title Value False Notes: Plots a "Moving Average Ribbon" using the gradient color system – it is created using a series of exponential moving averages of various lengths. The lengths of the averages are calculated based on the length of the first moving average line which is set by the input BaseLength. Each subsequent length is calculated based on the ArithOrGeom_1or2 input. **********************************/ var fpArray = new Array(); var bInit = false; function preMain() { setPriceStudy(true); setShowCursorLabel(false); setShowTitleParameters( false ); setStudyTitle("Moving Average Ribbon"); setCursorLabelName("XMA1", 0); setCursorLabelName("XMA2", 1); setCursorLabelName("XMA3", 2); setCursorLabelName("XMA4", 3); setCursorLabelName("XMA5", 4); setCursorLabelName("XMA6", 5); setCursorLabelName("XMA7", 6); setCursorLabelName("XMA8", 7); setDefaultBarFgColor(Color.RGB(255,255,0), 7); setDefaultBarFgColor(Color.RGB(255,200,0), 6); setDefaultBarFgColor(Color.RGB(255,150,0), 5); setDefaultBarFgColor(Color.RGB(255,150,0), 4); setDefaultBarFgColor(Color.RGB(255,100,0), 3); setDefaultBarFgColor(Color.RGB(255,50,0), 2); setDefaultBarFgColor(Color.RGB(255,0,0), 1); setDefaultBarFgColor(Color.RGB(255,0,0), 0); setPlotType(PLOTTYPE_LINE, 0); setPlotType(PLOTTYPE_LINE, 1); setPlotType(PLOTTYPE_LINE, 2); setPlotType(PLOTTYPE_LINE, 3); setPlotType(PLOTTYPE_LINE, 4); setPlotType(PLOTTYPE_LINE, 5); setPlotType(PLOTTYPE_LINE, 6); setPlotType(PLOTTYPE_LINE, 7); setDefaultBarThickness(2, 0); setDefaultBarThickness(2, 1); setDefaultBarThickness(2, 2); setDefaultBarThickness(2, 3); setDefaultBarThickness(2, 4); setDefaultBarThickness(2, 5); setDefaultBarThickness(2, 6); setDefaultBarThickness(2, 7); askForInput(); var x=0; fpArray[x] = new FunctionParameter("ViewValue", FunctionParameter.BOOLEAN); with(fpArray[x++]){ setName("Display Cursor Labels"); setDefault(false); } fpArray[x] = new FunctionParameter("BaseLength", FunctionParameter.NUMBER); with(fpArray[x++]){ setName("Base Length"); setLowerLimit(1); setDefault(10); } fpArray[x] = new FunctionParameter("ArithOrGeom_1or2", FunctionParameter.NUMBER); with(fpArray[x++]){ setName("Arithmetic Or Geometric (1 Or 2)"); setLowerLimit(1); setDefault(1); } fpArray[x] = new FunctionParameter("IncrementOrMultiplier", FunctionParameter.NUMBER); with(fpArray[x++]){ setName("Increment Or Multiplier"); setLowerLimit(1); setDefault(10); } fpArray[x] = new FunctionParameter("Thickness", FunctionParameter.NUMBER); with(fpArray[x++]){ setName("Line Thickness"); setLowerLimit(1); setDefault(2); } } var aLength = new Array(8); var aSmoothingFactor = new Array(8); var aXMA = new Array(8); var aXMA_Ref = new Array(8); var aColor = new Array(8); function main(BaseLength, ArithOrGeom_1or2, IncrementOrMultiplier, Thickness, ViewValue) { var nCounter = 0; var nState = getBarState(); if ( bInit == false ) { setDefaultBarThickness(Thickness, 0); setDefaultBarThickness(Thickness, 1); setDefaultBarThickness(Thickness, 2); setDefaultBarThickness(Thickness, 3); setDefaultBarThickness(Thickness, 4); setDefaultBarThickness(Thickness, 5); setDefaultBarThickness(Thickness, 6); setDefaultBarThickness(Thickness, 7); setShowCursorLabel(ViewValue); ClearArrays(); bInit = true; } if (nState == BARSTATE_NEWBAR) { for (var i = 1; i <= 8; i++) { aXMA_Ref[i] = aXMA[i]; } } if (getCurrentBarCount() == 1 ) { aLength[1] = BaseLength ; aSmoothingFactor[1] = 2 / ( aLength[1] + 1 ); aXMA[1] = close(0); for (nCounter = 1; nCounter <= 7; nCounter++) { if (ArithOrGeom_1or2 == 1) aLength[nCounter + 1] = aLength[nCounter] + IncrementOrMultiplier; else aLength[nCounter + 1] = aLength[nCounter] * IncrementOrMultiplier; aSmoothingFactor[nCounter + 1] = 2 / (aLength[nCounter + 1] + 1); aXMA[nCounter + 1] = close(0); } } else { for (nCounter = 1; nCounter <= 8; nCounter++) { aXMA[nCounter] = aXMA_Ref[nCounter] + aSmoothingFactor[nCounter] * (close(0) - aXMA_Ref[nCounter]); } } return new Array(aXMA[8], aXMA[7], aXMA[6], aXMA[5], aXMA[4], aXMA[3], aXMA[2], aXMA[1]); } function ClearArrays(){ for (var i = 1; i <= 8; i++) { aLength[i] = 0; aSmoothingFactor[i] = 0; aXMA[i] = 0; aXMA_Ref[i] = 1; aColor[i] = 0; } }