DarvasBox.efs
EFSLibrary - Discussion Board
File Name: DarvasBox.efs
Description:
Thus study is based on the June 2005 article, Something Darvas Something New, by Daryl Guppy.
Formula Parameters:
- High periods (Bars): Intraday (Default 4)
- High periods (Months): DWM (Default 6)
Notes:
The study has options to configure the number of bars required to define the Darvas Box via the Edit Studies option (Chart Options-->Edit Studies). The study is configured for daily or intraday intervals. For daily charts, the formula only uses the second parameter ( "High Periods(Months): DWM" )and is based on monthly highs. The default is set to look for a 6 month high. The chart example provided is using a 1-month high. For intraday charts, the formula uses the first parameter, which is based on the specified number of bars for the chart's interval. On intraday charts the study will also give audible alerts when a bar closes above or below a Darvas Box or below a Ghost Box. The Darvas and Ghost boxes appear in blue and green, respectively. The related article is copyrighted material. If you are not a subscriber of Stocks & Commodities, please visit www.traders.com.
Download File:
DarvasBox.efs
EFS Code:
/*************************************** Provided By : eSignal (c) Copyright 2005 Description: Darvas Box Version 1.0 4/12/2005 Notes: June 2005 Issue - "Something Darvas, Something New" by Daryl Guppy This study uses EFS2 functionality available in eSignal version 7.9 or later. Formula Parameters: Defaults: High periods (Bars): Intraday 4 High periods (Months): DWM 6 ***************************************/ function preMain() { setPriceStudy(true); setStudyTitle("Darvas Box "); setShowTitleParameters(false); setCursorLabelName("Darvas High", 0); setCursorLabelName("Darvas Low", 1); setDefaultBarFgColor(Color.blue, 0); setDefaultBarFgColor(Color.blue, 1); setDefaultBarThickness(2, 0); setDefaultBarThickness(2, 1); setPlotType(PLOTTYPE_FLATLINES, 0); setPlotType(PLOTTYPE_FLATLINES, 1); // Number of bars to define Darvas Box High on intraday intervals. var fp1 = new FunctionParameter("iLength", FunctionParameter.NUMBER); fp1.setName("High periods (Bars): Intraday"); fp1.setLowerLimit(1); fp1.setDefault(4); // Number of Monthly bars to define a Darvas Box High on D,W,M intervals. var fp2 = new FunctionParameter("dLength", FunctionParameter.NUMBER); fp2.setName("High periods (Months): DWM"); fp2.setLowerLimit(1); fp2.setDefault(6); } var bVersion = null; var dh = null; // Darvas High var dl = null; // Darvas Low var bBox = false; // Darvas Box exists var gBox = false; // Ghost Box var gBoxHeight = 0; // Ghost Box Height var gBoxLength = 0; // Ghost Box Length var gBoxCntr = 0; // Current Ghost Box Length var gBoxNum = 0; // Ghost Box number. var gBoxBase = 0 ; // Base start value for bottom of Ghost Box. var bDraw = false; // Allow new Ghost Box to be drawn. var CurIndex = null;// Current Bar Index; var CurIndex1 = null; var nCntr = 0; // Number of bars to start a box var nBoxCntr = 0; var nIndex = 0; // Bar index of start of last box function main(iLength, dLength) { if (bVersion == null) bVersion = verify(); if (bVersion == false) return; var nState = getBarState(); if (nState == BARSTATE_NEWBAR) { CurIndex1 = CurIndex; if (bBox == true) adjustIndex(); nCntr++; } CurIndex = getCurrentBarIndex(); if (CurIndex1 == null) return; // New Darvas Box if (bBox == false && nState == BARSTATE_NEWBAR && nCntr >= 4) { var bSetdh = false; if (dh == null || high(0) > dh) { // set dh var h = high(-4); var nTestHigh = testHigh(iLength, dLength); if (high(-1) < h && high(-2) < h && high(-3) < h && h >= nTestHigh) { dh = h; bSetdh = true; nIndex = CurIndex - 4; // bar index of dh } } if (dl == null && dh != null) { // set dl for (var i = nIndex; i < getCurrentBarIndex()-3; i++) { var index = i-getCurrentBarIndex(); var l = low(index); if (low(index+1) > l && low(index+2) > l && low(index+3) > l) { dl = l; i = 0; } } if (dl == null && bSetdh == false) adjustIndex(); } if (dh != null && dl != null) { // Darvas Box found if (bSetdh == false && (CurIndex - CurIndex1) == 0) adjustIndex(); bBox = true; removeGhostBox(gBoxNum); gBox = false; nBoxCntr++; var aBox = new Array(dh, dl); var i = getCurrentBarIndex()-1; var j = -1; while (i >= nIndex) { // plot box back to the dh bar index. setBar(Bar.Value, j, aBox); j--; i--; } // New D_Box range has formed. Alert.playSound("Blip.wav"); drawLineRelative(j+1, dh, j+1, dl, PS_SOLID, 2, Color.blue, "left"+nBoxCntr); } } // Check for breach of Darvas Box if (nState == BARSTATE_NEWBAR && bBox == true) { if (close(-1) > dh) { // Entry Trigger: Bar closed above top of D_Box Alert.playSound("beam1.wav"); gBox = true; // Draw Ghost Box gBoxHeight = dh - dl; gBoxLength = (CurIndex -nIndex) -1; gBoxBase = dh; gBoxNum++; gBoxCntr = 0; bDraw = true; drawGhostBox(); } else if (close(-1) < dl) { // Exit Trigger: Bar closed below D_Box Alert.playSound("buzz.wav"); } if (close(-1) > dh || close(-1) < dl) { // reset globals to find next box. bBox = false; drawLineRelative(-1, dh, -1, dl, PS_SOLID, 2, Color.blue, "right"+nBoxCntr); dh = null; dl = null; nIndex = 0; nCntr = 0; } } if (gBox == true && nState == BARSTATE_NEWBAR) drawGhostBox(); if (dh == null || dl == null) { return new Array(null, null); } else { return new Array(dh, dl); } } /***** Support Functions *****/ function removeGhostBox(num) { //if (gBox == true) { removeLine("gBoxLeft"+num); removeLine("gBoxRight"+num); removeLine("gBoxTop"+num); removeLine("gBoxBottom"+num); //} return; } function drawGhostBox() { if (close(-1) < gBoxBase) { // Exit Trigger: Bar closed below G_Box Alert.playSound("buzz.wav"); gBox = false; return; } if (gBoxCntr > gBoxLength) { gBoxBase += gBoxHeight; gBoxCntr = 0; gBoxNum++; bDraw = true; } gBoxCntr++; if (bDraw == true) { drawLineRelative(-1, gBoxBase, -1, gBoxBase+gBoxHeight, PS_SOLID, 3, Color.RGB(45, 185, 45), "gBoxLeft"+gBoxNum); drawLineRelative(-1+gBoxLength, gBoxBase, -1+gBoxLength, gBoxBase+gBoxHeight, PS_SOLID, 3, Color.RGB(45, 185, 45), "gBoxRight"+gBoxNum); drawLineRelative(-1, gBoxBase+gBoxHeight, -1+gBoxLength, gBoxBase+gBoxHeight, PS_SOLID, 3, Color.RGB(45, 185, 45), "gBoxTop"+gBoxNum); drawLineRelative(-1, gBoxBase, -1+gBoxLength, gBoxBase, PS_SOLID, 3, Color.RGB(45, 185, 45), "gBoxBottom"+gBoxNum); bDraw = false; } return; } function testHigh(i, d) { var nH = null; var aH; if (isDWM()) { nH = high(0, inv("M")); for (var j = 1; j < d; j++) { nH = Math.max(nH, high(-j, inv("M"))); } } else { nH = high(-5); for (var j = i-1; j > 0; j--) { nH = Math.max(nH, high(-j-5)); } } return nH; } function adjustIndex() { if (isComputeOnClose() && getCurrentBarIndex() == -1) { nIndex--; } else if (getCurrentBarIndex() == 0) { nIndex--; } return; } 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; }