Announcement

Collapse
No announcement yet.

2005 June: Something Darvas, Something New

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 2005 June: Something Darvas, Something New

    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:
    PHP 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.blue0);
        
    setDefaultBarFgColor(Color.blue1);
        
    setDefaultBarThickness(20);    
        
    setDefaultBarThickness(21);    
        
    setPlotType(PLOTTYPE_FLATLINES0);
        
    setPlotType(PLOTTYPE_FLATLINES1);
        
        
    // 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 ;  // 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(iLengthdLength) {
        if (
    bVersion == nullbVersion verify();
        if (
    bVersion == false) return;
        var 
    nState getBarState();
        
        if (
    nState == BARSTATE_NEWBAR) {
            
    CurIndex1 CurIndex;
            if (
    bBox == trueadjustIndex();
            
    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 high(-4);
                var 
    nTestHigh testHigh(iLengthdLength);
                if (
    high(-1) < && high(-2) < && high(-3) < && >= nTestHigh) {
                    
    dh h;
                    
    bSetdh true;
                    
    nIndex CurIndex 4;  // bar index of dh                
                
    }
            } 
            if (
    dl == null && dh != null) { // set dl
                
    for (var nIndexgetCurrentBarIndex()-3i++) {
                    var 
    index i-getCurrentBarIndex();
                    var 
    low(index);
                    if (
    low(index+1) > && low(index+2) > && low(index+3) > l) {
                        
    dl l;
                        
    0;
                    }
                }
                if (
    dl == null && bSetdh == falseadjustIndex();
            }
            if (
    dh != null && dl != null) {  // Darvas Box found
                
    if (bSetdh == false && (CurIndex CurIndex1) == 0adjustIndex();
                
    bBox true;
                
    removeGhostBox(gBoxNum);
                
    gBox false;
                
    nBoxCntr++;
                var 
    aBox = new Array(dhdl);
                var 
    getCurrentBarIndex()-1;
                var 
    = -1;
                while (
    >= nIndex) {  // plot box back to the dh bar index.
                    
    setBar(Bar.ValuejaBox);
                    
    j--;
                    
    i--;
                }
                
    // New D_Box range has formed.
                
    Alert.playSound("Blip.wav");
                
    drawLineRelative(j+1dhj+1dlPS_SOLID2Color.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(-1dh, -1dlPS_SOLID2Color.blue"right"+nBoxCntr);
                
    dh null;
                
    dl null;
                
    nIndex 0;
                
    nCntr 0;
            }
        }

        if (
    gBox == true && nState == BARSTATE_NEWBARdrawGhostBox();

        if (
    dh == null || dl == null) {
            return new Array(
    nullnull);
        } else {
            return new Array(
    dhdl);
        }
    }



    /***** 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(-1gBoxBase, -1gBoxBase+gBoxHeightPS_SOLID3Color.RGB(4518545), "gBoxLeft"+gBoxNum);
            
    drawLineRelative(-1+gBoxLengthgBoxBase, -1+gBoxLengthgBoxBase+gBoxHeightPS_SOLID3Color.RGB(4518545), "gBoxRight"+gBoxNum);
            
    drawLineRelative(-1gBoxBase+gBoxHeight, -1+gBoxLengthgBoxBase+gBoxHeightPS_SOLID3Color.RGB(4518545), "gBoxTop"+gBoxNum);
            
    drawLineRelative(-1gBoxBase, -1+gBoxLengthgBoxBasePS_SOLID3Color.RGB(4518545), "gBoxBottom"+gBoxNum);
            
    bDraw false;
        }
        
        return;
    }

    function 
    testHigh(id) {
        var 
    nH null;  
        var 
    aH;
        if (
    isDWM()) {
            
    nH high(0inv("M"));
            for (var 
    1dj++) {
                
    nH Math.max(nHhigh(-jinv("M")));
            }
        } else {
            
    nH high(-5);
            for (var 
    i-10j--) {
                
    nH Math.max(nHhigh(-j-5));
            }
        }    
        
        return 
    nH;
    }

    function 
    adjustIndex() {
        if (
    isComputeOnClose() && getCurrentBarIndex() == -1) {
            
    nIndex--;
        } else if (
    getCurrentBarIndex() == 0) {
            
    nIndex--;
        }
        return;
    }

    function 
    verify() {
        var 
    false;
        if (
    getBuildNumber() < 700) {
            
    drawTextRelative(6535"This study requires version 7.9 or later."
                
    Color.whiteColor.blueText.BOLD|Text.LEFT|Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM,
                
    null14"error");
            
    drawTextRelative(6520"Click HERE to upgrade.@URL=http://www.esignal.com/download/default.asp"
                
    Color.whiteColor.blueText.BOLD|Text.LEFT|Text.RELATIVETOLEFT|Text.RELATIVETOBOTTOM,
                
    null14"upgrade");
            return 
    b;
        } else {
            
    true;
        }
        
        return 
    b;

    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation
Working...
X