# Classic Darvas Box Formulas For Metastock

##### Super Moderator
CLASSIC DARVAS BOX FORMULAS FOR METASTOCK

The first formula is "Darvas High" which identifies new period highs followed by three lower highs.

Name of Indicator: Darvas High

Formula:

Periods:=100; { this is the only place the number of periods is set}

If((Ref(H,-3) >= Ref(HHV(H,Periods),-4))

AND Ref(H,-3) > Ref(H,-2)

AND Ref(H,-3) > Ref(H,-1)

AND Ref(H,-3) > H,

Ref(H,-3), PREVIOUS );

Name of Indicator: New Darvas High

Formula:

dh:= Fml("Darvas High");

def:=IsDefined(dh) AND IsDefined(Ref(dh,-2));

(def AND Ref(def,-1)=0) + (dh AND Ref(dh,-1)<>dh);

Name of Indicator: New Darvas Low

Formula:

dh:= Fml("Darvas High");

ndl:=(Ref(L,-3) < Ref(L,-2) AND Ref(L,-3) < Ref(L,-1)

AND Ref(L,-3) < L AND Ref(H,-2) < dh

AND Ref(H,-1) < dh AND H < dh);

def:=IsDefined(dh) AND IsDefined(Ref(dh,-1));

(def AND Ref(def,-1)=0)+ (ndl AND (Ref(ndl,-1) < 1))

Name of Indicator: Darvas Low

Formula:

If( Fml("New Darvas Low") , Ref(L,-3), PREVIOUS);

Name of Indicator: Darvas Box End

Formula:

def:=IsDefined(end) AND IsUndefined(Ref(end,-1));

(def AND Ref(def,-1)=0)+ (end AND Fml("New Darvas Low"))

We are now in a position to plot the High and Low of the Darvas box.

Name of Indicator: Darvas Box High

Formula:

dbe:=Fml("Darvas Box End");

dbhi:=If(dbe AND IsDefined(Ref(dbe,-1)), Fml("Darvas High"), PREVIOUS);

If(dbhi=0,H+0.0000001,dbhi)

Name of Indicator: Darvas Box Low

Formula:

dbe:=Fml("Darvas Box End");

bl:=If(dbe AND IsDefined(Ref(dbe,-1)), Fml("Darvas Low"), PREVIOUS);

If(bl=0,L-0.0000001,bl)

Next we need to develop the Sell Indicator. First we look for possible sell signals.

Name of Indicator: Darvas Poss Sell

Formula:

dsl:=L < Fml("Darvas Box Low");

def:=IsDefined(dsl) AND IsDefined(Ref(dsl,-1));

(def AND Ref(def,-1)=0)+(dsl AND (Ref(dsl,-1)<dsl))

Name of Indicator: Darvas Sell

Formula:

def:=IsDefined(sell) AND IsDefined(Ref(sell,-1));

((def AND Ref(def,-1)=0) + (sell = 0 AND Ref(sell,-1)=1))

Formula:

dc:= Fml("darvas sell");

{ change the following line to H>Fml("Darvas Box Hi") .. for Classic Darvas}

db:= C>Fml("Darvas Box Hi") AND

dto:=If(db AND PREVIOUS=0,1,If(dc,0,PREVIOUS));

dto AND (Ref(dto,-1) =0)

Using these formulas it is simple to create a new Metastock Expert Advisor for Darvas. Create a New advisor, call it Darvas and fill in the following tabs

For the Trends tab I used the somewhat arbitrary

Bullish C >= Fml("Darvas Box Low");

Bearish C < Fml("Darvas Box Low");

For Symbols tab use

Sell: down arrow graphic, formula Fml("Darvas Sell")

Sell: formula Fml("Darvas Sell") and some suitable text message such as "sell on next open"

#### jalanp

##### New Member
The super moderator should have posted a screen shot alongwith this metastock code, because nothing is basically clear from it, except that you create 7/8 indicators and create an expert.The super moderator should have tried to find out if it works or not. As far as I know it will not give the desired result. Ask Guppy.

#### Blaiserboy

##### Member
Probably he was just trying to help people get started. and as you know, very little in life is an exact precise science, rather we start into something and then have to learn and refine a lot......

Perhaps you would be able to post what you know to be the correct parameters and thereby save people some work.......

#### SGM

##### Active Member
CLASSIC DARVAS BOX FORMULAS FOR METASTOCK

Darvas Box Code for AmiBroker

_SECTION_BEGIN("Darvas Box");

box1=0;
box2=0;
SetBarsRequired(10000,10000);
procedure fillDarvas(start,end,swap,top, bottom )
{
for ( j = start; j < end; j++)
{
if( box1[j] == swap)
box1[j]= top ;
else
box1[j]= bottom;

if(box2[j] == swap)
box2[j]= bottom ;
else
box2[j]= top;
}
}

BoxArr1 = 0;
BoxArr2 = 0;
StateArray = 0;
DSell = 0;
TopArray = 0;
BotArray = 0;
tick=0;

BoxTop = High[0];
BoxBot = Low[0];
swap=0;
state = 0;
BoxStart = 0;

for (i=0; i<BarCount; i++)
{
if (state==5)
{
TopArray=BoxTop;
BotArray=BoxBot;
if (Low<(BoxBot*(1-tick/100)) || High>(BoxTop*(1+tick/100)))
{
fillDarvas(BoxStart,i,swap,BoxTop,BoxBot);

state = 1;
swap = !swap;
BoxTop = High;
BoxStart = i;
}
}
else
{
if (High<BoxTop)
{
if ((state<3) || (Low>BoxBot))
{
state++;
}
else
{
state=3;
}
if (state==3)
BoxBot=Low;
}
else
{
state=1;
BoxTop=High;
}
}
StateArray = state;
}

fillDarvas(BoxStart,BarCount,swap,BoxTop,BoxBot);

Plot( box1, "" , 1 + statearray, styleThick);
Plot( box2, "" , 1 + statearray , styleThick);
_SECTION_END();

The above code will plot the 2 sides (High /Low) of the Box on the chart. The idea is to trade the breakout on either side.

Regards
Sanjay

##### Super Moderator
The super moderator should have posted a screen shot alongwith this metastock code, because nothing is basically clear from it, except that you create 7/8 indicators and create an expert.The super moderator should have tried to find out if it works or not. As far as I know it will not give the desired result. Ask Guppy.

I have tried out all the indicators before posting them here. They all work.

For those of you who may be interested in reading his book check out http://www.nicolasdarvas.org/

#### rpc

##### Active Member
hi sanjay
I tried your darvas box afl.It shows horizontal lines only not boxes . Is it ok ?
rpc

#### jalanp

##### New Member
Sethi Darvas is a proprietory darvas formula. Here the boxes are clear cut. Sanjay's Afl for amibroker is also good. If anyone has plotted the Darvas in Metastock using the code given in this forum earlier, pl submit.
The png file is sethi darvas and jpg file is from amibroker.
jalanp

#### Attachments

• 47.4 KB Views: 1,099
• 24.8 KB Views: 1,083

#### rpc

##### Active Member
hi jalanp
Thanks for the clarification .I am still unable to get the box.Not that it matters because I think what matters is the horizontal lines and not the vertical ones.
rpc