PriceMA.efs
EFSLibrary - Discussion Board
File Name: PriceMA.efs
Description:
Trading High Yield Bonds Using ETFs by Brooke Gardner.
Formula Parameters:
PriceMA.efs
- Price Source: Close
- MA Period: 8
- MA Type: Simple
Notes:
The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.
Download File:
PriceMA.efs
PriceMA.efs
EFS Code:
PriceMA.efs
/********************************* Provided By: Interactive Data Corporation (Copyright © 2012) All rights reserved. This sample eSignal Formula Script (EFS) is for educational purposes only. Interactive Data Corporation reserves the right to modify and overwrite this EFS file with each new release. Description: Trading High Yield Bonds Using ETFs by Brooke Gardner. Version: 1.0 5/04/2012 Formula Parameters: Default: Price Source Close MA Period 8 MA Type Simple Notes: The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com. **********************************/ var fpArray = new Array(); function preMain() { setPriceStudy(true); setCursorLabelName("MA", 0); var x=0; fpArray[x] = new FunctionParameter("priceSource", FunctionParameter.STRING); with(fpArray[x++]) { setName("Price Source"); addOption("Open"); addOption("Close"); addOption("Low"); addOption("High"); addOption("HL/2"); addOption("HLC/3"); addOption("OHLC/4"); setDefault("Close"); } fpArray[x] = new FunctionParameter("maPeriod", FunctionParameter.NUMBER); with(fpArray[x++]) { setName("MA Period"); setLowerLimit(1); setDefault(8); } fpArray[x] = new FunctionParameter("maType", FunctionParameter.STRING); with(fpArray[x++]) { setName("MA Type"); addOption("Simple"); addOption("Exponential"); addOption("Weighted"); addOption("Volume Weighted"); setDefault("Simple"); } } var bInit = false; var bVersion = null; var xSource = null; var xMA = null; var i = 0; function main(priceSource, maPeriod, maType) { if (bVersion == null) bVersion = verify(); if (bVersion == false) return; // Back Testing formulas are not for real time analysis. // Therefore, prevent processing and exit at bar 0. if (getCurrentBarIndex() == 0) return; if (!bInit) { switch (priceSource) { case 'Open': xSource = open(); break; case 'Close': xSource = close(); break; case 'High': xSource = high(); break; case 'Low': xSource = low(); break; case 'HL/2': xSource = hl2(); break; case 'HLC/3': xSource = hlc3(); break; case 'OHLC/4': xSource = ohlc4(); break; default : xSource = close(); } switch (maType) { case "Simple" : xMA = sma(maPeriod, xSource); break; case "Exponential" : xMA = ema(maPeriod, xSource); break; case "Weighted" : xMA = wma(maPeriod, xSource); break; case "Volume Weighted" : xMA = vwma(maPeriod, xSource); break; default : xMA = sma(maPeriod, xSource); } bInit = true; } var nPrice = xSource.getValue(0); var vMA = xMA.getValue(0); // Exit Strategy if (Strategy.isInTrade()) { if (Strategy.isLong() && nPrice < vMA) { Strategy.doSell("Long Exit Signal", Strategy.CLOSE, Strategy.THISBAR); } else if (Strategy.isShort() && nPrice > vMA) { Strategy.doCover("Short Exit Signal", Strategy.CLOSE, Strategy.THISBAR); } } // Entry Strategy if (!Strategy.isInTrade()) { if (nPrice > vMA) { Strategy.doLong("Long signal", Strategy.CLOSE, Strategy.THISBAR); drawShape(Shape.UPARROW, AboveBar1, Color.lime, i++); } else if (nPrice < vMA) { Strategy.doShort("Short signal", Strategy.CLOSE, Strategy.THISBAR); drawShape(Shape.DOWNARROW, BelowBar1, Color.red, i++); } } return xMA.getValue(0); } // verify version function verify() { var b = false; if (getBuildNumber() < 779) { drawTextAbsolute(5, 35, "This study requires version 8.0 or later.", Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT, null, 13, "error"); drawTextAbsolute(5, 20, "Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp", Color.white, Color.blue, Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT|Text.BOLD|Text.LEFT, null, 13, "upgrade"); return b; } else { b = true; } return b; }