Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in...

23
Bonus Darvas Charting Formula

Transcript of Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in...

Page 1: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

Bonus Darvas Charting Formula

Page 2: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

METASTOCK: DARVAS TECHNIQUE Please refer to Daryl Guppy’s article found on the download page of www.nicolasdarvastrading.com

Page 3: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

TRADESTATION: DARVAS TECHNIQUE To demonstrate how these methods might be implemented in an EasyLanguage strategy, we have written a strategy called “Darvas by Guppy.” To begin, create a daily chart of the symbol of your choice. Then, insert the “Darvas by Guppy” strategy into the chart. To apply the classic style, set the periods input to 200. Ensure that the inputs ExitNextDay, GhostBoxExit, and BreakOutEntry are set to false for this style. The input VolumeEntry should be set to true. To apply the modern Darvas style, a period length of either 100 or 200 may be used. ExitNextDay and GhostBoxExit should both be set to true for this style. VolumeEntry should be false. Finally, to apply the breakout Darvas style, set BreakoutEntry, ExitNextDay, and GhostBoxExit to true. VolumeEntry should be set to false. This code may be downloaded from the TradeStation Support Center, which is accessible from TradeStation.com.

Strategy: Darvas by Guppy inputs:

Periods( 100 ), ExitNextDay( false ), GhostBoxExit( false ), BreakoutEntry (false ), VolumeEntry( false ), VolumeAvgLen( 10 ), VolumeFactor( 1.5 ) ;

variables: BarsSinceDH( 0 ), BarsSinceDL( 0 ), CriticalLow( 0 ), TempD_Low( 0 ), SearchForLow ( false ), D_Low( 0 ), D_High( 0 ),

BottomLineNum( 0 ), TopLineNum( 0 ), LeftSideNum( 0 ), RightSideNum( 0 ), CriticalHigh( 0 ), TempD_High( 0 ), DHighLowDiff( 0 ), MyStop( 0 ), MyTrigger( 0 ), DownTrend( 0 ) ;

if CurrentBar > Periods then begin BarsSinceDH = BarsSinceDH + 1 ; BarsSinceDL = BarsSinceDL + 1 ; if Low[3] <= CriticalLow[4] and

Low[3] <= Low[2] and Low[3] <= Low[1] and Low[3] < Low

then begin

TempD_Low = Low[3] ; BarsSinceDL = 3 ; end ;

Page 4: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

FIGURE 1: TRADESTATION, DARVAS TECHNIQUE. Here is an example of drawing Darvas boxes in TradeStation.

if SearchForLow and BarsSinceDL < 6 and BarsSinceDL <= BarsSinceDH then

begin D_Low = Low[BarsSinceDL] ; D_High = TempD_High ; SearchForLow = false ; BottomLineNum = TL_New( Date[BarsSinceDH], Time[BarsSinceDH], D_Low, Date[3], Time[3], D_Low ) ; TopLineNum = TL_New( Date[BarsSinceDH], Time[BarsSinceDH], D_High, Date[3], Time[3], D_High ) ;

Page 5: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

LeftSideNum = TL_New( Date[BarsSinceDH], Time[BarsSinceDH], D_High, Date[BarsSinceDH], Time[BarsSinceDH], D_Low ) ; RightSideNum = TL_New( Date[3], Time[3], D_High, Date[3], Time[3], D_Low ) ; end ;

if High[3] >= CriticalHigh[4] and High[3] >= High[2] and High[3] >= High[1] and High[3] > High

then begin BarsSinceDH = 3 ; TempD_High = High[3] ; SearchForLow = true ; end ;

CriticalHigh = Highest( High, Periods ) ; CriticalLow = Lowest( Low, BarsSinceDH ) ; end ;

DHighLowDiff = D_High - D_Low ; if GhostBoxExit and DHighLowDiff > 0 and Close > D_High + DHighLowDiff then

begin MyStop = ( IntPortion( ( Close - D_Low ) / DHighLowdiff ) - 1 ) * DHighLowDiff + D_Low ; MyTrigger = MyStop + DHighLowDiff ; end

else begin MyStop = D_Low ; MyTrigger = D_High ; end ;

if Close crosses under D_Low then DownTrend = 0

else if BreakoutEntry and Close crosses over D_High then DownTrend = 1

else if BreakoutEntry and DownTrend = 1 and BarsSinceDL = 3 then

DownTrend = 2 ; if ( BreakoutEntry and DownTrend = 2 ) or

BreakoutEntry = false then begin if VolumeEntry then

begin if Close crosses over MyTrigger and Volume > Average( Volume, VolumeAvgLen ) * VolumeFactor

then

Buy next bar market ; end

else if Close < MyTrigger then Buy next bar MyTrigger stop ;

Page 6: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

—Mark Mills TradeStation Securities, Inc. A subsidiary of TradeStation Group, Inc. www.TradeStationWorld.com

if ExitNextDay then begin if Low[1] >= MyStop and Low < MyStop then Sell next bar at market ; End else Sell next bar at MyStop stop ; end ;

Page 7: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

WEALTH-LAB: MODIFIED DARVAS TECHNIQUE Visit www.wealth-lab.com to try out this ChartScript adaptation of the modern Darvas method by searching the public ChartScript titles for “Guppy.” Select the script and then enter a symbol of your choice. As always, the WealthScript translation is available to Wealth-Lab Pro and Developer users via the Community|Download ChartScripts action. After spot-checking selected symbols, it appeared that the method provided a better return by acting on all 100-day breakout signals as opposed to waiting for a Darvas box and then entering after an ensuing breakout. Our ChartScript reflects this modification of the trading rules, where, in a portfolio Simulation of the current Nasdaq 100 stocks over the most recent six-year period, the Darvas script squeezed out a 4% APR gain with a $100,000 account after $8 per trade commissions using 5% of equity sizing. (A 1% max-risk sizing produced similar results.) Unfortunately, the simulated account suffered a 66% drawdown after achieving a whopping 120% gain in the period between April 1999 to April 2000.

WealthScript code: {$I ‘HighestBar2’} {$I ‘LowestBar2’} type GhostBox = record Bar, BoxNum: integer; HighClose, Stop, Base: float; end; const D_BARS = 4; var G: GhostBox; var DBm1: integer = D_BARS - 1; var Last_Bar: integer = BarCount - 1; var Bar, LastDHBar, LastDLBar, DHSer, DLSer, HCSer, BoxColor, BoxEndBar: integer; var DHCnfd, DLCnfd, DarvasValid: boolean; var C, BoxHeight: float; { * Ghost boxes processed only if position active * } procedure ManageGhostStop( Bar: integer );

Page 8: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

begin var p: integer = LastPosition; var n: integer = G.BoxNum; G.HighClose := Max( G.HighClose, PriceClose( Bar ) ); repeat var H: float = G.Base + BoxHeight * n; if G.HighClose > H then

begin DrawRectangle( G.Bar, H - BoxHeight, Bar, H, 0, #BlueBkg,

#Thin, #BlueBkg, true ); G.Bar := Bar; Inc( n );

end else break; until n > 25; G.Stop := G.Base + BoxHeight * ( n - 2 ); G.BoxNum := n; DrawCircle( 5, 0, Bar, G.Stop, #Fuchsia, #Thin ); if PriceClose( Bar ) < G.Stop then SellAtMarket( Bar + 1, p, ‘Ghost Stop’ ); end;

DHSer := CreateSeries; // Confirmed high series DLSer := CreateSeries; // Confirmed low series HCSer := HighestSeries( #Close, 100 );

for Bar := 100 to BarCount - 1 do begin C := PriceClose( Bar );

if not DHCnfd then begin if Bar >= BoxEndBar + 3 then

DHCnfd := Bar - HighestBar2( Bar, #High, D_BARS, 4 ) >= DBm1; if DHCnfd then LastDHBar := Bar - DBm1; end else DHCnfd := C <= PriceHigh( LastDHBar ); // Buy trigger

if DHCnfd then { if D_Box high confirmed, check for the low } if not DLCnfd then begin

DLCnfd := Bar - LowestBar2( Bar, #Low, D_BARS, 4 ) >= DBm1; if DLCnfd then

begin LastDLBar := Bar - DBm1;

Page 9: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

BoxHeight := PriceHigh( LastDHBar ) - PriceLow( LastDLBar ); DarvasValid := true; G.Bar := -1; end;

end else

DLCnfd := C >= PriceLow( LastDLBar ); // Sell trigger

{ Store values in series for graphing } @DHSer[Bar] := PriceHigh( LastDHBar ); @DLSer[Bar] := PriceLow( LastDLBar );

{ Trading rules and drawing } if DarvasValid then begin DarvasValid := DHCnfd and DLCnfd;

if not DarvasValid or ( Bar = Last_Bar ) then begin if not DHCnfd then begin BoxColor := #GreenBkg; if not LastPositionActive then begin

SetRiskStopLevel( @DLSer[Bar] ); if C > @HCSer[Bar-1] then BuyAtMarket( Bar + 1, ‘’ ); end else // initialize ghost box begin G.Bar := Bar - 1; G.BoxNum := 1; G.HighClose := C; G.Stop := @DHSer[Bar]; G.Base := G.Stop; end;

end else // DLCnfd is false

Page 10: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

—Robert Sucher www.wealth-lab.com

begin BoxColor := #RedBkg; if LastPositionActive then SellAtMarket( Bar + 1, LastPosition, ‘D_Box Stop’ ); end; { Draw D_Box at last bar or when ‘breached’ } if Bar = Last_Bar then DrawRectangle( LastDHBar, PriceHigh( LastDHBar ),

Last_Bar, PriceLow( LastDLBar ), 0, #GreenBkg, #Thin, #GreenBkg, true )

else DrawRectangle( LastDHBar, PriceHigh( LastDHBar ), Bar - 1,

PriceLow( LastDLBar ), 0, #Green, #Thin, BoxColor, true );

BoxEndBar := Bar; DHCnfd := false; // reset DLCnfd := false;

end; end else if ( G.Bar > -1 ) and LastPositionActive then

ManageGhostStop( Bar ) else if not LastPositionActive and ( C > @HCSer[Bar-1] ) then BuyAtMarket( Bar + 1, ‘100-bar breakout’ ); end; PlotSeriesLabel( DHSer, 0, #Blue, #Thin, ‘Darvas Highs’ ); PlotSeriesLabel( DLSer, 0, #Red, #Thin, ‘Darvas Lows’ ); PlotSeriesLabel( HCSer, 0, #Black, #Dotted, ‘Highest(#Close, 100)’ ); HideVolume;

Page 11: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

AMIBROKER: MODIFIED DARVAS TECHNIQUE Implementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker are presented in Listing 1.

LISTING 1 Periods = 100; function DarvasHigh( Periods ) { HHVtemp = HHV( High, Periods ); result = HHVTemp; for( i = Periods + 4; i < BarCount; i++ ) { result[ i ] = IIf( H[ i - 3 ] >= HHVTemp[ i - 4 ] AND

H[ i - 3 ] > H[ i - 2 ] AND H[ i - 3 ] > H[ i - 1 ] AND H[ i - 3 ] > H[ i ], H[ i - 3 ], result[ i - 1 ] );

} return result; } function NewDarvasHigh( Periods ) { dh = DarvasHigh( Periods ); return dh AND Nz( dh ) != Ref( Nz( dh ), -1 ); } function NewDarvasLow( Periods ) { dh = DarvasHigh( Periods ); 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; return Nz( ndl ) AND Ref( Nz( ndl ), -1 ) < 1; } function DarvasLow( Periods ) { return ValueWhen( NewDarvasLow( Periods ), Ref( L, -3 ) ); }

Page 12: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

—Tomasz Janeczko, AmiBroker.com www.amibroker.com

function DarvasBoxEnd( Periods ) { end = BarsSince( NewDarvasHigh( Periods ) ) < BarsSince( Ref( NewDarvasLow( Periods ), -1 ) ); return Nz( end ) AND NewDarvasLow( Periods ); } function DarvasBoxHigh( Periods ) { dbe = DarvasBoxEnd( Periods ); dbhi = ValueWhen( Nz( dbe ) AND NOT IsNull( Ref( dbe, -1 ), DarvasHigh( Periods ) ); return IIf( Nz( dbhi ) == 0, H + 1e-6, dbhi ); } function DarvasBoxLow( Periods ) { dbe = DarvasBoxEnd( Periods ); dblo = ValueWhen( Nz( dbe ) AND NOT IsNull( Ref( dbe, -1 ), DarvasLow( Periods ) ); return IIf( Nz( dblo ) == 0, L - 1e-6, dblo ); } function DarvasPossSell( Periods ) {

Page 13: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

eSIGNAL: MODIFIED DARVAS TECHNIQUE We’ve provided the indicator code “DarvasBox.efs,” which is available from the eSignal. 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 six-month high. The chart example provided is using a onemonth high. For intraday harts, 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. To discuss this study or download a complete copy of the formula, please visit the EFS Library Discussion Board forum under the Bulletin Boards link at www.esignalcentral.com. —Jason Keck eSignal, a division of Interactive Data Corp. 800 815-8256, www.esignalcentral.com

FIGURE 3: eSIGNAL, MODIFIED DARVAS TECHNIQUE. This sample chart uses a one-month high. The Darvas and ghost boxes appear in blue and green, respectively.

Page 14: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

NEUROSHELL TRADER: MODIFIED DARVAS TECHNIQUE To implement the Darvas formulas, select “New Indicator…” from the Insert menu and use the Indicator Wizard to create the following indicators:

DHCOND: AND2(A>=B(Lag(High,3), Lag(HighPrice(High,PERIODS),4), A>B(Lag(High,3), HighPrice(High,3)) DARVAS HIGH: SelectiveMovAvg(Lag(High,3), DHCOND, 1) DLPOSS: AND2(A<B(Lag(Low,3), LowPrice(Low,3)), A<B(HighPrice(High,3), DARVASHIGH)) DLCOND*: AND2( DLPOSS, BarsSince(DHCOND) < Lag(BarsSince(DLPOSS) ) DARVAS LOW: SelectiveAvg( Lag(Low,3), DLCOND ) DARVAS BOX ACTIVE*: A<B( BarsSince(DLCOND), BarsSince(CrossBelow(Low, DARVASLOW)) DARVAS BOX HIGH: If (DARVASBOXACTIVE, SelectiveAvg(DARVASHIGH, DLCOND,1), *) DARVAS BOX LOW: If (DARVASBOXACTIVE, DARVASLOW, *)

*Note: the BarsSince(COND) indicator is created as follows: Subtract(CumulativeSum(Add2(1,0),0), SelectiveAvg(CumulativeSum(Add2(1,0),0), COND, 1) ) To create a Darvas trading system, select “New Trading Strategy …” from the Insert menu and enter the following entry and exit conditions in the appropriate locations of the Trading Strategy Wizard:

Generate a buy long MARKET order if ALL of the following are true: CrossAbove ( DARVIS BOX HIGH ) Generate a Trailing Stop Order at the following price level: DARVIS BOX LOW

Page 15: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

If you have NeuroShell Trader Professional, you can also choose whether the Darvas periods should be optimized. After backtesting the trading strategy, use the “Detailed Analysis …” button to view the backtest and trade-by-trade statistics for this Darvas trading system. —Marge Sherald, Ward Systems Group, Inc. 301 662-7950, [email protected] www.neuroshell.com

FIGURE 4: NEUROSHELL, MODIFIED DARVAS TECHNIQUE. Here is a sample Neuroshell chart applying the Darvas trading system.

Page 16: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

NEOTICKER: MODIFIED DARVAS TECHNIQUE The code is listed the following order: Darvas High (Listing 1), New Darvas High (Listing 2), New Darvas Low (Listing 3), Darvas Low (Listing 4), Darvas Box End (Listing 5), Darvas Box High (Listing 6), Darvas Box Low (Listing 7), Darvas Poss Sell (Listing 8), Darvas Sell (Listing 9), Darvas Buy (Listing 10). To mark the buy and sell signals with up and down arrows, two additional indicators are required: up arrow on buy (Listing 11) will draw an up arrow at the low when Darvas Buy is greater than 1, down arrow on sell (Listing 12) will raw a down arrow at the high when Darvas Sell is greater than 1. Next, use a color plot formula to mark bullish and bearish trends on the chart. To add a color plot formula, right-click onthe data series and select “Add Indicator” from the popup menu. At the Parameter tab of the “Add Indicator” window, add the formula “c >= dvboxlow(data1)” into the formula field; change color 1 to green for bullish; change color 2 to red for bearish. The result is a chart with a pane that draws a colored histogram (Figure 5). A downloadable version of all the indicators and a sample chart will be available from the NeoTicker Yahoo! User group.

LISTING 1 dh := if((h(3) > hhv(4, h, param1)) and (h(3) > h(2)) and (h(3) > h(1)) and (h(3) > h), h(3), dh(1)); plot1 := dh; LISTING 2 dh := dvhigh(data1, 100); def := valid (dh, 0) > 0 and valid(dh, 2) > 0; plot1 := if(def>0 and def(1)=0, 1, 0)+if(dh>0 and dh(1)<>dh, 1, 0); LISTING 3 dh := dvhigh(data1, 100); ndl := (l(3) < l(2)) and (l(3) < l(1)) and (l(3) < l) and (h(2) < dh) and (h(1) < dh) and (h < dh); def := (valid(dh, 0) > 0) and (valid (dh, 1) > 0); plot1 := if(def > 0 and def(1) = 0, 1, 0) +if(ndl > 0 and ndl(1) < 1, 1, 0); LISTING 4 mydl := if(ndvlow(data1) > 0, l(3), mydl(1)); plot1 := mydl; LISTING 5 end := barssince(data1, “ndvhigh(data1) > 0”) < barssince(data1, “ndvlow(1, data1) > 0”); def := valid(end, 0) > 0 and valid(end, 1) < 1; plot1 := if(def > 0 and def(1)=0, 1, 0) +if(end > 0 and ndvlow(data1) > 0, 1, 0); LISTING 6 dbe := dvboxe(data1); dbhi := if(dbe>0 and valid(dbe,1)>0, dvhigh(data1, 100), dbhi(1)); plot1 := if(dbhi=0, h+0.0000001, dbhi); LISTING 7 dbe := dvboxe(data1); bl := if (dbe > 0 and valid (dbe, 1) > 0, dvlow(data1), bl(1)); plot1 := if(bl=0, l-0.0000001, bl);

Page 17: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

—Kenneth Yuen, TickQuest Inc. www.tickquest.com

FIGURE 5: NEOTICKER, MODIFIED DARVAS TECHNIQUE

LISTING 8 dsl := l < dvboxlow(data1); def := valid(dsl, 0) > 0 and valid(dsl, 1) > 0; plot1 := if(def > 0 and def(1)=0, 1, 0)+if(dsl > 0 and dsl(1)<dsl, 1, 0); LISTING 9 mysell := barssince(data1, “dvboxe(data1) > 0”) < barssince(data1, “dvposssell(data1) > 0”); def := valid(mysell, 0) > 0 and valid(mysell, 1) > 0; plot1 := if(def > 0 and def(1)=0, 1, 0) +if(mysell=0 and mysell(1)=1, 1, 0); LISTING 10 mydc := dvsell(data1); mydb := c > dvboxhigh(data1) and barssince(data1, “dvboxe(data1)>0”) <barssince(data1, “dvsell(data1)>0”); dto := if(mydb>0 and dto(1)=0, 1, if(mydc>0, 0, dto(1))); plot1 := if (dto > 0 and dto(1)=0, 1, 0); LISTING 11 plot1 := if(dvbuy(data1) > 0, l-0.01, 0); success1 := if(dvbuy(data1) > 0, 1, 0); LISTING 12 plot1 := if(dvsell(data1) > 0, h+0.01, 0); success1 := if(dvsell(data1) > 0, 1, 0);

Page 18: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

TRADING SOLUTIONS: MODIFIED DARVAS TECHNIQUE This system is also available as a function file that can be downloaded from the TradingSolutions website (www.tradingsolutions.com) in the Solution Library section. As with many indicators, these functions could make good inputs to neural network predictions.

Name: Darvas High (D_High) Inputs: High, Period (100) If (And (GE (Lag (High,3),Lag (Highest (High, Period),4)),GT (Lag (High,3),Highest (High,3))),Lag (High,3),Prev (1)) Name: New Davras High Subvalue Def (NewD_HighSubDef) Inputs: High, Period (100) And (IsNotNull (D_High (High, Period)), IsNotNull (Lag (D_High (High, Period),2))) Name: New Darvas High (NewD_High) Inputs: High, Period (100) Add (And (NewD_HighSubDef (High, Period),Not (Lag (NewD_HighSubDef (High, Period),1))),And (D_High (High, Period),Change (D_High (High, Period),1))) Name: New Darvas Low Subvalue NDL (NewD_LowSubNDL) Inputs: High, Low, Period (100) And (LT (Lag (Low,3),Lowest (Low,3)),LT (Lowest (High,3),D_High (High, Period))) Name: New Darvas Low Subvalue Def (NewD_LowSubDef) Inputs: High, Period (100) And (IsNotNull (D_High (High, Period)),IsNotNull (Lag (D_High (High, Period),1))) Name: New Darvas Low (NewD_Low) Inputs: High, Low, Period (100) Add (And (NewD_LowSubDef (High, Period),Not (Lag (NewD_LowSubDef (High, Period),1))),And (NewD_LowSubNDL (High, Low, Period),LT (Lag (NewD_LowSubNDL (High, Low, Period),1),1))) Name: Darvas Low (D_Low) Inputs: High, Low, Period (100) If (NewD_Low (High, Low, Period),Lag (Low,3),Prev (1)) Name: Darvas Box End Subvalue End (D_BoxEndSubEnd) Inputs: High, Low, Period (100) LT (BarsSinceUL (NewD_High (High, Period)),BarsSinceUL (Lag (NewD_Low (High, Low, Period),1))) Name: Darvas Box End Subvalue Def (D_BoxEndSubDef) Inputs: High, Low, Period (100) And (IsNotNull (D_BoxEndSubEnd (High, Low, Period)),IsNull (Lag (D_BoxEndSubEnd (High, Low, Period),1)))

Page 19: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

Name: Darvas Box End (D_BoxEnd) Inputs: High, Low, Period (100) Add (And (D_BoxEndSubDef (High, Low, Period),Not (Lag (D_BoxEndSubDef (High, Low, Period),1))),And (D_BoxEndSubEnd (High, Low, Period),NewD_Low (High, Low, Period))) Name: Darvas Box High Subvalue DBHI (D_BoxHighSubDBHI) Inputs: High, Low, Period (100) If (And (D_BoxEnd (High, Low, Period),IsNotNull (Lag (D_BoxEnd (High, Low, Period),1))),D_High (High, Period),Prev (1)) Name: Darvas Box High (D_BoxHigh) Inputs: High, Low, Period (100) If (EQ (D_BoxHighSubDBHI (High, Low, Period),0),Add (High,0.0000001),D_BoxHighSubDBHI (High, Low, Period)) Name: Darvas Box Low Subvalue BL (D_BoxLowSubBL) Inputs: High, Low, Period (100) If (And (D_BoxEnd (High, Low, Period),IsNotNull (Lag (D_BoxEnd (High, Low, Period),1))),D_Low (High, Low, Period),Prev (1)) Name: Darvas Box Low (D_BoxLow) Inputs: High, Low, Period (100) If (EQ (D_BoxLowSubBL (High, Low, Period),0),Sub (Low,0.0000001),D_BoxLowSubBL (High, Low, Period)) Name: Darvas Poss Sell Subvalue DSL (D_PossSellSubDSL) Inputs: High, Low, Period (100) LT (Low,D_BoxLow (High, Low, Period) Name: Darvas Poss Sell Subvalue Def (D_PossSellSubDef) Inputs: High, Low, Period (100) And (IsNotNull (D_PossSellSubDSL (High, Low, Period)),IsNotNull (Lag (D_PossSellSubDSL (High, Low, Period),1))) Name: Darvas Poss Sell (D_PossSell) Inputs: High, Low, Period (100) Add (And (D_PossSellSubDef (High, Low, Period),Not (Lag (D_PossSellSubDef (High, Low, Period),1))),And (D_PossSellSubDSL (High, Low, Period),LT (Lag (D_PossSellSubDSL (High, Low, Period),1),D_PossSellSubDSL (High, Low, Period)))) Name: Darvas Sell Subvalue Sell (D_SellSubSell) Inputs: High, Low, Period (100) LT (BarsSinceUL (D_BoxEnd (High, Low, Period)),BarsSinceUL (D_PossSell (High, Low, Period)))

Page 20: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

—Gary Geniesse NeuroDimension, Inc. 800 634-3327, 352 377-5144 http://www.tradingsolutions.com

FIGURE 6: TRADINGSOLUTIONS, MODIFIED DARVAS TECHNIQUE. Here is a chart displaying the Darvas box system. You can see that it was effective during this uptrend.

Name: Darvas Sell Subvalue Def (D_SellSubDef) Inputs: High, Low, Period (100) And (IsNotNull (D_SellSubSell (High, Low, Period)),IsNotNull (Lag (D_SellSubSell (High, Low, Period),1))) Name: Darvas Sell (D_Sell) Inputs: High, Low, Period (100) Add (And (D_SellSubDef (High, Low, Period),Not (Lag (D_SellSubDef (High, Low, Period),1))),And (Not (D_SellSubSell (High, Low, Period)),Lag (D_SellSubSell (High, Low, Period),1))) Name: Darvas Buy Subvalue DTO (D_BuySubDTO) Inputs: Close, High, Low, Period (100) If (And (And (GT (Close,D_BoxHigh (High, Low, Period)),LT (BarsSinceUL (D_BoxEnd (High, Low, Period)),BarsSinceUL (D_Sell (High, Low, Period)))),EQ (Prev (1),0)),1,If (D_Sell (High, Low, Period),0,Prev (1))) Name: Darvas Buy (D_Buy) Inputs: Close, High, Low, Period (100) And (D_BuySubDTO (Close, High, Low, Period),EQ (Lag (D_BuySubDTO (Close, High, Low, Period),1),0)) Name: Darvas Box System Inputs: Close, High, Low, Period (100) Enter Long: D_Buy(Close, High, Low, Period) Exit Long: D_Sell(High, Low, Period)

Page 21: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

TECHINIFILTER PLUS: MODIFIED DARVAS TECHNIQUE Here are the Technifilter Darvas box formulas with some variations.

1. Darvas box top formula. Parameters: 250 (One-year lookback) 2 (Sets the three-day setup)

NAME: DvBoxTop SWITCHES: multiline PARAMETERS: 250,2 FORMULA: [1]: (H<=Hy1M&1)U7 {# days since H > Hm250} [2]: HY[1]{f} {Get the high fixed as at [1]} [3]: [1]>&2 & [1]<100 {#days since high greater than 2 and less than 100} [4]: IF_THEN([3]=1,[2],0)u18 {last non zero value of [2]} 2. Darvas box bottom formula.

Parameters: 250 (One-year lookback) 2 (Sets the three-day setup)

NAME: DVboxbottom SWITCHES: multiline PARAMETERS: 2,250 FORMULA: [1]: (H<HM&2)U7 {# days since 1 lower high year hi} [2]: IF_THEN([1]=0,1,([1]+1)) [3]: LN[2]{f} {Lowest since high} [4]: (L>=[3]y1)u7 {# days since lowest low since high} [5]: IF_THEN([4]=0,1,([4])) [6]: LY[5] {f} {Box Bottom} [7]: [4]>&1 {Tests Look back} [8]: HY[1]{f} [9]: [1]>&1 & [1]<100 [10]: IF_THEN(([7]=1 & [9]=1),[6],0)u18 3. Darvas box top formula with the option to push the top x% higher, to minimize whipsaws or false breakouts.

Parameters: 250 (One-year lookback) 2 (Sets the three-day setup) 1.005 (0.5%) (The percentage the high must go above the box top to trigger an entry)

NAME: DvBoxTopTrigger SWITCHES: multiline PARAMETERS: 250,2,1.005 FORMULA: [1]: (H<=Hy1M&1)U7 {# days since H > Hm250} [2]: HY[1]{f} {Get the high fixed as at [1]} [3]: [1]>&2 & [1]<100 {#days since high greater than 2 and less than 100} [4]: IF_THEN([3]=1,[2],0)u18 {last non zero value of [2]} [5]: [4]*&3 {Multiply the Top by a %}

Page 22: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

—Benzie Pikoos, Brightspark +61 8 9375-1178 [email protected] www.technifilter.com

FIGURE 7. TECHNIFILTER PLUS, MODIFIED DARVAS TECHNIQUE. Here is a sample Darvas box chart in TechniFilter with the adjustable trigger and stop-loss line.

4. Darvas box bottom formula with the option to push the bottom x% lower to minimize whipsaws or false triggers of the stop-loss.

Parameters: 250 (One-year lookback) 2 (Sets the three-day setup) 0.99 (1%) (The percentage the close must go below the bottom of the box to trigger a stop signal.

NAME: DVboxbottomStop SWITCHES: multiline PARAMETERS: 2,250,.99 FORMULA: [1]: (H<HM&2)U7 {# days since 1 lower high year hi} [2]: IF_THEN([1]=0,1,([1]+1)) [3]: LN[2]{f} {Lowest since high} [4]: (L>=[3]y1)u7 {# days since lowest low since high} [5]: IF_THEN([4]=0,1,([4])) [6]: LY[5] {f} {Box Bottom} [7]: [4]>&1 {Tests Look back} [8]: HY[1]{f} [9]: [1]>&1 & [1]<100 [10]: IF_THEN(([7]=1 & [9]=1),[6],0)u18 [11]: [10]*&3 {multiply the Bottom by a % } Visit the TechniFilter Plus website to download these reports, strategy backtests, and formulas.

Page 23: Bonus Darvas Charting Formula - s3. · PDF fileImplementing the required calculations in AmiBroker Formula Language (AFL) is straightforward. Ready-to-use Darvas formulas for AmiBroker

FIGURE 8: TECHNIFILTER PLUS, STANDARD DARVAS. The box is the solid line, and the dotted lines are the adjustable lines.