This is read-only version of AFL library entry. Ability to add user formulas
and comment is only available from members-only area.
Details:
Formula name:
MS Darvas Box with Exploration
Author/Uploader:
TohMz - (email hidden)
Date/Time added:
2008-06-05 08:45:28
Origin:
http://trader.online.pl/MSZ/e-w-Darvis_Box.html
Keywords:
Darvas Box
Level:
basic
Flags:
system,exploration
DISCLAIMER: Most formulas present in AFL on-line library are submitted
by the users and are provided here on an "as is" and "as available" basis.
AmiBroker.com
makes no representations or warranties of any kind to the contents or the operation
of material presented here. We do not maintain nor provide technical support
for 3rd party formulas. Description:
Translate from http://trader.online.pl/MSZ/e-w-Darvis_Box.html
Buy: Today Buy Volume must be > N time of Buy MAV
AND The previous Day High must be below the
Darvas Top and Today must close above Darvas
Top
Sell: Today Sell Volume must be > N time of Sell MAV
AND The previous Day Low must be above the
Darvas bottom and Today must close below
Darvas Bottom
....etc
Formula:
/*
MS Darvas Box with Exploration
==============================
Translate from http://trader.online.pl/MSZ/e-w-Darvis_Box.html
- Improve scripting
* Allow Darvas Box Color/Style Changing
- Exploration
* Scan Price From .. To
*/
SetChartOptions( 0, chartShowArrows|chartShowDates );
_SECTION_BEGIN("Price Chart");
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C=
%g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C, SelectedValue(
ROC( C, 1 )) ));
PriceStyle = GetPriceStyle();
PriceStyleOpt = ParamStyle("Price Style")|PriceStyle;
if (PriceStyle==styleCandle)
Plot( C, "", colorBlack, PriceStyleOpt);
else
Plot( C, "", IIf( Close >= Ref(C, -1), colorBlue, colorRed ),
PriceStyleOpt);
_SECTION_END();
_SECTION_BEGIN("Darvas Box");
Periods= Param("Darvas Periods",5,5,260);
boxHigh = 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;
Topbox=ValueWhen(boxHigh, Ref(H,-3));
Botbox=ValueWhen(boxHigh,LLV(L,4));
/*=========================
- Allow color change
- Style change
==========================*/
Plot(TopBox, "Top", ParamColor("Box Top Color", colorRed), ParamStyle("Box
Top Style"));
Plot(Botbox, "Bot", ParamColor("Box Bottom Color",colorBlue), ParamStyle("Box
Bottom Style"));
_SECTION_END();
_SECTION_BEGIN("Exploration");
//== Price Increment Value - depend on different country
Inc = 0.1;
//== Set the Price Range for stock to scan
PriceFrom = Param("Price From:", 5, 0.1, 200, Inc);
PriceTo = Param("Price To:", 100, 0.1, 200, Inc);
/*
MAV - Moving Average of Volume
Buy - Default 20 days
Sell - default 10 days
Filter:
Buy: Today Buy Volume must be > N time of Buy MAV.
(Buy Up required Huge push force)
The previous Day High must be below the Darvas Top and Today must
close above Darvas Top
Sell: Today Sell Volume must be > N time of Sell MAV
(Sell Down required small pull force)
The previous Day Low must be above the Darvas bottom and Today must
close below Darvas Low
*/
Buy_MAPds = Param("Buy: MAV. Periods", 20, 1, 260);
Buy_VxMAV = Param("Buy: V > NxMAV", 2, 0, 20, 0.1);
Sell_MAPds = Param("Sell: MAV. Periods", 10, 1, 260);
Sell_VxMAV = Param("Sell: V > NxMAV", 1, 0, 20, 0.1);
BuyMAV = MA(V, Buy_MAPds);
SellMAV = MA(V, Sell_MAPds);
/* Rule to Filter
-
- The previous Day High must be inside the Darvas Top and Today must close
above Darvas Top
*/
Buy = Ref(H, -1) <=TopBox AND C>TopBox AND (V>Buy_VxMAV*BuyMAV);
Sell = Ref(L, -1) >=Botbox AND C<Botbox AND (V>Sell_VxMAV*SellMAV);
Filter = (Buy OR Sell) AND (C>=PriceFrom AND C<=PriceTo);
AddTextColumn(FullName(), "Security", 1.0, colorDefault, colorDefault, 200);
AddTextColumn(WriteIf(Buy, "Buy", WriteIf(Sell, "Sell", "-")), "Trade", 1.0,
colorYellow,
IIf(Buy, colorGreen, IIf(Sell, colorRed, colorDefault)),
50);
AddColumn(C, "Price", 0.3, colorDefault, colorDefault, 60);
AddColumn(V, "Volume", 1.0, colorDefault, colorDefault,80);
_SECTION_END();
Dear TohMZ,
Thank you fo the coding, visually it looks good. I have some questions for you:
1. When I compared to the 2 previously posted darvas codings, yours shows the different darvas box.
2. Scan and explore show different results
3. Some stocks that "broken out" on particular dates, were not on reports, eventhogh visually shown on your indicator.
Best regards,
TohMz
2008-06-07 11:40:33
1. Originally, My intention is to show you how to generate amibroker script from Metastock formula.
I did a comparison of the 3 Darvas Box, found that Darvas I and Darvas 3 quite close. But Darvas 2 differrent slightly. Based on the flexibility of Darvas 3, and found that it is also commonly used in the VT Trader Forex Platform. based on request that need Exploration I come out on this version.
2. The 3 MS Darvas Box was created by different person and different idea, therefore the result is expected to be different.
3. Because of the filter condition did not meet, no every stock is captured.
for example, the stock that break out you mentioned - It could be the following condition did not met:
1. Prev High not inside the TopBox Line
2. Today Close did not above TopBox Line
3. The Today Volume did not more that 2 time the MAV of 20 days.
You can modified the parameter setting or change or remove the filter criterias based on your market need and meet what you want.
The filter criteria was set in such a way is that we want to get rid of non liquid stock and
reduce the number of stocks displays. Otherwise just based on break out of topbox or bottombox, there will be too many to display.
This filter criteria is just one of the method. There are many method of scanning.
You can do the mininum, scan for upper and lower limit of to the Darvas line, scan with Moving Average for Bullish/Bearish trend....etc
However, I just wanted to created a scripting template for you. That all.
Lastly, I script for fun, I don't really fancy about Darvas box trading. This type of "Buy High Sell High" technique is good in certain market timing. The classic DarvasBox may be not suitable in today environment. See for yourself in the Darvas script in this forum.
There is a "turtle soup" theroy mentioned in the "Street Smarts" by Linda Bradford. She come out a technique different form the Break TopBox Line. Something like, break up bottomBox line and buy up. Very interesting book.
Dear TohMz,
Thank you 4 your explanation. I think your script is better than previuosly posted since the parameters are adjustable. In the current uncertain market situation, I think no indicators or system is perfectly match to our requirement. Darvas system is suitable in the uptrend market situation.
GBU, and best regards,
Darvas fans
2008-06-08 08:01:12
Yup Darvas suitable for Uptrend only but it's good if market bullish and don't try when bearish
TohMZ
2008-06-08 21:07:02
"Darvas suitable for Uptrend only but it's good if market bullish and don't try when bearish"
Not Really. If you think out of Darvas Box.
WIlliam Alligator System designed by Dr. Bill William in his book "Trading Choa..." is another variation form of Darvas Box.
The Fractal is the Darvas Top & Bottom, The Alligrator is the trend indicator - Long when Bullish, Short when Bearish, Don't trade when Neutral. With addition AO and AC indicators, adding more confidence. WiseMan Strategies help you to bottom/Top fishing. Read his book and grab the idea.
Loook into amibroker script "WIlliam Alligator System" and back test yourself. Compare the system with darvas box.
Maybe, i can do some modification to the "WIlliam Alligator System" script to make it more to the orgin idea.
Darvas Fans
2008-06-09 02:17:52
Hai TohMZ
Would you please share William Alligaitor AFL?
So we can learn it in detail.
Thank you
Darvas Fan
2008-06-09 02:51:50
/* The first set of lines are to set up the color coding for
the price bars */
outsidebar = outside();
insidebar = H <= Ref(H,-1) and L >= Ref(L,-1);
upbar = H > ref(H,-1) and L >= ref(L, -1);
downbar = L < ref(L,-1) and H <= ref(H,-1);
barcolor=iif(outsidebar, 1, iif(downbar, 4, iif(upbar,5, 6) ) );
/*The following builds the alligator lines*/
maxGraph=12;
AlligatorBlue=Ref(Wilders(A,13),-8);
Graph0=AlligatorBlue;
AlligatorRed=Ref(Wilders(A,8),-5);
Graph1=AlligatorRed;
AlligatorGreen=Ref(Wilders(A,5),-3);
Graph2=AlligatorGreen;
Graph0Style=Graph1Style=Graph2Style=1+4;
Graph3=C;
Graph3Style=64;
/*Red:* modified for Amibroker*/
/*
Graph3Color=22; 22 is the number for dark green
*/
Graph3barcolor=barcolor;
Graph2Color=27; /* 6 is green */
Graph1Color=5; /* 5 is red color */
Graph0color=7; /* 7 is dark blue */
/*The following builds Fractal Up*/
var1=ValueWhen(
(Ref(H,-2) > Ref(H, -4)) AND
(Ref(H,-2) > Ref(H, -3)) AND
(Ref(H,-2) > Ref(H, -1)) AND
(Ref(H,-2) > H), Ref(H,-2),1);
FractalUp=HighestSince(var1>0,var1,1);
Graph4=FractalUp;
Graph4Color=3; /* 6 is green */
Graph4Style=9;
/*The following builds Fractal Down*/
var2=
(Ref(L,-2) <= Ref(L, -1)) AND
(Ref(L,-2) <= Ref(L, 0)) AND
(Ref(L,-2) <= Ref(L, -3)) AND
(Ref(L,-2) <= Ref(L, -4));
FractalDown=ValueWhen( var2,Ref(L,-2),1);
Graph5=FractalDown;
Graph5Style=1;
Graph5Color=8; /* red is 5 blue is 7 */
Graph5Style=9;
/*
Graph6=ma(c,17);
graph7=ma(c,50);
graph8=ma(c,200);
graph6Style=Graph7Style=graph8Style=12;
*/
/* Below are the buy sell signals for testing */
buy = cross(H,FractalUp+0.065)
and (C > AlligatorRed) ;
Sell= A < AlligatorGreen
or (ref(C,-2) < FractalUp
and (ref(C,-1)<ref(C,-2) ) ) ;
/* The following is Guru commentary coding */
/* Guru Commentary */
WriteIF(Hold(Buy==1,10),
"Buy signal bars ago " + WriteIF(Hold(Buy==1,10),
WriteVal(BarsSince(Buy==1)),""),
"No Buy Signal") + "n" +
WriteIF(Hold(Sell==1,10),
"Sell signal bars ago " + WriteIF(Hold(Sell==1,10),
WriteVal(BarsSince(Sell==1)),""),
"No Sell Signal") ;
/* End of commentary code */
/* The following lines of code set up a sell on the last day if in an open
position*/
barnumber = cum( 1 );
lastbar = barnumber == lastvalue( barnumber );
sell = SELL or LASTBAR;
filter = cross(H,FractalUp+0.065) or Cross(L,FractalDown-0.065) ;
/* removes redundant buy and sell signals */
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
first=1;
/* First is the number of days for each ROC interval for reviewing performance
*/
/* To use this filter always make the current day at least 3*first days before
the current date
for meaningful results */
/*
numcolumns = 7;
column0 = C;
column0format = 1.2;
column0name = "Close";
column1 = ref(C, 1+first);
column1name = "Close+i ";
column1format = 1.2;
column2 = ref(C,1+first*2);
column2name = "Close+i*2 ";
column2format = 1.2;
column3 = ref(C,1+first*3);
column3name = "Close+i*3 ";
column3format = 1.2;
column4= ref(C,first*1+1) - C;
column4name="ROC+i";
column4format = 1.2;
column5= ref(C,first*2+1) - C;
column5name="ROC+2i";
column5format = 1.2;
column6= ref(C,first*3+1) - C;
column6name="ROC+3i";
column6format = 1.2;
*/
/* End of Exploration Code. */
Dear TohMz,
Yeah I have noticed that upper and lower lines of alligator system is similar to your darvas upper and lower box. When I compare to peviously posted darvas coding, your coding gives faster breakout signals (I set darvas period at 5). That is better.
Best ragards,
Hi buddy
2008-06-09 20:38:18
Don't mentioned it. The credit should not go to me. I just convey their design into a better presention to you.
However, think out of Darvas box, the upper and lower lines still can further modified.
Why must fixed at 5 bars? Why not 2/3/4 bars. Why must all the bars lower than the Pivot Bars ?
Why cannot be same high as pivot bars ?
If you deviate these from Darvas Box, you can see a lot of trading opportunities like consolidation, small pauses or maybe pattern...etc breakouts. Use alligator MA or other MAs to serve as trend guideline to the correct side of the market. Combine with other indicators to add better consideration.
However, I am done with these darvas box modification. No further modification will be done by me.