Modified Darvas Box
The Modified Darvas Box AFL in Amibroker is based on the Darvas Box theory, identifying potential breakout areas. Leveraging amibroker data feed functionalities, this AFL assists traders in recognizing price consolidation and breakout patterns. The Modified Darvas Box helps traders make informed decisions by identifying key levels for potential trading opportunities.
/ // // After reference the Darvas Box code from Stephane, I added an additional // rule of sell. So that the profit can increase a bit. The idea is the found // the suitable selling point after we found the box top. When it meet the // highest point and turn back, we sell if the different between the highest // price and current close price is greater than a certain prestentage. Just // like to share and hope can get comment from the others, since I am a // beginner of TA. // //------------------------------------------------------------------------------ //////////begin///////// 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; DBuy = 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(BoxTop*(1+tick/100))) { fillDarvas(BoxStart,i,swap,BoxTop,BoxBot); state = 1; swap = !swap; BoxTop = High[i]; BoxStart = i; } } else { if (High[i] BoxBot)) { state++; } else { state=3; } if (state==3) BoxBot=Low[i]; } else { state=1; BoxTop=High[i]; } } StateArray[i] = state; } fillDarvas(BoxStart,BarCount,swap,BoxTop,BoxBot); Buyrule=H>Ref(box1,-1) AND H>Ref(box2,-1) AND Ref(statearray,-1)==5; Sellrule=Lbox2,box1,box2); Sellrule2 = (((topvalue-Close)*100/topvalue) > lossopt) AND (statearray == statopt); Sell = Sellrule OR Sellrule2; Short = Sell; Cover = Buy;