/*********************************Provided By: eSignal (Copyright c eSignal), a division of Interactive Data Corporation. 2016. 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 responsiblefor the functionality once modified. eSignal reserves the right to modify and overwrite this EFS file with each new release.Description: ATR Breakout Entries by Ken CalhounVersion: 1.00 02/08/2016Formula Parameters: Default:ATR Length 14Highest ATR Lookback 14SMA Length 100Use Wide Range condition trueWide Range Lookback 7Trailing Stop 2Notes:The related article is copyrighted material. If you are not a subscriberof Stocks & Commodities, please visit www.traders.com.**********************************/var fpArray = new Array();function preMain(){ setPriceStudy(true); setCursorLabelName("SMA"); var x=0; fpArray[x] = new FunctionParameter("ATRLength", FunctionParameter.NUMBER); with(fpArray[x++]){ setLowerLimit(1); setUpperLimit(1000); setDefault(14); setName("ATR Length"); } fpArray[x] = new FunctionParameter("ATRlb", FunctionParameter.NUMBER); with(fpArray[x++]){ setLowerLimit(1); setUpperLimit(1000); setDefault(14); setName("Highest ATR Lookback"); } fpArray[x] = new FunctionParameter("SMALength", FunctionParameter.NUMBER); with(fpArray[x++]){ setLowerLimit(1); setUpperLimit(1000); setDefault(100); setName("SMA Length"); } fpArray[x] = new FunctionParameter("isWR", FunctionParameter.BOOLEAN); with(fpArray[x++]){ setDefault(true); setName("Use Wide Range condition"); } fpArray[x] = new FunctionParameter("RangeLen", FunctionParameter.NUMBER); with(fpArray[x++]){ setLowerLimit(1); setUpperLimit(1000); setDefault(7); setName("Wide Range Lookback"); } fpArray[x] = new FunctionParameter("TrlStop", FunctionParameter.NUMBER); with(fpArray[x++]){ setLowerLimit(0.01); setDefault(2); setName("Trailing Stop"); }}var bInit = false;var bVersion = null;var xClose = null;var xHigh = null;var xLow = null;var bIsLong = false;var bEntryFound = false;var vStopPrice = null;var vHighOfDay = null;var xSMA = null;var xATR = null;var xHighestATR = null;var xRange = null;var xWR = null;var vHighestHigh = null;function main(ATRLength,ATRlb,SMALength,isWR,RangeLen, TrlStop){ if (bVersion == null) bVersion = verify(); if (bVersion == false) return; if(getBarState() == BARSTATE_ALLBARS){ xClose = null; xHigh = null; xLow = null; bIsLong = false; bEntryFound = false; vStopPrice = null; bVersion = null; vHighOfDay = null; xSMA = null; xATR = null; xHighestATR = null; xRange = null; xWR = null; vHighestHigh = null; bInit = false; } if (!bInit){ bIsLong = false; bEntryFound = false; xClose = close(); xHigh = high(); xLow = low(); xSMA = sma(SMALength); xATR = atr(ATRLength); xHighestATR = hhv(ATRlb, xATR); if (isWR){ xRange = efsInternal("calcRange", inv("D")); xWR = upperDonchian(RangeLen-1,xRange); } bInit = true; } if(xSMA.getValue(-1) == null) return; var nATR = xATR.getValue(0); var nSMA = xSMA.getValue(0); var nPrevSMA = xSMA.getValue(-1); var nPrevHATR = xHighestATR.getValue(-1) var nClose = xClose.getValue(0); var nLow = xLow.getValue(0); var nHigh = xHigh.getValue(0); var nPrevHigh = xHigh.getValue(-1); if (bIsLong){ if (nHigh > vHighestHigh && (nLow - TrlStop) > vStopPrice) { vStopPrice = (nLow - TrlStop); vHighestHigh = nHigh } else if (nLow <= vStopPrice){ drawTextRelative(0, AboveBar1, "\u00EA", Color.red, null, Text.PRESET|Text.CENTER, "Wingdings", 10, "Exit"+rawtime(0)); drawText("Suggested Long Exit at "+formatPriceNumber(vStopPrice),BottomRow1,Color.red,Text.LEFT,"Text Exit"+rawtime(0)); bIsLong = false; bEntryFound = false; } } if (bEntryFound && !bIsLong && nHigh >= vHighOfDay) { drawTextRelative(0,BelowBar1, "\u00E9", Color.green, null, Text.PRESET|Text.CENTER, "Wingdings", 10, "Long"+rawtime(0)); drawText("Suggested Long Entry at "+formatPriceNumber(vHighOfDay),TopRow1,Color.green,Text.LEFT,"Text"+rawtime(0)); bIsLong = true; vStopPrice = (nLow - TrlStop); vHighestHigh = nHigh; } if(!bIsLong && nATR >= nPrevHATR && nHigh > nSMA && nPrevSMA > nPrevHigh){ if (!isWR || isWR && IsWideCandle()) { vHighOfDay = nHigh + 0.5; bEntryFound = true; } } return nSMA;}function IsWideCandle(){ if (xWR.getValue(0) > xWR.getValue(-1)) return true; else return false;}function calcRange(){ return high() - low();}function verify(){ var b = false; if (getBuildNumber() < 779){ drawTextAbsolute(5, 35, "This study requires version 12.1 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;} |