klkoo Posted May 17, 2011 Report Share Posted May 17, 2011 (edited) Anybody has the MT4 formula for the Darvas Channel? The Darvas Channel is similar with the fractal channel. Edited May 17, 2011 by klkoo To put the request in the title Quote Link to comment Share on other sites More sharing options...
shabz Posted May 17, 2011 Report Share Posted May 17, 2011 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); } //+------------------------------------------------------------------+----+ Quote Link to comment Share on other sites More sharing options...
dannydon786 Posted May 18, 2011 Report Share Posted May 18, 2011 do you have the mt4 indicator complied sabz thanks Quote Link to comment Share on other sites More sharing options...
murtamad Posted May 18, 2011 Report Share Posted May 18, 2011 dannydon786, you could compile it with the mql editor that is in every mt4 platform. Or just put the mq4 file into your mt4 experts/indicator folder. Remember to close mt4 first and upon restarting it will compile the indicator automatically. Quote Link to comment Share on other sites More sharing options...
Guest indoshare Posted May 18, 2011 Report Share Posted May 18, 2011 is this indi good??????????? Quote Link to comment Share on other sites More sharing options...
shabz Posted May 18, 2011 Report Share Posted May 18, 2011 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. Quote Link to comment Share on other sites More sharing options...
klkoo Posted May 18, 2011 Author Report Share Posted May 18, 2011 Actually, I am looking at the modified of the darvas support & resistance lines as per atttached chart. Anybody can modify the code accordingly? Thanks you in advanced. Attachment of chart:- http://www.4shared.com/photo/mSlkFzep/TM_17-2-10.html Quote Link to comment Share on other sites More sharing options...
shabz Posted May 20, 2011 Report Share Posted May 20, 2011 What is the difference ? Quote Link to comment Share on other sites More sharing options...
klkoo Posted May 20, 2011 Author Report Share Posted May 20, 2011 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. Quote Link to comment Share on other sites More sharing options...
shabz Posted May 21, 2011 Report Share Posted May 21, 2011 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. Quote Link to comment Share on other sites More sharing options...
shabz Posted May 21, 2011 Report Share Posted May 21, 2011 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.