/***************************************Provided By : eSignal (c) Copyright 2005Description: Two-Bar PatternsVersion 1.0 5/10/2005Notes:July 2005 Issue - "Targeting Your Pattern" by Massimiliano Scorpio This study uses EFS2 functionality available in eSignalversion 7.9 or later.Formula Parameters: Defaults:Pattern Code 1 3311Pattern Code 1 Color redPattern Code 2 nonePattern Code 2 Color bluePattern Code 3 nonePattern Code 3 Color greenPattern Code 4 nonePattern Code 4 Color aquaPattern Code 5 nonePattern Code 5 Color magentaMax number of labels per code. 100Font Size 10***************************************/function preMain() { setPriceStudy(true); setStudyTitle("MS Two-Bar Patterns "); setShowTitleParameters(false); setCursorLabelName("msPattern Code", 0); setDefaultBarFgColor(Color.brown, 0); setComputeOnClose(); var fp1 = new FunctionParameter("nPatt1", FunctionParameter.NUMBER); fp1.setName("Pattern Code 1"); fp1.setLowerLimit(0); fp1.setDefault(3311); var fp2 = new FunctionParameter("cPatt1", FunctionParameter.COLOR); fp2.setName("Pattern Code 1 Color"); fp2.setDefault(Color.red); var fp3 = new FunctionParameter("nPatt2", FunctionParameter.NUMBER); fp3.setName("Pattern Code 2"); fp3.setLowerLimit(0); var fp4 = new FunctionParameter("cPatt2", FunctionParameter.COLOR); fp4.setName("Pattern Code 2 Color"); fp4.setDefault(Color.blue); var fp5 = new FunctionParameter("nPatt3", FunctionParameter.NUMBER); fp5.setName("Pattern Code 3"); fp5.setLowerLimit(0); var fp6 = new FunctionParameter("cPatt3", FunctionParameter.COLOR); fp6.setName("Pattern Code 3 Color"); fp6.setDefault(Color.green); var fp7 = new FunctionParameter("nPatt4", FunctionParameter.NUMBER); fp7.setName("Pattern Code 4"); fp7.setLowerLimit(0); var fp8 = new FunctionParameter("cPatt4", FunctionParameter.COLOR); fp8.setName("Pattern Code 4 Color"); fp8.setDefault(Color.aqua); var fp9 = new FunctionParameter("nPatt5", FunctionParameter.NUMBER); fp9.setName("Pattern Code 5"); fp9.setLowerLimit(0); var fp10 = new FunctionParameter("cPatt5", FunctionParameter.COLOR); fp10.setName("Pattern Code 5 Color"); fp10.setDefault(Color.magenta); var fpz1 = new FunctionParameter("nImageLimit", FunctionParameter.NUMBER); fpz1.setName("Max number of labels per code."); fpz1.setDefault(100); var fpz2 = new FunctionParameter("nFontSize", FunctionParameter.NUMBER); fpz2.setName("Font Size"); fpz2.setDefault(10);}var bVersion = null;var nCntr = 0; // image countervar aCodes = new Array(); // stores code for bars' with identified patternsvar bInit = true;var nP1 = null;var nP2 = null;var nP3 = null;var nP4 = null;var nP5 = null;function main(nPatt1, cPatt1, nPatt2, cPatt2, nPatt3, cPatt3, nPatt4, cPatt4, nPatt5, cPatt5, nImageLimit, nFontSize) { if (bVersion == null) bVersion = verify(); if (bVersion == false) return; var nState = getBarState(); var sCode = getPattern(); aCodes[getValue("rawtime")] = sCode; if (bInit == true) { if (nPatt1 > 0) nP1 = nPatt1; if (nPatt2 > 0) nP2 = nPatt2; if (nPatt3 > 0) nP3 = nPatt3; if (nPatt4 > 0) nP4 = nPatt4; if (nPatt5 > 0) nP5 = nPatt5; bInit = false; } if (nState == BARSTATE_NEWBAR) { if (nCntr > nImageLimit) nCntr = 0; else nCntr++; for (var i = 1; i <= 5; i++) { var patt = eval("nPatt" + i); if (!isNaN(patt) && patt != null) { drawTextRelative(1, 75 - (i*11), " Code " + i + ": " + patt + " @URL=EFS:edit", Color.white, eval("cPatt"+i), Text.BOLD|Text.LEFT|Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM, null, 10, "legend" + i); } } } // Identify selected pattern codes switch (eval(sCode)) { case (nPatt1): markPattern(1, cPatt1, nFontSize); break; case (nPatt2): markPattern(2, cPatt2, nFontSize); break; case (nPatt3): markPattern(3, cPatt3, nFontSize); break; case (nPatt4): markPattern(4, cPatt4, nFontSize); break; case (nPatt5): markPattern(5, cPatt5, nFontSize); break; } return sCode;}/***** Support Functions *****/function getPattern() { var s = "" + getZ(open(0)) + getZ(high(0)) + getZ(low(0)) + getZ(close(0)); return s;}function getZ(nPrice) { var zNum = 0; var nATR = atr(10); var h1 = high(-1); var l1 = low(-1); var nMidpoint1 = (h1 + l1) / 2; if (nPrice < l1 && nPrice >= (l1 - nATR) ) zNum = 1; // zone 1 else if (nPrice >= l1 && nPrice < nMidpoint1) zNum = 2; // zone 2 else if (nPrice >= nMidpoint1 && nPrice < h1) zNum = 3; // zone 3 else if (nPrice >= h1 && nPrice < (h1 + nATR) ) zNum = 4; // zone 4 else if (nPrice >= (h1 + nATR) ) zNum = 5; // zone 5 return zNum;}function markPattern(num, pattColor, fontSize) { drawTextRelative(0, AboveBar1, num+"@URL=EFS:onLButtonDblClk", Color.white, pattColor, Text.BOLD|Text.PRESET|Text.CENTER, null, eval(fontSize), "Patt" + num + nCntr); return;}function edit() { askForInput("MS Two-Bar Patterns "); return;}function onLButtonDblClk(barIndex, yValue) { if (barIndex == 1) return; var barRef = getValue("rawtime", barIndex); var patt = aCodes[barRef]; var pattCount = null; var pctTotal = null; var nEqual = 0; var nBelow = 0; var nAbove = 0; var pctEqual = 0; var pctBelow = 0; var pctAbove = 0; var nCount = 0; var nOldest = getOldestBarIndex(); var nTot = Math.abs( nOldest + Math.abs(barIndex)); var barRef = null; var nCode = null; for (var i = nOldest; i < barIndex; i++) { barRef = getValue("rawtime", i); nCode = aCodes[barRef]; if (nCode == patt) { nCount++; if (close(i+1) == open(i+1)) nEqual++; if (close(i+1) < open(i+1)) nBelow++; if (close(i+1) > open(i+1)) nAbove++; } } pattCount = nCount; pctTotal = ((nCount/nTot)*100).toFixed(2); if (nEqual > 0) pctEqual = ((nEqual/nCount)*100).toFixed(2); if (nBelow > 0) pctBelow = ((nBelow/nCount)*100).toFixed(2); if (nAbove > 0) pctAbove = ((nAbove/nCount)*100).toFixed(2); var b = false; if (nP1 != null && patt == nP1) b = true; if (nP2 != null && patt == nP2) b = true; if (nP3 != null && patt == nP3) b = true; if (nP4 != null && patt == nP4) b = true; if (nP5 != null && patt == nP5) b = true; if (b == false) return; var nATR = atr(10, barIndex); var h1 = high(barIndex-1); var l1 = low(barIndex-1); var nMidpoint1 = (h1 + l1) / 2; debugClear(); Alert.playSound("Pairing.wav"); debugPrintln("Close has been equal the open " + nEqual + " times " + pctEqual + "% on Total Pattern"); debugPrintln("Close has been below the open " + nBelow + " times " + pctBelow + "% on Total Pattern"); debugPrintln("Close has been above the open " + nAbove + " times " + pctAbove + "% on Total Pattern"); debugPrintln("In the next bar:"); debugPrintln("Total Number of Patterns " + patt + ": (w/out present bar) " + pattCount + " - " + pctTotal + "% on Total Bars."); debugPrintln(""); debugPrintln("Close: is " + getElementDesc(4, patt)); debugPrintln("Low: is " + getElementDesc(3, patt)); debugPrintln("High: is " + getElementDesc(2, patt)); debugPrintln("Open: is " + getElementDesc(1, patt)); debugPrintln(""); debugPrintln("Close: " + formatPriceNumber(close(barIndex))); debugPrintln("Low: " + formatPriceNumber(low(barIndex))); debugPrintln("High: " + formatPriceNumber(high(barIndex))); debugPrintln("Open: " + formatPriceNumber(open(barIndex))); debugPrintln(""); debugPrintln("Previous Low - 10 ATR: " + formatPriceNumber(l1 - nATR) ); debugPrintln("Previous Low: " + formatPriceNumber(l1) ); debugPrintln("Previous Midpoint: " + formatPriceNumber(nMidpoint1) ); debugPrintln("Previous High: " + formatPriceNumber(h1) ); debugPrintln("Previous High + 10 ATR: " + formatPriceNumber(h1 + nATR) ); debugPrintln(""); debugPrintln("Description:"); debugPrintln(""); debugPrintln("A Pattern coded as " + patt + " has been identified at bar " + barIndex + "!"); return;}function getElementDesc(nPos, pattcode) { var pattDesc0 = "below previous (Low - ATR 10)."; var pattDesc1 = "above (at) (previous Low - ATR 10) and below previous Low."; var pattDesc2 = "above (at) previous Low and below previous Midpoint."; var pattDesc3 = "above (at) previous Midpoint and below previous High."; var pattDesc4 = "above (at) previous High and below (High +ATR 10)."; var pattDesc5 = "above (at) previous High + ATR 10."; if (pattcode == null) return "N/A."; if (pattcode.length < 3) return "N/A."; var DescNum = pattcode.charAt(nPos-1); switch (DescNum) { case "0" : DescNum = "0"; break; case "1" : DescNum = "1"; break; case "2" : DescNum = "2"; break; case "3" : DescNum = "3"; break; case "4" : DescNum = "4"; break; case "5" : DescNum = "5"; break; } return eval("pattDesc"+DescNum);}function verify() { var b = false; if (getBuildNumber() < 700) { drawTextAbsolute(5, 35, "This study requires version 7.9 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;} |