[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Combining Candlestick Bullish Reversals with Money Flow - a Scan



PureBytes Links

Trading Reference Links

The code below is a simple adaptation of Jim 
Varney's "Candlestochastics" in the AFL library.  Basically, it 
combines candlestick bullish reversal signals with a money flow 
indicator (FVE by Markos Katsanos).  Use the code only as a scan 
for 'Long' buy signals.  Even though Jim's exploration has bearish 
reversals; the money flow doesn't work that well in reverse (because 
stocks can go up on sheer momentum even though there is a divergence 
and money flow trends down).  The 'Buy' is triggered when there is a 
divergence between stock price and the money flow - with money flow 
trending upward at a sharp angle while the price is forming a base - 
AND - when one of the 4 candlestick bullish reversal signals is 
given.  Don't pay too much attention to the 'Sell' signal (in case 
you are thinking of a backtest) because I just slapped some 'Sell' 
signal together in order to run a scan/exploration.
Can this code be improved?  Yes - add more bullish reversal signals 
to the code (there are at least 10 more).  That way you will get more 
signals when you scan.  Also, you can play around with a 
better 'Sell' signal (if you are thinking of backtesting)

********************************************************

/* -- CANDLESTOCHASTICS 	-- */
/* -- Written by Jim Varney 	-- */
/*
Adapted for FVE indicator - Long Only.  This Exploration combines FVE 
with a scan for 4 different candlestick bullish reversal patterns 

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

A "1" in the column signifies TRUE, a "0" indicates no signal.

------------------------------------------------------------------*/

/* Minimum Price and 14 day Avg Volume Values for Filter */
minPrice = 1;     //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);

// Money Flow Indicator - FVE by Markos Katsanos 

Period = Param("Period for FVE", 22, 5, 80, 1 );
Coeff = Param("Coeff for Cutoff", 0.1, 0, 2, 0.01 );

intra=log(H)-log(L);
Vintra = StDev(intra, period );
inter = log(Avg)-log(Ref(Avg,-1));
Vinter = StDev(inter,period);
Cutoff = Coeff * (Vinter+Vintra)*C;
MF = C- (H+L)/2 + Avg - Ref( Avg, -1 );
VC = IIf( MF > Cutoff, V,
IIf( MF < -Cutoff, -V, 0 ));
FVE = 100 * Sum( VC, Period )/(MA( V, Period ) * Period ); 


RAD_TO_DEG = 180/3.1415926; // radians to degrees
LinRegAngleFVE = RAD_TO_DEG * atan( LinRegSlope( FVE, 22 ) ); // 
calculates angle of money flow indicator

// Buy Rules

FVEBuy = FVE > -10 AND FVE < 10 AND
LinRegAngleFVE > 30 AND
FVE > EMA( FVE, 5 ) AND EMA(FVE, 5) > EMA(FVE, 22) AND
LinRegSlope( C, 30 ) < Ref(C, -30 ) *0.6/100 AND
LinRegSlope( C, 30 ) > -Ref( C, -30 ) * 0.3/100;

// Sell Rules

FVESell = LinRegAngleFVE < -20 OR Close < (0.72 * HHV (Close, 2));


/* Exploration Columns for Sorting */

NumColumns = 9;

Column0 = V;
Column1 = VolumeIdx;
Column2 = PL;
Column3 = MDS;
Column4 = BLE;
Column5 = HAM;
Column6 = BRE;
Column7 = DCC;
Column8 = EDS;

Column0Name = "Volume"; 
Column1Name = "Vol Idx";
Column2Name = "PCL[up]";
Column3Name = "MDS[up]";
Column4Name = "BLE[up]";
Column5Name = "HAM[up]";
Column6Name = "BRE[dn]";
Column7Name = "DCC[dn]";
Column8Name = "EDS[dn]";

Column0Format = 1.0;
Column1Format = 1.1;
Column2Format = 1.0;
Column3Format = 1.0;
Column4Format = 1.0;
Column5Format = 1.0;
Column6Format = 1.0;
Column7Format = 1.0;
Column8Format = 1.0;


/* Filter */

Filter = ((C > minPrice) AND (VolAvg >= minVol)) AND (FVEBuy AND (PL 
OR MDS OR BLE OR HAM));


/* Buy and Sell */

Buy = IIf(FVEBuy AND (PL + MDS + HAM + BLE > 0), 1, 0);
Sell = FVESell;






Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/