Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

divergence 85% success rate Avg profit 1.45% for Amibroker (AFL)

Copy & Paste Friendly
// ********************************************
// INDICATOR	:DIVERGENCE
// DATE		:07-30-04
// PROGRAMMER	:M.Lauronen
// COPYRIGHTS	:Public Domain
// ********************************************

// --------------------------------------------
// Recommended AmiBroker indicator settings:
//		Level 0
//		Percent
//		Middle
//		Scaling: Custom 0 - 100
// --------------------------------------------

// Adjust the following parameters to suit your needs
// Adjust the following parameters to suit your needs

//period = Param("% change",0.4,0.1,25,0.1);
//period	= 5;
uplimit=2;
uplimit=IIf(Interval()==in15Minute,4,IIf(Interval()==inHourly,8,
								IIf(Interval()==inDaily,12,uplimit)));
i=uplimit;
globalTitile=" ";
BuyCond  =ShortCond=False;
divergenceCount=0;
highCount=0.0;

for(;i>=0.2;){
numChg = i ;
i=i-0.1;
// --------------------------------------------
// Divergence for LONG
// --------------------------------------------

trendMom	= RSI(5);

periods = 5;
Ksmooth = 3;
trendStoch=StochK( periods , Ksmooth);  

bull=High - EMA(Close,13);
bear=Low - EMA(Close,13);
bb=bull+bear;


Hist=MACD(12,26)-Signal(12,26,9);

FI = (Close - Ref(Close, -1)) * V;


trendZig	= Zig(L, numChg);


f	= trendZig > Ref(trendZig, -1) AND Ref(trendZig, -1) < Ref(trendZig, -2);

p1	= ValueWhen(f, Ref(trendZig, -1), 1); 
p2	= ValueWhen(f, Ref(trendZig, -1), 2);
r1	= ValueWhen(f, Ref(trendMom,-1), 1);
r2 	= ValueWhen(f, Ref(trendMom,-1), 2);
stockUp1= ValueWhen(f, Ref(trendStoch,-1), 1);
stockUp2= ValueWhen(f, Ref(trendStoch,-1), 2);
bbUP1= ValueWhen(f, Ref(bb,-1), 1);
bbUP2= ValueWhen(f, Ref(bb,-1), 2);
HistUP1= ValueWhen(f, Ref(Hist,-1), 1);
HistUP2= ValueWhen(f, Ref(Hist,-1), 2);
FIUP1= ValueWhen(f, Ref(FI,-1), 1);
FIUP2= ValueWhen(f, Ref(FI,-1), 2);


f	= r1 > r2 AND p1 < p2;
fStoch=stockUp1 > stockUp2 AND p1 < p2;
fbb=bbUP1> bbUP2 AND p1 < p2;
HistUP=HistUP1> HistUP2 AND p1 < p2;
FIUP= FIUP1 > FIUP2 AND p1 < p2;

sigRSI	= f AND NOT Ref(f, -1) AND trendMom > Ref(trendMom, -1); 
sigStockUp	= fStoch AND NOT Ref(fStoch, -1) AND trendStoch > Ref(trendStoch, -1); 
sigbbUp	= fbb AND NOT Ref(fbb, -1) AND bb> Ref(bb, -1); 
HistSigUP 	= HistUP AND NOT Ref(HistUP , -1) AND Hist> Ref(Hist, -1); 
FISigUP 	= FIUP AND NOT Ref(FIUP, -1) AND FI> Ref(FI, -1);

//_N(str = "(" + period + ")");
///Plot(trendMom, "RSI" + str, colorWhite);
Plot(trendZig, "zig", colorBlack,styleOwnScale);
Plot(sigRSI* 100, "RsiSigUp", colorGreen, styleHistogram + styleThick + styleNoLabel);
Plot(sigStockUp* 100, "StockSigUp", colorGreen, styleHistogram + styleThick + styleNoLabel);
Plot(sigbbUp* 100, "bbUp", colorGreen, styleHistogram + styleThick + styleNoLabel);
Plot(HistSigUP * 100, "MACDUp", colorGreen, styleHistogram + styleThick + styleNoLabel);
Plot(FISigUP * 100, "FIUP", colorGreen, styleHistogram + styleThick + styleNoLabel);



// --------------------------------------------
// Divergence for SHORT
// --------------------------------------------

trendZig2	= Zig(H, numChg);

f	= trendZig2 < Ref(trendZig2, -1) AND Ref(trendZig2, -1) > Ref(trendZig2, -2);

p1	= ValueWhen(f, Ref(trendZig2, -1), 1);
p2	= ValueWhen(f, Ref(trendZig2, -1), 2);
r1	= ValueWhen(f, Ref(trendMom,-1), 1);
r2 	= ValueWhen(f, Ref(trendMom,-1), 2);
stockDown1= ValueWhen(f, Ref(trendStoch,-1), 1);
stockDown2= ValueWhen(f, Ref(trendStoch,-1), 2);
bbDown1= ValueWhen(f, Ref(bb,-1), 1);
bbDown2= ValueWhen(f, Ref(bb,-1), 2);
HistDown1= ValueWhen(f, Ref(Hist,-1), 1);
HistDown2= ValueWhen(f, Ref(Hist,-1), 2);
FIDown1= ValueWhen(f, Ref(FI,-1), 1);
FIDown2= ValueWhen(f, Ref(FI,-1), 2);



f	= r1 < r2 AND p1 > p2;
fStoch=stockDown1 < stockDown2 AND p1 > p2;
fbb=bbDown1 < bbDown2 AND p1 > p2;
HistDown=HistDown1< HistDown2 AND p1 > p2;
FIDown= FIDown1 < FIDown2 AND p1 > p2;

sigRSIDown	= f AND NOT Ref(f, -1) AND trendMom < Ref(trendMom, -1); 
sigStock	= fStoch AND NOT Ref(fStoch, -1) AND trendStoch < Ref(trendStoch, -1); 
sigbbDown	= fbb AND NOT Ref(fbb, -1) AND bb < Ref(bb, -1);
HistSigDown 	= HistDown AND NOT Ref(HistDown , -1) AND Hist< Ref(Hist, -1); 
FISigDown	= FIDown AND NOT Ref(FIDown, -1) AND FI< Ref(FI, -1);

//_N(str = "(" + period + ")");
Plot(sigRSIDown* 100, "rsiSigDown", colorRed, styleHistogram + styleThick + styleNoLabel);
Plot(sigStock* 100, "StockSigDown", colorRed, styleHistogram + styleThick + styleNoLabel);
Plot(sigbbDown* 100, "bbDown", colorRed, styleHistogram + styleThick + styleNoLabel);
Plot(HistSigDown * 100, "MAcdDown", colorRed, styleHistogram + styleThick + styleNoLabel);
Plot(FISigDown* 100, "FIDown", colorRed, styleHistogram + styleThick + styleNoLabel);


divergenceCount+=IIf(sigRSI,1,0) + IIf(FISigUP,1,0)+ 
					 IIf(sigStockUp ,1,0)+ IIf(sigbbUp ,1,0)+  IIf(HistSigUp ,1,0);

divergenceCount+=IIf(sigRSIDown ,1,0) + IIf(sigStock ,1,0)+ 
					 IIf(sigbbDown ,1,0)+ IIf(HistSigDown ,1,0)+  IIf(FISigDown,1,0);



BuyCondTmp=sigRSI OR sigStockUp OR  sigbbUp OR HistSigUp OR  FISigUP;
ShortCondTmp=sigRSIDown OR sigStock OR sigbbDown OR HistSigDown OR FISigDown;
highCount+=IIf(BuyCondTmp OR ShortCondTmp,numChg,0.0);

BuyCond = BuyCond OR BuyCondTmp ;
BuyCond=BuyCond AND (highCount>10);
ShortCond= ShortCond OR ShortCondTmp;
ShortCond=ShortCond AND (highCount>10);	



globalTitile+=WriteIf(BuyCondTmp OR ShortCondTmp ,""+i,"")+

	  	WriteIf(sigRSI,"rsiup ","")+WriteIf(sigStockUp,"stochup ","")+WriteIf(sigbbUp,"bbup ","")
		+WriteIf(HistSigUP ,"macdup ","")+ WriteIf(FISigUP,"FIUP ","") 



		+WriteIf(sigRSIDown ,"rsiDown ","")+WriteIf(sigStock ,"stochDown ","")+WriteIf(sigbbDown,"bbDown ","")
		+WriteIf(HistSigDown ,"macdDown ","")+ WriteIf(FISigDown,"FIDown ","")
		+ WriteIf(BuyCondTmp OR ShortCondTmp ,"\n","");
		





} //for

Title=globalTitile;



FirstTradeTime = 091500;				// Earliest time to take a trade
LastTradeTime = 151500;					// Latest time to take new trades
ExitAllPositionsTime = 151500;	
//change = Param("% change",0.1,0.1,25,0.1);
z = Zig(Close, 0.8 );

Buy=(BuyCond )  ;//AND (TimeNum() >= FirstTradeTime AND TimeNum() <= LastTradeTime );
Sell = IIf(z < Ref(z, -1), 1, 0) ;//  OR TimeNum() > ExitAllPositionsTime;
Short=(ShortCond ) ;//AND (TimeNum() >= FirstTradeTime AND TimeNum() <= LastTradeTime );
Cover = IIf(z > Ref(z, -1), 1, 0) ;//OR	 TimeNum() > ExitAllPositionsTime;
 
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short); 


Filter=BuyCond OR ShortCond;
//Filter=Filter AND (TimeNum()>091500 AND TimeNum()<100000);


AddColumn(BuyCond,"DiverBuy");
AddColumn(ShortCond,"DiverSell"); 
AddColumn(divergenceCount,"no of diver");
AddColumn(highCount,"high");
//AddTextColumn(globalTitile,"indicators");
//AddColumn(StrLen(globalTitile),"StrLen",1);


		
Back