Welcome Features News Download Registration Support FAQ Wish list Links
Advanced stock charting and analysis program

AFL Library

This is read-only version of AFL library entry. Ability to add user formulas and comment is only available from members-only area.

Details:

Formula name: Against all odds
Author/Uploader: hostyle - hostyle [at] ifrance.com
Date/Time added: 2001-06-20 13:49:09
Origin: France
Keywords:
Level: medium
Flags: system,exploration,commentary

DISCLAIMER: Most formulas present in AFL on-line library are submitted by the users and are provided here on an "as is" and "as available" basis. AmiBroker.com makes no representations or warranties of any kind to the contents or the operation of material presented here. We do not maintain nor provide technical support for 3rd party formulas.
Description:

Against all odds. Written by Thierry HUITEL. Based on Jim Varney's work-- CANDLESTOCHASTICS-- , and all the amibroker group :-).This Exploration is a scan for 24 different buy or sell signals that selects days when several bullish or bearish indicators are triggered at the same time.

Formula:

/*Against all odds (draft). Written by Thierry HUITEL o-l---} */
/* based on Jim Varney's work-- CANDLESTOCHASTICS-- */
/*and all the amibroker group :-) */

/*
This Exploration is a scan for 24 different buy or sell signals.
The odds are 1 of 6 to get a TWO with a dice. If you try 1000 times, the odds
are more than 99%.
The aim of the exploration is to find days when many bullish or bearish signs
are triggered at the same time. If 5 indicators give a buy advice, it is more
reliable than one.
I invite everybody to add your own systems to these ones, to improve the
reliability. And experimented technical analysts could give advices to avoid the
trap of using several different indicators all working off the same input data.

Vol Index: this column is the ratio of today's volume to the 14-day average
volume.
This column should be sorted Descending. The best signals are occur when
VolIndex is at least 2 or higher.

PCL[up]: Piercing Line, "up" signifies Bullish.
MDS[up]: Morning Doji Star
BLE[up]: Bullish Engulfing
HAM[up]: Hammer
BRE[dn]: Bearish Engulfing, "dn" signifies Bearish.
DCC[dn]: Dark Cloud Cover
EDS[dn]: Evening Doji Star
TDREI[up] & [dn]: Tom DeMark's Range Expansion Index 
KUP[up] & [dn]: Keltner Bands -DIMITRIS TSOKAKIS
RSI[up] & [dn]: Relative Strength Index 14 periods
MFI[up] & [dn]: Money Flow Index
ST2[up] & [dn]: Stochastic Slow - Donald Dalley
DIV[up] & [dn]: % R divergence  -DIMITRIS TSOKAKIS
KST[up] & [dn]: MARTIN PRING'S KST MOMENTUM SYSTEM -TJ
COP[up]: Coppock Curve TJ
SMH[up] & [dn]: smash day pattern. DIMA
CHK[up] & [dn]: Chaikin Money Flow. Thierry Huitel

A "1" in the column signifies TRUE, a "0" indicates no signal.
------------------------------------------------------------------*/
"Commentaires sur  " + name() +" pour le  "+date();

/* Minimum Price and 14 day Avg Volume Values for Filter */
minPrice = 3;     //change as needed
minVol = 50000;   //change as needed

VolAvg = ma( v, 14 );
VolumeIdx = v / VolAvg;
AvgRange = sum( abs(O-C),15 )/15;

/* Candle Codes */
White = iif((C>O) AND ((C-O)>=0.8*(H-L)),1,0) AND (C-O)>AvgRange;
Black = iif((C<O) AND ((O-C)>=0.8*(H-L)),1,0) AND (O-C)>AvgRange;
Doji  = iif(abs(O-C)<=0.1*(H-L),1,0);

/* Dark Cloud Cover [Bear] */
DCC = iif(ref(White, -1) AND Black AND C<=ref(((H+L)/2),-1)
	AND O>ref(C,-1), 1,0);

/* Piercing Line [Bull] */
PL = iif(ref(Black, -1) AND White AND C>=ref(((H+L)/2),-1)
	AND O<ref(C,-1), 1,0);

/* Evening Doji Star [Bear] */
EDS = iif(ref(White, -2) AND ref(Doji, -1) AND Black AND
	C<=ref(((H+L)/2),-2), 1,0);

/* Morning Doji Star [Bull] */
MDS = iif(ref(Black, -2) AND ref(Doji, -1) AND White AND
	C>=ref(((H+L)/2),-2), 1,0);

/* Hammer [Bull] */
HAM = iif( (H-L > 1.5*AvgRange) AND (C > (H+L)/2)  AND (O > C) AND 
	(VolumeIdx > 2), 1, 0);

/* Bearish Engulfing */
BRE = iif(Black AND ref(White, -1) AND (C < ref(O, -1))  AND (O > ref(C, -1)),
1,0);

/* Bullish Engulfing */
BLE = iif(White AND ref(Black, -1) AND (C > ref(O,-1))  AND (O < ref(C,-1)),
1,0);


/* Stochastics 14-4 */

ss = ma(stochk(14),4);
StochBuy = iif(ss<=20, 1, 0);
StochSell = iif(ss>=80, 1, 0);

/* TDREI */
HighMom = H - Ref( H, -2 );
LowMom = L - Ref( L, -2 );
Cond1 = ( H >= Ref( L,-5) OR H >= Ref( L, -6 ) ); 
Cond2 = ( Ref( H, -2 ) >= Ref( C, -7 ) OR Ref( H, -2 ) >= Ref( C, -8 ) ); 
Cond3 = ( L <= Ref( H, -5 ) OR L <= Ref( H, -6) ); 	
Cond4 = ( Ref( L, -2 ) <= Ref( C, -7 ) OR Ref( L, -2 ) <= Ref( C, -8 ) );
Cond = ( Cond1 OR Cond2 ) AND ( Cond3 OR Cond4 );
Num = IIf( Cond, HighMom + LowMom, 0 );
Den = Abs(  HighMom ) + Abs( LowMom );
TDREI = 100 * Sum( Num, 5 )/Sum( Den, 5 ) ;
tdreiBuy = iif(TDREI<=-95, 1, 0);
tdreiSell = iif(TDREI>=95, 1, 0);

/* KUP */
KUP=EMA((H+L+C)/3,10)+EMA(H-L,10);
KDOWN=EMA((H+L+C)/3,10)-EMA(H-L,10);
kupBuy = iif(CROSS(C,KDOWN), 1, 0);
kupSell = iif(CROSS(KUP,C), 1, 0);

/*RSI*/
vrsi= rsi(14);
rsiBuy = iif(CROSS(vrsi,30), 1, 0);
rsiSell = iif(CROSS(70,vrsi), 1, 0);

/*MFI*/
mfiBuy = iif(CROSS(mfi(),30), 1, 0);
mfiSell = iif(CROSS(70,mfi()), 1, 0);

/*STO2*/
lookback = 14;
buyrange = 30;
sellrange = 70;
stochKworkaround = STOCH(14);
stochDworkaround = EMA( STOCH(14), 5);
sto2Buy = iif(STOCH(14) < buyrange AND CROSS(stochKworkaround,
stochDworkaround), 1, 0);
sto2Sell = iif(STOCH(14) > sellrange AND CROSS(stochDworkaround,
stochKworkaround), 1, 0);

/* %R, ema 9 and divergences */

R=-100*((HHV(HIGH,14)-CLOSE))/(HHV(HIGH,14)-LLV(LOW,14));
DIVR=(R-REF(R,-1))*(C-REF(C,-1));
DIVB=IIF((DIVR<0) AND (R-ref(R,-1))>0 and (REF(R,-1)<-90),-100,0);
DIVB1=IIF((DIVR<0) AND (R-ref(R,-1))>0 and (REF(R,-1)<-90),-80,0);
DIVS=IIF((DIVR<0) AND (R-ref(R,-1))<0 and (REF(R,-1)>-10),-20,0);
divBuy = iif(DIVB==-100, 1, 0);
divSell = iif(DIVS==-20, 1, 0);

/*KST*/

KST =  (MA(ROC(CLOSE,10),10) * 1) +
            (MA(ROC(CLOSE,15),10) * 2) +
            (MA(ROC(CLOSE,20),10) * 3) +
            (MA(ROC(CLOSE,30),15) * 4);
kstBuy = iif(CROSS(KST ,  MA(KST, 109)), 1, 0);
kstSell = iif(CROSS(MA(KST , 120), KST), 1, 0);

/*COP*/
copBuy = iif((EMA( ROC( MA( C, 22 ), 250 ), 150 ) / 100) < 0, 1, 0);

/*SMASH*/
numDays = 3; // Consider smash Day if closed above/below previous numDays
highs/lows
closeInDayRangePct = 0.25; // Smash day close should be in the high/low %% of
the day range
smashDayDown = close < LLV (ref (low, -1), numDays) AND close < open AND close
< (low + closeInDayRangePct * (high - low));
smashDayUp = close > HHV (ref (high, -1), numDays) AND close > open AND close >
(high - closeInDayRangePct * (high - low));
// Enter in the direction opposite to the smash day if the very next day price
moves opposite the smash day.
smashBuy = iif(ref (smashDayDown, -1) AND high > ref (high, -1), 1, 0);
smashSell = iif(ref (smashDayUp, -1) AND low < ref (low, -1), 1, 0);

/*CHAIKIN MONEY FLOW*/
ICH = sum(((( C-L )-( H-C )) / ( H-L ))*V, 21 ) / sum(V,21); 
LCH = llv( ICH, 255 );
top = (LCH/2);
chkBuy = cross (ICH, top);
chkSell = cross (0, ICH);

/*number of buy signals --- give weight to your favorite ones with a
coefficient. */
somme= PL + MDS + HAM + BLE + tdreiBuy + kupBuy + rsiBuy + (2*mfibuy) + sto2Buy
+ (2*divBuy) + kstBuy + copBuy + (2*smashBuy) + chkBuy;

/*number of sell signals. */
somme2 = BRE + DCC + EDS + tdreiSell + kupSell + rsiSell + mfiSell + sto2Sell +
divSell + divSell + kstSell + smashSell + chkSell;

/*Guru comment*/
"number of buy indicators triggered: " + writeval (somme) ;
"Aujourd'hui, les signaux haussiers suivants ont été déclenchés: ";

/* Exploration Columns for Sorting */

NumColumns = 29;

Column0 = V;
Column1 = VolumeIdx;
Column2 = somme;
Column3 = PL;
Column4 = MDS;
Column5 = BLE;
Column6 = HAM;
Column7 = BRE;
Column8 = DCC;
Column9 = EDS;
Column10 = tdreiBuy;
Column11 = tdreiSell;
Column12 = kupBuy;
Column13 = kupSell;
Column14 = rsiBuy;
Column15 = rsiSell;
Column16 = mfiBuy;
Column17 = mfiSell;
Column18 = sto2Buy;
Column19 = sto2Sell;
Column20 = divBuy;
Column21 = divSell;
Column22 = kstBuy;
Column23 = kstSell;
Column24 = copBuy; 
Column25 = smashBuy;
Column26 = smashSell;
Column27 = chkBuy;
Column28 = chkSell;

Column0Name = "Volume"; 
Column1Name = "Vol Idx";
Column2Name = "triggers";
Column3Name = "PCL[up]";
Column4Name = "MDS[up]";
Column5Name = "BLE[up]";
Column6Name = "HAM[up]";
Column7Name = "BRE[dn]";
Column8Name = "DCC[dn]";
Column9Name = "EDS[dn]";
Column10Name = "TDREI[up]";
Column11Name = "TDREI[dn]";
Column12Name = "KUP[up]";
Column13Name = "KUP[dn]";
Column14Name = "RSI[up]";
Column15Name = "RSI[dn]";
Column16Name = "MFI[up]";
Column17Name = "MFI[dn]";
Column18Name = "ST2[up]";
Column19Name = "ST2[dn]";
Column20Name = "DIV[up]";
Column21Name = "DIV[dn]";
Column22Name = "KST[up]";
Column23Name = "KST[dn]";
Column24Name = "COP[up]";
Column25Name = "SMH[up]";
Column26Name = "SMH[dn]";
Column27Name = "CHK[up]";
Column28Name = "CHK[dn]";

Column0format = 1.0;
Column1format = 1.1;
Column2format = 1.1;
Column3format = 1.2;
Column4format = 1.0;
Column5format = 1.0;
Column6format = 1.0;
Column7format = 1.0;
Column8format = 1.0;
Column9format = 1.0;
Column10format = 1.0;
Column11format = 1.0;
Column12format = 1.0;
Column13format = 1.0;
Column14format = 1.0;
Column15format = 1.0;
Column16format = 1.0;
Column17format = 1.0;
Column18format = 1.0;
Column19format = 1.0;
Column20format = 1.0;
Column21format = 1.0;
Column22format = 1.0;
Column23format = 1.0;
Column24format = 1.0;
Column25format = 1.0;
Column26format = 1.0;
Column27format = 1.0;
Column28format = 1.0;

/* Filter */
/*the highest % for somme gives the most reliable buy signal*/
Filter = somme>=6 and VolumeIdx>=2;
/*Filter = ((C > minPrice) AND (VolAvg >= minVol)) AND (StochBuy AND (PL or MDS
or BLE or HAM)) OR (StochSell AND (BRE or DCC or EDS));*/


/* Buy and Sell */
/* set your own requirements: how many indicators triggered at the same time
*/
Buy = somme>=6;
Sell = somme2>=3;
writeval (somme);

Comments:

Scuba
scubastock [at] hotmail.com
2001-07-26 15:36:15
Hello, this is a very interesting system to work with, and I hope you get input from more users and expand on it.

FYI I have added one more buy/sell indicator (and given it weight 2) which seem to work well for me:

/*MACD SIGNAL CROSS*/
macdBuy = cross(macd(), ema(macd(),9));
macdSell = cross(ema(macd(),9), macd());

I would also think it would be interesting to add pattern recognition like Thomasz' Double top detection (http://www.amibroker.com/library/detail.php?id=19) and a double bottom detection version of this.


:-) Scuba
Scuba
scubastock [at] hotmail.com
2001-07-27 06:26:33
Hello again :) I have added an expanded commentary, that I think is nice to use to quickly see which indicators are triggered (on all days, not only those which trigger an automated buy/sell-signal). Feel free to add it and improve on it in a new version of this system if you like.

What could be interesting here is to have two 'grades' of automated buy/sell signals for different levels of triggers. Red/green arrows for very strong signal (high number of concurrent indicators) and two different coloured arrows for weaker signals (a lower number of concurrent indicators). Is this possible?

And maybe move all user-changeable values and weighting to a section in the top of the code?

BTW, it seems that divSell is listed twice under /*number of sell signals. */

The expanded commentary: (but first a little more translation in the top :)
------------------------------------------------------------------*/
"Comments for " + name() +" for date "+date();

Then:

/*Guru comment*/
"Weighted buy indicator: " + writeval (somme) ;
"Weighted sell indicator: " + writeval (somme2) ;
"";
"Buy indicators triggered:\n" + writeif(PL==1,"Candlestick Piercing Line\n","") + writeif(MDS==1,"Candlestick Morning Doji Star\n","") + writeif(HAM==1,"Candlestick Hammer\n","") + writeif(BLE==1,"Candlestick Bullish Engulfing\n","") + writeif(tdreiBuy==1,"DeMark's Range Expansion Index\n","") + writeif(kupBuy==1,"Keltner Bands\n","") + writeif(rsiBuy==1,"RSI\n","") + writeif(mfiBuy==1,"Money Flow Index\n","") + writeif(sto2Buy==1,"Stochastic Slow\n","") + writeif(divBuy==1,"% R divergence\n","") + writeif(kstBuy==1,"Pring's KST momentum\n","") + writeif(copBuy==1,"Coppock Curve\n","") + writeif(smashBuy==1,"Smash Day pattern\n","") + writeif(chkBuy==1,"Chaikin Money Flow\n","") + writeif(macdBuy==1,"MACD signal cross\n","")+writeif(somme==0,"None\n","");
"Sell indicators triggered:\n" + writeif(BRE==1,"Candlestick Bearish Engulfing\n","") + writeif(DCC==1,"Candlestick Dark Cloud Cover\n","") + writeif(EDS==1,"Candlestick Evening Doji Star\n","") + writeif(tdreiSell==1,"DeMark's Range Expansion Index\n","") + writeif(kupSell==1,"Keltner Bands\n","") + writeif(rsiSell==1,"RSI\n","") + writeif(mfiSell==1,"Money Flow Index\n","") + writeif(sto2Sell==1,"Stochastic Slow\n","") + writeif(divSell==1,"% R divergence\n","") + writeif(kstSell==1,"Pring's KST momentum\n","") + writeif(smashSell==1,"Smash Day pattern\n","") + writeif(chkSell==1,"Chaikin Money Flow\n","") + writeif(macdSell==1,"MACD signal cross\n","")+writeif(somme2==0,"None\n","");
"";
"";
"";

:-) Scuba
Privateer
tradeshark [at] online.de
2001-09-04 16:27:46
Hi,

tried to test this interesting approach, but get only a bunch of "unknown identifier" messages.

Sorry
Tomasz Janeczko
tj --at-- amibroker.com
2003-08-08 06:45:04
This code uses obsolete function Stoch()
that should be replaced with StochK()
jq
jq1688n [at] hotmail.com
2004-11-05 19:21:46
please tje code not rum here, and not have nothing mistake menssage
naren
nnainani [at] indiatimes.com
2004-11-13 02:04:38
This formula gives error even after doing StochK(14) when applied after copying in the custom indicator.Can someone upload or send correct formula.Regards,naren.
Hans

2004-11-13 16:41:09
You can have better layout for explore while replacing code for colums with following:

/* Exploration Columns for Sorting */

AddColumn(V,"Volume",1.0);
AddColumn(VolumeIdx,"Vol Idx",1.1);
AddColumn(somme,"Buy sign",1.2);
AddColumn(somme2,"Sell sign",1.2);
AddColumn(IIf(PL, 66,01 ),"Piercing",formatChar, colorGreen );
AddColumn(IIf(MDS, 66, IIf(EDS, 83,01 )),"Doji Star",formatChar, IIf(eds,colorRed,colorGreen) );
AddColumn(IIf(BLE, 66, IIf(BRE, 83,01 )),"Engulfing",formatChar, IIf(bre,colorRed,colorGreen) );
AddColumn(IIf(Ham, 66,01 ),"Hammer",formatChar, colorGreen );
AddColumn(IIf(DCC, 83,01 ),"Dark Cloud Cover",formatChar, colorRed);
AddColumn( IIf(tdreiBuy, 66, IIf(tdreiSell, 83,01 )), "TDREI", formatChar, IIf(tdreisell,colorRed,colorGreen) );
AddColumn( IIf(kupbuy, 66, IIf(kupSell, 83,01 )), "Keltner", formatChar, IIf(kupsell,colorRed,colorGreen) );
AddColumn( IIf(rsiBuy, 66, IIf(rsiSell, 83,01 )), "RSI", formatChar, IIf(rsisell,colorRed,colorGreen) );
AddColumn( IIf(mfiBuy, 66, IIf(mfiSell, 83,01 )), "MFI", formatChar, IIf(mfisell,colorRed,colorGreen) );
AddColumn( IIf(sto2Buy, 66, IIf(sto2Sell, 83,01 )), "Stoc", formatChar, IIf(sto2sell,colorRed,colorGreen) );
AddColumn( IIf(divBuy, 66, IIf(divSell, 83,01 )), "%R", formatChar, IIf(divsell,colorRed,colorGreen) );
AddColumn( IIf(kstBuy, 66, IIf(kstSell, 83,01 )), "KST", formatChar, IIf(kstsell,colorRed,colorGreen) );
AddColumn( IIf(Copbuy, 66,01 ),"Coppock",formatChar, colorGreen );
AddColumn( IIf(smashBuy, 66,IIf(smashSell, 83,01 )), "Smash day", formatChar, IIf(smashsell,colorRed,colorGreen) );
AddColumn( IIf(chkBuy, 66, IIf(chkSell, 83,01 )), "Chaikin Money", formatChar, IIf(chksell,colorRed,colorGreen) );
AddColumn( IIf(macdBuy, 66, IIf(macdSell, 83,01 )), "MACD", formatChar, IIf(macdsell,colorRed,colorGreen) );

ronny
ronny38000 [at] hotmail.com
2005-07-08 07:39:08
i get syntax error ?
as follows


Line 115, Column 25:
lookback = 14;

buyrange = 30;

sellrange = 70;

stochKworkaround = STOCH(
------------------------^

Error 23.
Syntax error
steve
steve.tech [at] westnet.com.au
2005-07-25 06:51:09
I also get syntax errors. has anyone got the working code
Many thanks Steve
Magnus
z94joma [at] hotmail.com
2005-07-27 17:09:46
I should say STOCHK

See Tomasz above.
Sylwester Szady
sszady [at] own.pl
2005-11-01 14:23:45
/* to use as indicator */

Plot( somme, "buy", colorGreen, styleLine|styleOwnScale );
Plot( somme2, "sell", colorRed, styleLine|styleOwnScale );
Plot( Filter, "deal", colorBlue, styleLine|styleOwnScale );

Sylwester Szady
sszady [at] own.pl
2005-11-01 14:40:10
/* and... /*

Plot( Close, "Price", colorBlack, styleCandle|styleOwnScale );
Plot( Volume, "Volume", colorSkyblue, styleHistogram|styleThick|styleOwnScale );
aziz
lr88rl [at] hotmail.com
2005-12-06 13:23:16
.


the formula not work it gives syntax error, will tou please upload the right formula .


thanks alot


.
aziz
lr88rl [at] hotmail.com
2005-12-06 13:25:15
The formula not work ,it gives syntax error, will you please upload the right formula .


thanks alot
wbs
wbs331b [at] charter.net
2006-01-04 22:14:15
"Weighted buy indicator:" returns text "{EMPTY}" for OTC stocks. How can this be fixed?

Thanks.
savio
softnews2003 [at] yahoo.com
2006-02-10 11:46:35
The formula not work; any Solution ??
bigbrooster
hydrium [at] gmail.com
2006-03-26 08:19:16
The solution to all syntax errors re: this formula were posted by:

Tomasz Janeczko on
2003-08-08 06:45:04

However the formula doesnt work anyway!
rob
chapman49682 [at] yahoo.com
2006-04-19 09:58:58
Very useful concept. Once the StochK() mod is made, and a few comment line syntax errors are fixed, the signals generated in SCAN are quite reliable. This code can be easily modified with one's own personal favorites. Haven't got the EXPLORE running just yet, but when i do, I will post the code.
rob
chapman49682 [at] yahoo.com
2006-04-19 10:14:35
//this code works. It has some of the
//modifications suggested above.
//You might have to comment out
// some lines (start them with // )
//which generate syntax errors due to line
// wraparound.


/*Against all odds (draft). Written by Thierry HUITEL o-l---} */
/* based on Jim Varney's work-- CANDLESTOCHASTICS-- */
/*and all the amibroker group :-) */

/*
This Exploration is a scan for 24 different buy or sell signals.
The odds are 1 of 6 to get a TWO with a dice. If you try 1000 times, the odds
are more than 99%.
The aim of the exploration is to find days when many bullish or bearish signs
are triggered at the same time. If 5 indicators give a buy advice, it is more
reliable than one.
I invite everybody to add your own systems to these ones, to improve the
reliability. And experimented technical analysts could give advices to avoid
the trap of using several different indicators all working off the same input
data.

Vol Index: this column is the ratio of today's volume to the 14-day average
volume.
This column should be sorted Descending. The best signals are occur when
VolIndex is at least 2 or higher.

PCL[up]: Piercing Line, "up" signifies Bullish.
MDS[up]: Morning Doji Star
BLE[up]: Bullish Engulfing
HAM[up]: Hammer
BRE[dn]: Bearish Engulfing, "dn" signifies Bearish.
DCC[dn]: Dark Cloud Cover
EDS[dn]: Evening Doji Star
TDREI[up] & [dn]: Tom DeMark's Range Expansion Index
KUP[up] & [dn]: Keltner Bands -DIMITRIS TSOKAKIS
RSI[up] & [dn]: Relative Strength Index 14 periods
MFI[up] & [dn]: Money Flow Index
ST2[up] & [dn]: Stochastic Slow - Donald Dalley
DIV[up] & [dn]: % R divergence -DIMITRIS TSOKAKIS
KST[up] & [dn]: MARTIN PRING'S KST MOMENTUM SYSTEM -TJ
COP[up]: Coppock Curve TJ
SMH[up] & [dn]: smash day pattern. DIMA
CHK[up] & [dn]: Chaikin Money Flow. Thierry Huitel

A "1" in the column signifies TRUE, a "0" indicates no signal.
------------------------------------------------------------------*/
"Commentaires sur " + Name() +" pour le "+Date();

/* Minimum Price and 14 day Avg Volume Values for Filter */
minPrice = 3; //change as needed
minVol = 50000; //change as needed

VolAvg = MA( V, 14 );
VolumeIdx = V / VolAvg;
AvgRange = Sum( abs(O-C),15 )/15;

/* Candle Codes */
White = IIf((C>O) AND ((C-O)>=0.8*(H-L)),1,0) AND (C-O)>AvgRange;
Black = IIf((C<O) AND ((O-C)>=0.8*(H-L)),1,0) AND (O-C)>AvgRange;
Doji = IIf(abs(O-C)<=0.1*(H-L),1,0);

/* Dark Cloud Cover [Bear] */
DCC = IIf(Ref(White, -1) AND Black AND C<=Ref(((H+L)/2),-1)
AND O>Ref(C,-1), 1,0);

/* Piercing Line [Bull] */
PL = IIf(Ref(Black, -1) AND White AND C>=Ref(((H+L)/2),-1)
AND O<Ref(C,-1), 1,0);

/* Evening Doji Star [Bear] */
EDS = IIf(Ref(White, -2) AND Ref(Doji, -1) AND Black AND
C<=Ref(((H+L)/2),-2), 1,0);

/* Morning Doji Star [Bull] */
MDS = IIf(Ref(Black, -2) AND Ref(Doji, -1) AND White AND
C>=Ref(((H+L)/2),-2), 1,0);

/* Hammer [Bull] */
HAM = IIf( (H-L > 1.5*AvgRange) AND (C > (H+L)/2) AND (O > C) AND
(VolumeIdx > 2), 1, 0);

/* Bearish Engulfing */
BRE = IIf(Black AND Ref(White, -1) AND (C < Ref(O, -1)) AND (O > Ref(C, -1)),
1,0);

/* Bullish Engulfing */
BLE = IIf(White AND Ref(Black, -1) AND (C > Ref(O,-1)) AND (O < Ref(C,-1)),
1,0);


/* Stochastics 14-4 */

ss = MA(StochK(14),4);
StochBuy = IIf(ss<=20, 1, 0);
StochSell = IIf(ss>=80, 1, 0);

/* TDREI */
HighMom = H - Ref( H, -2 );
LowMom = L - Ref( L, -2 );
Cond1 = ( H >= Ref( L,-5) OR H >= Ref( L, -6 ) );
Cond2 = ( Ref( H, -2 ) >= Ref( C, -7 ) OR Ref( H, -2 ) >= Ref( C, -8 ) );
Cond3 = ( L <= Ref( H, -5 ) OR L <= Ref( H, -6) );
Cond4 = ( Ref( L, -2 ) <= Ref( C, -7 ) OR Ref( L, -2 ) <= Ref( C, -8 ) );
Cond = ( Cond1 OR Cond2 ) AND ( Cond3 OR Cond4 );
Num = IIf( Cond, HighMom + LowMom, 0 );
Den = abs( HighMom ) + abs( LowMom );
TDREI = 100 * Sum( Num, 5 )/Sum( Den, 5 ) ;
tdreiBuy = IIf(TDREI<=-95, 1, 0);
tdreiSell = IIf(TDREI>=95, 1, 0);

/* KUP */
KUP=EMA((H+L+C)/3,10)+EMA(H-L,10);
KDOWN=EMA((H+L+C)/3,10)-EMA(H-L,10);
kupBuy = IIf(Cross(C,KDOWN), 1, 0);
kupSell = IIf(Cross(KUP,C), 1, 0);

/*RSI*/
vrsi= RSI(14);
rsiBuy = IIf(Cross(vrsi,30), 1, 0);
rsiSell = IIf(Cross(70,vrsi), 1, 0);

/*MFI*/
mfiBuy = IIf(Cross(MFI(),30), 1, 0);
mfiSell = IIf(Cross(70,MFI()), 1, 0);

/*STO2*/
lookback = 14;
buyrange = 30;
sellrange = 70;
stochKworkaround = StochK(14);
stochDworkaround = EMA( StochK(14), 5);
sto2Buy = IIf(StochK(14) < buyrange AND Cross(stochKworkaround,
stochDworkaround), 1, 0);
sto2Sell = IIf(StochK(14) > sellrange AND Cross(stochDworkaround,
stochKworkaround), 1, 0);

/*MACD SIGNAL CROSS*/
macdBuy = Cross(MACD(), EMA(MACD(),9));
macdSell = Cross(EMA(MACD(),9), MACD());


/* %R, ema 9 and divergences */

R=-100*((HHV(High,14)-Close))/(HHV(High,14)-LLV(Low,14));
DIVR=(R-Ref(R,-1))*(C-Ref(C,-1));
DIVB=IIf((DIVR<0) AND (R-Ref(R,-1))>0 AND (Ref(R,-1)<-90),-100,0);
DIVB1=IIf((DIVR<0) AND (R-Ref(R,-1))>0 AND (Ref(R,-1)<-90),-80,0);
DIVS=IIf((DIVR<0) AND (R-Ref(R,-1))<0 AND (Ref(R,-1)>-10),-20,0);
divBuy = IIf(DIVB==-100, 1, 0);
divSell = IIf(DIVS==-20, 1, 0);

/*KST*/

KST = (MA(ROC(Close,10),10) * 1) +
(MA(ROC(Close,15),10) * 2) +
(MA(ROC(Close,20),10) * 3) +
(MA(ROC(Close,30),15) * 4);
kstBuy = IIf(Cross(KST , MA(KST, 109)), 1, 0);
kstSell = IIf(Cross(MA(KST , 120), KST), 1, 0);

/*COP*/
copBuy = IIf((EMA( ROC( MA( C, 22 ), 250 ), 150 ) / 100) < 0, 1, 0);

/*SMASH*/
numDays = 3; // Consider smash Day if closed above/below previous numDays highs/lows
closeInDayRangePct = 0.25; // Smash day close should be in the high/low %% of the Day range
smashDayDown = Close < LLV (Ref (Low, -1), numDays) AND Close < Open AND Close
< (Low + closeInDayRangePct * (High - Low));
smashDayUp = Close > HHV (Ref (High, -1), numDays) AND Close > Open AND Close >
(High - closeInDayRangePct * (High - Low));
// Enter in the direction opposite to the smash day if the very next day price moves opposite the smash Day.
smashBuy = IIf(Ref (smashDayDown, -1) AND High > Ref (High, -1), 1, 0);
smashSell = IIf(Ref (smashDayUp, -1) AND Low < Ref (Low, -1), 1, 0);

/*CHAIKIN MONEY FLOW*/
ICH = Sum(((( C-L )-( H-C )) / ( H-L ))*V, 21 ) / Sum(V,21);
LCH = LLV( ICH, 255 );
top = (LCH/2);
chkBuy = Cross (ICH, top);
chkSell = Cross (0, ICH);

/*number of buy signals --- give weight to your favorite ones with a
coefficient. */
somme= PL + MDS + HAM + BLE + tdreiBuy + kupBuy + rsiBuy + (2*mfibuy) + sto2Buy
+ (2*divBuy) + kstBuy + copBuy + (2*smashBuy) + chkBuy;

/*number of sell signals. */
somme2 = BRE + DCC + EDS + tdreiSell + kupSell + rsiSell + mfiSell + sto2Sell +
divSell + divSell + kstSell + smashSell + chkSell;

/*Guru comment*/
"number of buy indicators triggered: " + WriteVal (somme) ;
"Aujourd'hui, les signaux haussiers suivants ont été déclenchés: ";

/* Exploration Columns for Sorting */

/* Exploration Columns for Sorting */
AddColumn(V,"Volume",1.0);
AddColumn(VolumeIdx,"Vol Idx",1.1);
AddColumn(somme,"Buy sign",1.2);
AddColumn(somme2,"Sell sign",1.2);
AddColumn(IIf(PL, 66,01 ),"Piercing",formatChar, colorGreen );
AddColumn(IIf(MDS, 66, IIf(EDS, 83,01 )),"Doji Star",formatChar, IIf(eds,colorRed,colorGreen) );
AddColumn(IIf(BLE, 66, IIf(BRE, 83,01 )),"Engulfing",formatChar, IIf(bre,colorRed,colorGreen) );
AddColumn(IIf(Ham, 66,01 ),"Hammer",formatChar, colorGreen );
AddColumn(IIf(DCC, 83,01 ),"Dark Cloud Cover",formatChar, colorRed);
AddColumn( IIf(tdreiBuy, 66, IIf(tdreiSell, 83,01 )), "TDREI", formatChar, IIf(tdreisell,colorRed,colorGreen) );
AddColumn( IIf(kupbuy, 66, IIf(kupSell, 83,01 )), "Keltner", formatChar, IIf(kupsell,colorRed,colorGreen) );
AddColumn( IIf(rsiBuy, 66, IIf(rsiSell, 83,01 )), "RSI", formatChar, IIf(rsisell,colorRed,colorGreen) );
AddColumn( IIf(mfiBuy, 66, IIf(mfiSell, 83,01 )), "MFI", formatChar, IIf(mfisell,colorRed,colorGreen) );
AddColumn( IIf(sto2Buy, 66, IIf(sto2Sell, 83,01 )), "Stoc", formatChar, IIf(sto2sell,colorRed,colorGreen) );
AddColumn( IIf(divBuy, 66, IIf(divSell, 83,01 )), "%R", formatChar, IIf(divsell,colorRed,colorGreen) );
AddColumn( IIf(kstBuy, 66, IIf(kstSell, 83,01 )), "KST", formatChar, IIf(kstsell,colorRed,colorGreen) );
AddColumn( IIf(Copbuy, 66,01 ),"Coppock",formatChar, colorGreen );
AddColumn( IIf(smashBuy, 66,IIf(smashSell, 83,01 )), "Smash day", formatChar, IIf(smashsell,colorRed,colorGreen) );
AddColumn( IIf(chkBuy, 66, IIf(chkSell, 83,01 )), "Chaikin Money", formatChar, IIf(chksell,colorRed,colorGreen) );
AddColumn( IIf(macdBuy, 66, IIf(macdSell, 83,01 )), "MACD", formatChar, IIf(macdsell,colorRed,colorGreen) );



/* Filter */
/*the highest % for somme gives the most reliable buy signal*/
Filter = somme>=6 AND VolumeIdx>=2;
/*Filter = ((C > minPrice) AND (VolAvg >= minVol)) AND (StochBuy AND (PL or MDS
or BLE or HAM)) OR (StochSell AND (BRE or DCC or EDS));*/


/* Buy and Sell */
/* set your own requirements: how many indicators triggered at the same time
*/
Buy = somme>=6;
Sell = somme2>=3;
WriteVal (somme);
rob
rob49682 [at] hotmail.com
2006-04-21 19:39:15
PS - As the author indicated, this is intended as (and works best as) an Exploration. It is not a tradable system, but instead serves as a source of good Buy / Sell Short candidates.
rob
chapman49682 [at] yahoo.com
2006-04-22 00:47:57
Sorry - found a couple gof litches, and added Sell Threshold and Buy Threshold parameters, and enhanced the Buy/Sell "Explore" output with colored signals.

New code follows.
rob
chapman49682 [at] yahoo.com
2006-04-22 00:48:37
/*Against all odds (draft). Written by Thierry HUITEL o-l---} */
/* based on Jim Varney's work-- CANDLESTOCHASTICS-- */
/*and all the amibroker group :-) */

/*
This Exploration is a scan for 24 different buy or sell signals.
The odds are 1 of 6 to get a TWO with a dice. If you try 1000 times, the odds
are more than 99%.
The aim of the exploration is to find days when many bullish or bearish signs
are triggered at the same time. If 5 indicators give a buy advice, it is more
reliable than one.
I invite everybody to add your own systems to these ones, to improve the
reliability. And experimented technical analysts could give advices to avoid
the trap of using several different indicators all working off the same input
data.

Vol Index: this column is the ratio of today's volume to the 14-day average
volume.
This column should be sorted Descending. The best signals are occur when
VolIndex is at least 2 or higher.

PCL[up]: Piercing Line, "up" signifies Bullish.
MDS[up]: Morning Doji Star
BLE[up]: Bullish Engulfing
HAM[up]: Hammer
BRE[dn]: Bearish Engulfing, "dn" signifies Bearish.
DCC[dn]: Dark Cloud Cover
EDS[dn]: Evening Doji Star
TDREI[up] & [dn]: Tom DeMark's Range Expansion Index
KUP[up] & [dn]: Keltner Bands -DIMITRIS TSOKAKIS
RSI[up] & [dn]: Relative Strength Index 14 periods
MFI[up] & [dn]: Money Flow Index
ST2[up] & [dn]: Stochastic Slow - Donald Dalley
DIV[up] & [dn]: % R divergence -DIMITRIS TSOKAKIS
KST[up] & [dn]: MARTIN PRING'S KST MOMENTUM SYSTEM -TJ
COP[up]: Coppock Curve TJ
SMH[up] & [dn]: smash day pattern. DIMA
CHK[up] & [dn]: Chaikin Money Flow. Thierry Huitel

A "1" in the column signifies TRUE, a "0" indicates no signal.
------------------------------------------------------------------*/
"Commentaires sur " + Name() +" pour le "+Date();

/* Minimum Price and 14 day Avg Volume Values for Filter */
minPrice = 3; //change as needed
minVol = 50000; //change as needed

VolAvg = MA( V, 14 );
VolumeIdx = V / VolAvg;
AvgRange = Sum( abs(O-C),15 )/15;

/* Candle Codes */
White = IIf((C>O) AND ((C-O)>=0.8*(H-L)),1,0) AND (C-O)>AvgRange;
Black = IIf((C<O) AND ((O-C)>=0.8*(H-L)),1,0) AND (O-C)>AvgRange;
Doji = IIf(abs(O-C)<=0.1*(H-L),1,0);

/* Dark Cloud Cover [Bear] */
DCC = IIf(Ref(White, -1) AND Black AND C<=Ref(((H+L)/2),-1)
AND O>Ref(C,-1), 1,0);

/* Piercing Line [Bull] */
PL = IIf(Ref(Black, -1) AND White AND C>=Ref(((H+L)/2),-1)
AND O<Ref(C,-1), 1,0);

/* Evening Doji Star [Bear] */
EDS = IIf(Ref(White, -2) AND Ref(Doji, -1) AND Black AND
C<=Ref(((H+L)/2),-2), 1,0);

/* Morning Doji Star [Bull] */
MDS = IIf(Ref(Black, -2) AND Ref(Doji, -1) AND White AND
C>=Ref(((H+L)/2),-2), 1,0);

/* Hammer [Bull] */
HAM = IIf( (H-L > 1.5*AvgRange) AND (C > (H+L)/2) AND (O > C) AND
(VolumeIdx > 2), 1, 0);

/* Bearish Engulfing */
BRE = IIf(Black AND Ref(White, -1) AND (C < Ref(O, -1)) AND (O > Ref(C, -1)),
1,0);

/* Bullish Engulfing */
BLE = IIf(White AND Ref(Black, -1) AND (C > Ref(O,-1)) AND (O < Ref(C,-1)),
1,0);


/* Stochastics 14-4 */

ss = MA(StochK(14),4);
StochBuy = IIf(ss<=20, 1, 0);
StochSell = IIf(ss>=80, 1, 0);

/* TDREI */
HighMom = H - Ref( H, -2 );
LowMom = L - Ref( L, -2 );
Cond1 = ( H >= Ref( L,-5) OR H >= Ref( L, -6 ) );
Cond2 = ( Ref( H, -2 ) >= Ref( C, -7 ) OR Ref( H, -2 ) >= Ref( C, -8 ) );
Cond3 = ( L <= Ref( H, -5 ) OR L <= Ref( H, -6) );
Cond4 = ( Ref( L, -2 ) <= Ref( C, -7 ) OR Ref( L, -2 ) <= Ref( C, -8 ) );
Cond = ( Cond1 OR Cond2 ) AND ( Cond3 OR Cond4 );
Num = IIf( Cond, HighMom + LowMom, 0 );
Den = abs( HighMom ) + abs( LowMom );
TDREI = 100 * Sum( Num, 5 )/Sum( Den, 5 ) ;
tdreiBuy = IIf(TDREI<=-95, 1, 0);
tdreiSell = IIf(TDREI>=95, 1, 0);

/* KUP */
KUP=EMA((H+L+C)/3,10)+EMA(H-L,10);
KDOWN=EMA((H+L+C)/3,10)-EMA(H-L,10);
kupBuy = IIf(Cross(C,KDOWN), 1, 0);
kupSell = IIf(Cross(KUP,C), 1, 0);

/*RSI*/
vrsi= RSI(14);
rsiBuy = IIf(Cross(vrsi,30), 1, 0);
rsiSell = IIf(Cross(70,vrsi), 1, 0);

/*MFI*/
mfiBuy = IIf(Cross(MFI(),30), 1, 0);
mfiSell = IIf(Cross(70,MFI()), 1, 0);

/*STO2*/
lookback = 14;
buyrange = 30;
sellrange = 70;
stochKworkaround = StochK(14);
stochDworkaround = EMA( StochK(14), 5);
sto2Buy = IIf(StochK(14) < buyrange AND Cross(stochKworkaround,
stochDworkaround), 1, 0);
sto2Sell = IIf(StochK(14) > sellrange AND Cross(stochDworkaround,
stochKworkaround), 1, 0);

/*MACD SIGNAL CROSS*/
macdBuy = Cross(MACD(), EMA(MACD(),9));
macdSell = Cross(EMA(MACD(),9), MACD());


/* %R, ema 9 and divergences */

R=-100*((HHV(High,14)-Close))/(HHV(High,14)-LLV(Low,14));
DIVR=(R-Ref(R,-1))*(C-Ref(C,-1));
DIVB=IIf((DIVR<0) AND (R-Ref(R,-1))>0 AND (Ref(R,-1)<-90),-100,0);
DIVB1=IIf((DIVR<0) AND (R-Ref(R,-1))>0 AND (Ref(R,-1)<-90),-80,0);
DIVS=IIf((DIVR<0) AND (R-Ref(R,-1))<0 AND (Ref(R,-1)>-10),-20,0);
divBuy = IIf(DIVB==-100, 1, 0);
divSell = IIf(DIVS==-20, 1, 0);

/*KST*/

KST = (MA(ROC(Close,10),10) * 1) +
(MA(ROC(Close,15),10) * 2) +
(MA(ROC(Close,20),10) * 3) +
(MA(ROC(Close,30),15) * 4);
kstBuy = IIf(Cross(KST , MA(KST, 109)), 1, 0);
kstSell = IIf(Cross(MA(KST , 120), KST), 1, 0);

/*COP*/
copBuy = IIf((EMA( ROC( MA( C, 22 ), 250 ), 150 ) / 100) < 0, 1, 0);

/*SMASH*/
numDays = 3; // Consider smash Day if closed above/below previous numDays highs/lows
closeInDayRangePct = 0.25; // Smash day close should be in the high/low %% of the Day range
smashDayDown = Close < LLV (Ref (Low, -1), numDays) AND Close < Open AND Close
< (Low + closeInDayRangePct * (High - Low));
smashDayUp = Close > HHV (Ref (High, -1), numDays) AND Close > Open AND Close >
(High - closeInDayRangePct * (High - Low));
// Enter in the direction opposite to the smash day if the very next day price moves opposite the smash Day.
smashBuy = IIf(Ref (smashDayDown, -1) AND High > Ref (High, -1), 1, 0);
smashSell = IIf(Ref (smashDayUp, -1) AND Low < Ref (Low, -1), 1, 0);

/*CHAIKIN MONEY FLOW*/
ICH = Sum(((( C-L )-( H-C )) / ( H-L ))*V, 21 ) / Sum(V,21);
LCH = LLV( ICH, 255 );
top = (LCH/2);
chkBuy = Cross (ICH, top);
chkSell = Cross (0, ICH);

/*number of buy signals --- give weight to your favorite ones with a
coefficient. */
somme= PL + MDS + HAM + BLE + tdreiBuy + kupBuy + rsiBuy + (2*mfibuy) + sto2Buy
+ (2*divBuy) + kstBuy + copBuy + (2*smashBuy) + chkBuy;

/*number of sell signals. */
somme2 = BRE + DCC + EDS + tdreiSell + kupSell + rsiSell + mfiSell + sto2Sell +
divSell + divSell + kstSell + smashSell + chkSell;

/*Guru comment*/
"number of buy indicators triggered: " + WriteVal (somme) ;
"Aujourd'hui, les signaux haussiers suivants ont été déclenchés: ";

/* Buy / sell thresholds */
BuyThreshold = Param( "BuyThreshold",6,0,10,1);
//BuyThreshold = Optimize( "BuyThreshold",6,0,10,1);
//BuyThreshold = 6;

SellThreshold = Param( "SellThreshold",5,0,10,1);
//SellThreshold = Optimize( "SellThreshold",5,0,10,1);
//SellThreshold = 5;

/* Exploration Columns for Sorting */
AddColumn(V,"Volume",1.0);
AddColumn(VolumeIdx,"Vol Idx",1.1);
AddColumn(somme,"Buy sign",1.2,colorDefault,IIf(somme < BuyThreshold,colorDefault,colorGreen) );
AddColumn(somme2,"Sell sign",1.2,colorDefault,IIf(somme2 < SellThreshold,colorDefault,colorRed) );
AddColumn(IIf(PL, 66,01 ),"Piercing",formatChar, colorGreen );
AddColumn(IIf(MDS, 66, IIf(EDS, 83,01 )),"Doji Star",formatChar, IIf(eds,colorRed,colorGreen) );
AddColumn(IIf(BLE, 66, IIf(BRE, 83,01 )),"Engulfing",formatChar, IIf(bre,colorRed,colorGreen) );
AddColumn(IIf(Ham, 66,01 ),"Hammer",formatChar, colorGreen );
AddColumn(IIf(DCC, 83,01 ),"Dark Cloud Cover",formatChar, colorRed);
AddColumn( IIf(tdreiBuy, 66, IIf(tdreiSell, 83,01 )), "TDREI", formatChar, IIf(tdreisell,colorRed,colorGreen) );
AddColumn( IIf(kupbuy, 66, IIf(kupSell, 83,01 )), "Keltner", formatChar, IIf(kupsell,colorRed,colorGreen) );
AddColumn( IIf(rsiBuy, 66, IIf(rsiSell, 83,01 )), "RSI", formatChar, IIf(rsisell,colorRed,colorGreen) );
AddColumn( IIf(mfiBuy, 66, IIf(mfiSell, 83,01 )), "MFI", formatChar, IIf(mfisell,colorRed,colorGreen) );
AddColumn( IIf(sto2Buy, 66, IIf(sto2Sell, 83,01 )), "Stoc", formatChar, IIf(sto2sell,colorRed,colorGreen) );
AddColumn( IIf(divBuy, 66, IIf(divSell, 83,01 )), "%R", formatChar, IIf(divsell,colorRed,colorGreen) );
AddColumn( IIf(kstBuy, 66, IIf(kstSell, 83,01 )), "KST", formatChar, IIf(kstsell,colorRed,colorGreen) );
AddColumn( IIf(Copbuy, 66,01 ),"Coppock",formatChar, colorGreen );
AddColumn( IIf(smashBuy, 66,IIf(smashSell, 83,01 )), "Smash day", formatChar, IIf(smashsell,colorRed,colorGreen) );
AddColumn( IIf(chkBuy, 66, IIf(chkSell, 83,01 )), "Chaikin Money", formatChar, IIf(chksell,colorRed,colorGreen) );
AddColumn( IIf(macdBuy, 66, IIf(macdSell, 83,01 )), "MACD", formatChar, IIf(macdsell,colorRed,colorGreen) );



/* Filter */
/*the highest % for somme gives the most reliable buy signal*/
Filter = (somme >= BuyThreshold AND VolumeIdx>=2) OR (somme2 >= SellThreshold AND VolumeIdx>=2) ;
/*Filter = ((C > minPrice) AND (VolAvg >= minVol)) AND (StochBuy AND (PL or MDS
or BLE or HAM)) OR (StochSell AND (BRE or DCC or EDS));*/


/* Buy and Sell */
Buy = somme>=BuyThreshold; //6
Sell = somme2>=SellThreshold; //3
WriteVal (somme);
dhiraj sood
dhirajsud [at] gmail.com
2007-02-26 11:07:04
hello excellent work good hard working but this formula is not reliabel. whean we cheq with this formula result is less than 20% accurate dhiraj
Dan
arrangingfire25 [at] hotmail.com
2009-05-30 22:22:35
Good Work Rob, Many Thanks.


About | Privacy | Terms of Use | Contact information
Copyright © 2001 AMIBROKER.COM