Jump to content

[REQ]Darvas Channel


Recommended Posts

Here is the formula:

 

[spoiler=code]//+------------------------------------------------------------------+

//| Darvas Boxes.mq4 |

//| Copyright © 2004, MetaQuotes Software Corp. |

//| http://www.metaquotes.net |

//+------------------------------------------------------------------+

#property copyright "Copyright © 2004, MetaQuotes Software Corp."

#property link "http://www.metaquotes.net"

//----

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 RoyalBlue

#property indicator_color2 RoyalBlue

//----

double ind_buffer1[];

double ind_buffer2[];

//----

bool allow_buy;

bool allow_sell;

double price;

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- indicators

SetIndexStyle(0,DRAW_LINE);

SetIndexDrawBegin(0,0);

SetIndexBuffer(0, ind_buffer1);

//

SetIndexStyle(1,DRAW_LINE);

SetIndexDrawBegin(1,2);

SetIndexBuffer(1, ind_buffer2);

//

allow_buy=true;

allow_sell=false;

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custor indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

//---- TODO: add your code here

//----

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int counted_bars=IndicatorCounted();

//---- TODO: add your code here

double box_top=0;

double box_bottom=0;

int state=1;

//----

for(int i=Bars - 1; i > 0; i--)

{

if (state==1)

{

box_top=High;

}

else if (state==2)

{

if (box_top > High)

{

}

else

{

box_top=High;

}

}

else if (state==3)

{

if (box_top > High)

{

box_bottom=Low;

}

else

{

box_top=High;

}

}

else if (state==4)

{

if (box_top > High)

{

if (box_bottom < Low)

{

}

else

{

box_bottom=Low;

}

}

else

{

box_top=High;

}

}

else if (state==5)

{

if (box_top > High)

{

if (box_bottom < Low)

{

}

else

{

box_bottom=Low;

}

}

else

{

box_top=High;

}

state=0;

}

ind_buffer1=box_top;

ind_buffer2=box_bottom;

state++;

}

ind_buffer1[0]=EMPTY_VALUE;

ind_buffer2[0]=EMPTY_VALUE;

//----

return(0);

}

//+------------------------------------------------------------------+----+

 

Link to comment
Share on other sites

1. First copy the whole code I have given, highlight the text then use CTRL + C to copy.

 

2. Now open Metaeditor within MT4 platform, click File, then New, then select Custom Indicator, click next, give the indicator a name, hit finish.

 

3. Now you have some text, highlight all & delete. Now use CTRL + V to paste the code from your clipboard & hit compile.

 

4. The indicator will now appear on your indicator list in Navigator.

Link to comment
Share on other sites

The modified darvas indicator is drawing the box top horizontal line once there is 3 lower high is formed. The horizontal line will be remained at that position till next box top is formed. Once the next box top is formed, the old horizontal line will be connected to the new horizontal line diagonally. Please refer to the attached chart for clarification.

 

This is also applied for the box bottom.

Link to comment
Share on other sites

I have found the formula you mention, but it is for metastock. If any coders can convert it to MT4 then code is below:[spoiler=metastock code]CLASSIC DARVAS BOX FORMULAS FOR METASTOCK

 

These formulas were developed by Matthew Ford. They provide a method of plotting the parameters of the Classic Darvas Box in 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:

 

end:=BarsSince(Fml("New Darvas High")) <

 

BarsSince(Ref(Fml("New Darvas Low"),-1));

 

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:

 

sell:=BarsSince(Fml("Darvas Box End")) <

 

BarsSince(Fml("Darvas Poss Sell"));

 

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

 

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

 

Name of Indicator: Darvas Buy

 

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

 

(BarsSince(Fml("darvas box end")) < BarsSince(Fml("darvas sell")));

 

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

 

Buy: up arrow graphic, formula Fml("Darvas Buy")

 

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

 

For Alerts tab use

 

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

 

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

 

 

 

The Fractal channel is another possibility if you can adjust it to plot highs & lows after every 3rd lower low or 3rd higher high.

Link to comment
Share on other sites

Here is the fractal channel indicator.[spoiler=code]//+------------------------------------------------------------------+

//| Fractal Channel |

//| Copyright © 2005 Chris Battles |

//| [email protected] |

//+------------------------------------------------------------------+

#property copyright "Chris Battles"

#property link "mailto:[email protected]"

 

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 Red

#property indicator_color2 Blue

 

//---- buffers

double v1[];

double v2[];

double val1;

double val2;

int i;

 

int init(){

IndicatorBuffers(2);

//---- drawing settings

SetIndexArrow(0, 119);

SetIndexArrow(1, 119);

 

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2,Red);

SetIndexDrawBegin(0,i-1);

SetIndexBuffer(0, v1);

SetIndexLabel(0,"Resistance");

 

SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2,Blue);

SetIndexDrawBegin(1,i-1);

SetIndexBuffer(1, v2);

SetIndexLabel(1,"Support");

 

return(0);

}

 

int start(){

i=Bars;

while(i>=0){

val1 = iFractals(NULL, 0, MODE_UPPER,i);

if (val1 > 0)

v1=High;

else

v1 = v1[i+1];

 

val2 = iFractals(NULL, 0, MODE_LOWER,i);

if (val2 > 0)

v2=Low;

else

v2 = v2[i+1];

 

i--;

}

return(0);

}

 

//+------------------------------------------------------------------+

 

 

Enjoy.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...