Amibroker Explorations and Trading Systems

TradeOptions

Well-Known Member
#1
I will be posting a few Amibroker Explorations and Trading Systems in this thread. If you have any interesting ones as well then please feel free to post. All credit goes to the original creators of these AFL’s.

Thanks and regards

PS: I have got these from internet, if there is any copyright issue with any of these then moderators can please delete that post.

Please use Code(#) for pasting codes.
Those who do not know how to use Code(#) in their posts, please see this link –
http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-233.html#post1016826
 

TradeOptions

Well-Known Member
#2
EOD Trade Explorer

This exploration will show the following columns in the output -

Ticker
Date/Time
Stochs
Appel's
T3 RSI
T3 Price
MACD-H
MACD-S
BBand
Close
ROC Price
Volume
ROC Volume
Acc/Dist
WAD
ADX-14
RSI-14
Price Volume Breakout
52-Week
Long Term
Mid Term
Short Term

Code:
//Tillson's Part (RSI Smoothing)

#include <T3_include.AFL>;
TillsonBuy = Cross (t3(RSI(9),3), t3(RSI(9),5));
TillsonSell =  Cross (t3(RSI(9),5), t3(RSI(9),3));

//Appel's Triple Momentum
x = ROC (C,5);
y = ROC (C,15);
Z = ROC (C,25);
AROC=x+y+z;
ABuy = Cross (t3(AROC,3), t3(AROC,5));
ASell = Cross (t3(AROC,5), t3(AROC,3));


//Price Smoothing
Tillson2Buy = Cross (T3(C,3), T3(C,5));
Tillson2Sell =  Cross (T3(C,5), T3(C,3));

//Stochastics Part
StochBuy = Cross(StochK(14,3), StochD(14,3,3));
StochSell = Cross (StochD(14,3,3), StochK(14,3));

//MCAD Histogram Signal
r1 = Param( "Fast avg", 12, 2, 200, 1 );
r2 = Param( "Slow avg", 26, 2, 200, 1 );
r3 = Param( "Signal avg", 9, 2, 200, 1 );
ml = MACD(r1, r2); 
sl = Signal(r1,r2,r3);
mhist=ml-sl;

//MACD Signal Crosses
MB= Cross (MACD(), Signal());
MS = Cross( Signal(), MACD());
MB_status=	WriteIf(MB, "Bullish", WriteIf(MS, "Bearish", "Neutral"));
MS_Col=IIf(MB, colorGreen, IIf(MS, colorRed, colorLightGrey));

mbuy = Cross(mhist,0) AND V >=50000 OR Cross(MACD(),Signal());
msell = Cross(0,mhist) AND V >=50000 OR Cross(Signal(), MACD());

//Wad: Larry Williams Acc/Distribution Status
TRH = IIf(Ref(C, -1) > H, Ref(C, -1), H);
TRL = IIf(Ref(C, -1) < L, Ref(C, -1), L);
ad = IIf(C > Ref(C, -1), C - TRL, IIf(C < Ref(C, -1), C - TRH, 0));
WAD = Cum(ad);
wu = wad > Ref(wad,-1);
wd = wad < Ref(wad,-1);
wad_status=	WriteIf(wu, "Rising", WriteIf(wd, "Falling", "Neutral"));
wad_Col=IIf(wu, colorGreen, IIf(wd, colorRed, colorLightGrey));

//Bollinger Bands: last bar close at upper or lower band
a1 = C>=BBandTop(C,20,2); 
a2 = C<=BBandBot(C,20,2); 
a3 = a1 OR a2; 
ThisIsLastBar = BarIndex() == LastValue( BarIndex()); 
bb_status=	WriteIf(a1, "BBT", WriteIf(a2, "BBB", "Neutral"));
bb_Col=IIf(a1, colorGreen, IIf(a2, colorRed, colorLightGrey));


//Longterm Bullish or Bearish
Bull = C > MA(C,200);
Bear= C < MA(C,200);
lt_status=	WriteIf(Bull, "Bullish", WriteIf(Bear, "Bearish", "Neutral"));
lt_Col=IIf(Bull, colorGreen, IIf(bear, colorRed, colorLightGrey));

//Midterm Bullish or Bearish
mBull = C > MA(C,50);
mBear= C < MA(C,50);
mt_status=	WriteIf(mBull, "Bullish", WriteIf(mBear, "Bearish", "Neutral"));
mt_Col=IIf(mBull, colorGreen, IIf(mbear, colorRed, colorLightGrey));

//Shortterm Bullish or Bearish
sBull = C > MA(C,15);
sBear= C < MA(C,15);
st_status=	WriteIf(sBull, "Bullish", WriteIf(sBear, "Bearish", "Neutral"));
t_Col=IIf(sBull, colorGreen, IIf(sbear, colorRed, colorLightGrey));

//52 Week New High-New Low
HI = High > Ref(HHV(High,260),-1);
LI = Low < Ref(LLV(Low,260),-1);
W_status=	WriteIf(HI, "High", WriteIf(LI, "Low", "Neutral"));
W_Col=IIf(HI, colorGreen, IIf(LI, colorRed, colorLightGrey));

//Price Volume Breakout: close greater than last close and volume at least twice as much 50-day MA
HIV = C > Ref (C,-1) AND V > (MA(V,50)*2);
LIV = C < Ref (C,-1) AND V < (MA(V,50)*2);
V_status= WriteIf(HIV, "Gainer", WriteIf(LIV, "Loser", "Neutral"));
V_Col=IIf(HIV, colorGreen, IIf(LIV, colorRed, colorLightGrey));

Filter =  TillsonBuy OR TillsonSell OR Tillson2Buy OR Tillson2Sell OR StochBuy OR StochSell 
OR mbuy OR msell OR ABuy OR ASell OR MB OR MS OR wu OR wd OR a3 OR ThisIsLastBar OR bull OR bear OR hiv OR liv OR hi OR li OR mbull OR mbear OR sbull OR sbear;

//Eploration Section
// 1. 3,5-Period T3 Crosses on RSI 

Tbuy_status=	WriteIf(TillsonBuy, "Buy", WriteIf(TillsonSell, "Sell", "No Signal"));

// Set the background color for Signal Status Column
T3_Col=IIf(TillsonBuy, colorGreen, IIf(TillsonSell, colorRed, colorLightGrey));

//StochRSI Exploration

//StochRSIBuy_status=	WriteIf(StochRSIBuy, "Buy", WriteIf(StochRSIBuy, "Sell", "No Signal"));

// Set the background color for Signal Status Column
//StochRSI_Col=IIf(StochRSIBuy, colorGreen, IIf(StochRSIBuy, colorRed, colorLightGrey));

// 2. 3,5-Periods T3 crosses on Price 

T2buy_status=	WriteIf(Tillson2Buy, "Buy", WriteIf(Tillson2Sell, "Sell", "No Signal"));

// Set the background color for Signal Status Column
T32_Col=IIf(Tillson2Buy, colorGreen, IIf(Tillson2Sell, colorRed, colorLightGrey));

// 3. 14-Perios Stochs

Stochbuy_status=	WriteIf(StochBuy, "Buy", WriteIf(StochSell, "Sell", "No Signal"));

// Set the background color for Signal Status Column
Stoch_Col=IIf(StochBuy, colorGreen, IIf(StochSell, colorRed, colorLightGrey));


//4. Daily Acc/Dist Status

acc = AccDist() > Ref (AccDist(),-1);
dist = AccDist() < Ref (AccDist(),-1);

ad_status=	WriteIf(acc, "Accumulation", WriteIf(dist, "Distribution", "Neutral"));

// Set the background color for Signal Status Column
ad_Col=IIf(acc, colorGreen, IIf(dist, colorRed, colorLightGrey));


//5. 14-Period daily ADX levels

up= ADX(14) > Ref( ADX(14),-1);
down= ADX(14) < Ref( ADX(14),-1);

adx_status=	WriteIf(up, "Rising", WriteIf(down, "Falling", "Neutral"));

// Set the background color for Signal Status Column
adx_Col=IIf(up, colorGreen, IIf(down, colorRed, colorLightGrey));

//6.MACD Histogram
mbuy_status=	WriteIf(mbuy, "Bullish", WriteIf(msell, "Bearish", "No Signal"));

// Set the background color for Signal Status Column
m_Col=IIf(mbuy, colorGreen, IIf(msell, colorRed, colorLightGrey));

//7.ATR
ABuy_status=	WriteIf(ABuy, "Buy", WriteIf(ASell, "Sell", "No Signal"));

// Set the background color for Signal Status Column
ATR_Col=IIf(ABuy, colorGreen, IIf(ASell, colorRed, colorLightGrey));

//8. 14-Period daily RSI levels

up= RSI(14) > Ref( RSI(14),-1);
down= RSI(14) < Ref( RSI(14),-1);

rsi_status=	WriteIf(up, "Rising", WriteIf(down, "Falling", "Neutral"));

// Set the background color for Signal Status Column
rsi_Col=IIf(up, colorGreen, IIf(down, colorRed, colorLightGrey));




AddTextColumn(Stochbuy_status, "Stochs", 1, colorWhite, Stoch_Col);
//AddTextColumn(StochRSIBuy_status, "StochRSI", 1, colorWhite, StochRSI_Col);
AddTextColumn(ABuy_status, "Appel's", 1, colorWhite, ATR_Col);
AddTextColumn(Tbuy_status, "T3 RSI", 1, colorWhite, T3_Col);
AddTextColumn(T2buy_status, "T3 Price", 1, colorWhite, T32_Col);
AddTextColumn(mbuy_status, "MACD-H", 1, colorWhite, m_Col);
AddTextColumn(MB_status, "MACD-S", 1, colorWhite, MS_Col);
AddTextColumn(bb_status, "BBand", 1, colorWhite, bb_Col);
//AddTextColumn(adx_status, "ADX", 1, colorWhite, adx_Col);
AddColumn(C, "Close", 1.2, IIf(C > Ref(C,-1), colorGreen, colorRed));
AddColumn(ROC(C,1), "ROC Price", 1.2, IIf(ROC(C,1) > 0, colorGreen, colorRed));
AddColumn(V, "Volume", 1, IIf(V > Ref(V,-1), colorGreen, colorRed));
AddColumn(ROC(V,1), "ROC Volume", 1.2, IIf(ROC(V,1) > 0, colorGreen, colorRed));
AddTextColumn(ad_status, "Acc/Dist", 1, colorWhite, ad_Col);
AddTextColumn(wad_status, "WAD", 1, colorWhite, wad_Col);
AddColumn(ADX(14),"ADX-14",1,IIf(ADX(14) > Ref(ADX(14),-1), colorGreen, colorRed));
//AddTextColumn(rsi_status, "RSI", 1, colorWhite, rsi_Col);
AddColumn(RSI(14),"RSI-14",1, IIf(RSI(14) > Ref(RSI(14),-1), colorGreen, colorRed));
//AddColumn(Ref (C,-1), "Last Close", 1.2);
AddTextColumn(V_status, "Price Volume Breakout", 1, colorWhite, V_Col);
AddTextColumn(W_status, "52-Week", 1, colorWhite, W_Col);
AddTextColumn(lt_status, "Long Term", 1, colorWhite, lt_Col);
AddTextColumn(mt_status, "Mid Term", 1, colorWhite, lt_Col);
AddTextColumn(st_status, "Short Term", 1, colorWhite, lt_Col);
 

TradeOptions

Well-Known Member
#3
Exploration - Against All Odds - scan for 24 different buy or sell signals

This exploration will show the following columns in the output -

Ticker
Date/Time
Volume
Vol Idx
Buy sign
Sell sign
Piercing
Doji Star
Engulfing
Hammer
Dark Cloud Cover
TDREI
Keltner
RSI
MFI
Stoc
%R
KST
Coppock
Smash day
Chaikin Money
MACD



Code:
/*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);
 

TradeOptions

Well-Known Member
#4
Trend exploration with multiple timeframes

This exploration will show the following columns in the output -

Ticker
Date/Time
MA-140
MA-60
MA-8
Overall Trend
Trend Phase
Comments


Code:
//------------------------------------------------------------------------------
//
//  Formula Name:    Trend exploration with multiple timeframes
//  Author/Uploader: Marcus Davidsson 
//  E-mail:          [email protected]
//  Date/Time Added: 2006-09-30 20:31:21
//  Origin:          
//  Keywords:        exploration, trend, moving average
//  Level:           medium
//  Flags:           exploration
//  Formula URL:     http://www.amibroker.com/library/formula.php?id=724
//  Details URL:     http://www.amibroker.com/library/detail.php?id=724
//
//------------------------------------------------------------------------------
//
//  I started experimenting with Tradestations Radarscreen
//
//  when it struck me that Amibroker have the same function "Exploration" but
//  100000$ much cheaper.
//
//  The formula is quite simple just load it in to Amibroker
//
//  and go to automatic analysis and push explore.
//
//  The formula will scan multiple moving averages and draw conclusions
//  regarding overall trend phase, strenght etc. Enjoy!
//
//------------------------------------------------------------------------------

/*Use daily data! You could use data with
higher time resolution but then you have
to include a timeframe parameters
since 10 periods will become
10 minutes (if you have one Minute data)*/ 

//////////////////////////////////////////////////////////////

Filter = 1; // all symbols and quotes accepted.
DTL=140; // DTL = Define Trend Long
DTM=60;	// DTM = Define Trend Medium
DTS=8;  // DTS = Define Trend Short

//////////////////////////////////////////////////////////////

TL=LinRegSlope(MA(C, DTL),2);	 // TL = Trend Long
TM=LinRegSlope(MA(C, DTM),2);  // TM = Trend Medium
TS=LinRegSlope(MA(C, DTS),2);  // TS = Trend Short

TLL=IIf(LinRegSlope(MA(C, DTL),2) > 0,True, False);		
TMM=IIf(LinRegSlope(MA(C, DTM),2) > 0,True, False);		
TSS=IIf(LinRegSlope(MA(C, DTS),2) > 0,True, False);		

TLLL= 
WriteIf(TL>0 AND TL<0.3,"+",
WriteIf(TL>=0.3 AND TL<0.6 ,"+ +", 
WriteIf(TL>=0.6,"+ + +", 
WriteIf(TL<0 AND TL>-0.3,"-",
WriteIf(TL<=-0.3 AND TL>-0.6 ,"- -",
WriteIf(TL<=-0.6,"- - -",""))))));  

TMMM=
WriteIf(TM>0 AND TM<0.3,"+",
WriteIf(TM>=0.3 AND TM<0.6 ,"+ +",
WriteIf(TM>=0.6,"+ + +",
WriteIf(TM<0 AND TM>-0.3,"-",
WriteIf(TM<=-0.3 AND TM>-0.6 ,"- -",
WriteIf(TM<=-0.6,"- - -",""))))));  

TSSS=
WriteIf(TS>0 AND TS<0.3,"+",
WriteIf(TS>=0.3 AND TS<0.6 ,"+ +",
WriteIf(TS>=0.6,"+ + +",
WriteIf(TS<0 AND TS>-0.3,"-",
WriteIf(TS<=-0.3 AND TS>-0.6 ,"- -",
WriteIf(TS<=-0.6,"- - -",""))))));  

//////////////////////////////////////////////////////////////

AddTextColumn( TLLL, "MA"+-DTL, 1 , colorDefault,
IIf( TLL==True, colorGreen, colorRed ),-1 );
AddTextColumn( TMMM, "MA"+-DTM, 1 , colorDefault,
IIf( TMM==True, colorGreen, colorRed ),-1 );
AddTextColumn( TSSS, "MA"+-DTS, 1 , colorDefault,
IIf( TSS==True, colorGreen, colorRed ),-1 );

//////////////////////////////////////////////////////////////
message=
WriteIf(TL>=0.3 AND TM>=0.3 AND
TS>=0.3, "Strong Up Trend",
WriteIf(TL<=-0.3 AND TM<=-0.3 AND
TS<=-0.3, "Strong Down Trend",
WriteIf(TLL==True AND TMM==True AND
TSS==True,"Up Trend",
WriteIf(TLL==False AND TMM==False AND
TSS==False,"Down Trend", "No Trend"))));


AddTextColumn( message, "Overall Trend", 1 , 
colorDefault,IIf(TLL==True AND TMM==True AND
TSS==True, colorGreen, 
IIf(TLL==False AND TMM==False AND
TSS==False, colorRed, colorDefault )),-1 );

//////////////////////////////////////////////////////////////

x = IIf(Cross(LinRegSlope(MA(C, DTL),2),0) OR
Cross(0, LinRegSlope(MA(C, DTL),2) ), True, False); 
y = BarIndex()-ValueWhen(x==True, BarIndex(),1); 

Phase=WriteIf(Y>=400,"Mature",WriteIf(Y>100 AND
Y<400, "Progress", WriteIf(Y<=100, "Initial", "")));
//AddColumn( y, "Trend Phase", 1 , colorDefault,  -1);
AddTextColumn( Phase, "Trend Phase", 1 , colorDefault,  -1);

//////////////////////////////////////////////////////////////
Comments=
WriteIf(Y>=400,"Mature trend with risk of bubble",
WriteIf(y<400 AND TLL==True AND TMM==True AND TSS==True,
"Keep on coming baby $",
WriteIf(y<15 AND TLL==True AND TMM==True AND TSS==True OR
TLL==False AND TMM==False AND TSS==False,
"Are you going to grow up and become a big boy?",
WriteIf(y<400 AND TLL==False AND TMM==False AND TSS==False,
"Keep on coming baby $$",
WriteIf(TLL==True AND TMM==True AND TSS==False OR 
TLL==False AND TMM==False AND TSS==True,
"Risk for short term reversal",
WriteIf(TLL==True AND TMM==False AND TSS==True OR
TLL==False AND TMM==True AND TSS==False,
"trading range-avoid",
"live to trade another day")))))); 
			
AddTextColumn( Comments, "Comments", 1 ,
colorDefault,colorDefault,-1 );


//////////////////////////////////////////////////////////////
 

TradeOptions

Well-Known Member
#5
Elder Impulse Indicator V2

This exploration will show the following columns in the output -

Ticker
Date/Time
Impulse Status
Bars in this state
Weekly Trend
Monthly Trend

Code:
//------------------------------------------------------------------------------
//
//  Formula Name:    Elder Impulse Indicator V2
//  Author/Uploader: Lal 
//  E-mail:          
//  Date/Time Added: 2006-02-09 17:33:09
//  Origin:          Elder's Come Into My Trading Room
//  Keywords:        Elder Impulse
//  Level:           medium
//  Flags:           exploration,indicator
//  Formula URL:     http://www.amibroker.com/library/formula.php?id=585
//  Details URL:     http://www.amibroker.com/library/detail.php?id=585
//
//------------------------------------------------------------------------------
//
//  Elder's Impulse Indicator with exploration
//
//------------------------------------------------------------------------------

_SECTION_BEGIN("Elder Impulse");
/**************************************************************************
Name		:	Elder Impulse Indicator
Coded by	:	Lal
Date		:	28.10.2005
Note		: 	Please refer to Elder's "Come Into my Trading Room"
			for full details 


Update	:	19.Jan.2006
		Added Option to allow bars to be Colored as per Impulse

		Added explorer section to display Impulse Status
		along with Weekly AND Monthly Trends.

		20. Jan.2006
		Added ability to flexibly locate Weekly and Monthly 
		Ribbons

		9.Feb.2006
		Added option for use of TEMA and JMA 
		Added option to allow standard MACD params 
******************************************************************************/

EnableTextOutput(False);

// User-defined parameter for EMA periods

EMA_Type		= Param("EMA-1, TEMA-2, JMA-3", 2, 1, 3, 1);
EMA_prds 		= Param("EMA_periods", 7, 1, 30, 1);
Std_MACD		= Param("Standard MACD? No-0, Yes-1", 1, 0, 1, 1);
Plot_fashion	= Param("Bar+Arrows-1, Impulse  Bars-2", 2, 1, 2, 1);


// Allow user to define Weekly and Monthly Ribbon Location and Height
WR_P1 = Param("Weekly Ribbon Location", -10.5, -1000, 1000, 0.1);
WR_P2 = Param("Weekly Ribbon Height", 366.5, -0.001, 500, 0.1);

MR_P1 = Param("Monthly Ribbon Location", 5.2, -1000, 1000, 0.1);
MR_P2 = Param("Monthly Ribbon Height", 199, -0.001, 500, 0.1);


// Compute EMA and MACD Histogram
if(EMA_Type == 1)
{
	DayEMA	= EMA(Close, EMA_prds);
}
if (EMA_Type == 2)
{
	DayEMA	= TEMA(Close, EMA_prds);
}

if(EMA_Type == 3)
{
	// Line below to be used with Jurik JMA
	// DayEMA = JurikJMA(C, EMA_Prds);
}

Histogram	= MACD() - Signal();

// Determine if we have an Impulse UP, DOWN or None
Impulse_Up		=	DayEMA > Ref(DayEMA, -1) AND Histogram > Ref(Histogram, -1);
Impulse_Down	=	DayEMA < Ref(DayEMA, -1) AND Histogram < Ref(Histogram, -1);   
Impulse_None		=	(NOT Impulse_UP) AND (NOT Impulse_Down);

// Compute Weekly MACD and determine whether rising or falling
// Note: uses "non-standard"  parameters!
TimeFrameSet(inWeekly);

if (Std_MACD == 0)
{
MACD_val		=	MACD(5, 8);
Signal_val		=	Signal(5, 8, 5);
}
else
{
MACD_val		=	MACD(12, 26);
Signal_val		=	Signal(12, 26, 9);
}

Hist_in_w		=	MACD_val - Signal_val;

wh_rising = Hist_in_w > Ref(Hist_in_w, -1);
wh_falling = Hist_in_w < Ref(Hist_in_w, -1);

TimeFrameRestore();

// Now get Monthly MACD Histogram....
TimeFrameSet(inMonthly);
MACD_val		=	MACD(5, 8);
Signal_val		=	Signal(5, 8, 5);
Hist_in_m		=	MACD_val - Signal_val;

mh_rising = Hist_in_m > Ref(Hist_in_m, -1);
mh_falling = Hist_in_m < Ref(Hist_in_m, -1);

TimeFrameRestore();

wh_rising 		= TimeFrameExpand( wh_rising, inWeekly, expandLast ); 
wh_falling 		= TimeFrameExpand( wh_falling, inWeekly, expandLast); 
mh_rising 	= TimeFrameExpand(mh_rising, inMonthly, expandLast);
mh_falling 	= TimeFrameExpand(mh_falling, inMonthly, expandLast);

kol 	= IIf( wh_rising, colorGreen,  IIf(wh_falling, colorRed, colorLightGrey));
mkol 	= IIf( mh_rising, colorBlue,  IIf(mh_falling, colorYellow, colorLightGrey));

// Plot them all!
if (Plot_fashion == 1)
{
	Plot(Close, "Close", colorTeal, styleBar);
	PlotShapes(shapeUpArrow * Impulse_Up, colorBlue, 0, Low, -12);
	PlotShapes(shapeDownArrow * Impulse_Down, colorRed, 0, High, -12);
	PlotShapes(shapeSmallCircle * Impulse_None, colorWhite, 0, High, 5);
}
else
{
	bar_kol	=	IIf(impulse_UP, colorBlue, IIf(impulse_Down, colorRed, colorWhite));
	Plot(C, "Close", bar_kol, styleBar);
}

Plot(10, "ribbon", kol, styleOwnScale|styleArea|styleNoLabel, WR_P1, WR_P2);	// Weekly trend
Plot(10, "ribbon", mkol, styleOwnScale|styleArea|styleNoLabel, MR_P1, MR_P2);	// Monthly Trend

// Explorer Section
// Determine if Impulse status is bullish, neutral or bearish.  Display as Text Column.
Impulse_State		=	WriteIf(Impulse_Up, "Bulllish", WriteIf(Impulse_Down, "Bearish", "Neutral"));

// Set the background color for Impulse Status Column
Impulse_Col		=	IIf(Impulse_Up, colorGreen, IIf(Impulse_Down, colorRed, colorLightGrey));

// Determine Weekly Trend. Display as Text Column
Weekly_Trend		=	WriteIf(wh_rising, "Rising", WriteIf(wh_falling, "Falling", "Flat!"));
Weekly_Col		=	IIf(wh_rising, colorGreen, IIf(wh_falling, colorRed, colorLightGrey));

// Determine Monthly Trend. Display as Text Column
Monthly_Trend	=	WriteIf(mh_rising, "Rising", WriteIf(mh_falling, "Falling", "Flat!"));
Monthly_Col		=	IIf(mh_rising, colorGreen, IIf(mh_falling, colorRed, colorLightGrey));

// Determine how many bars has the current state existed
bars_in_bull	=	Min(BarsSince(impulse_none), BarsSince(impulse_down));
bars_in_bear	=	Min(BarsSince(impulse_up), BarsSince(impulse_none));
bars_in_neut	=	Min(BarsSince(impulse_down), BarsSince(impulse_up));

// Set a single variable to show number of bars in current state depending upon 
// actual Impulse Status - Bullish, Bearish or Neutral
bars_in_state	=	IIf(Impulse_Up, bars_in_bull, IIf(Impulse_down, bars_in_bear, bars_in_neut));

// Columns for display in Explorer 
AddTextColumn(Impulse_State, "Impulse Status", 1, colorWhite, Impulse_Col);
AddColumn(bars_in_state, "Bars in this state", 1, colorWhite, Impulse_col);
AddTextColumn(Weekly_Trend, "Weekly Trend", 1, colorWhite, Weekly_Col);
AddTextColumn(Monthly_Trend, "Monthly Trend", 1, colorWhite, Monthly_Col);

Filter = 1;

_SECTION_END();
 

TradeOptions

Well-Known Member
#6
All in One Explorer - Manish

This exploration will show the following columns in the output -

Ticker
Date/Time
Close
Volume
BBand
Short MA(15)
Mid MA(45)
Long MA(100)
MACD
Aroon
Stochastic
RSI(14)
MFI(14)
Score



Code:
_SECTION_BEGIN("All in One Explorer - Manish");
i=0;
//52 Week High Low
High52 = HHV(High,250);
Low52 = LLV(Low,250);

//Bollinger Band
BB1=C>BBandTop(C,20,2) AND Ref(C,-1)<Ref(BBandTop(C,20,2),-1);
BB2=C<BBandBot(C,20,2) AND Ref(C,-1)>Ref(BBandBot(C,20,2),-1);
BBStatus=WriteIf(BB1,"Above Top",WriteIf(BB2,"Below Bottom",WriteIf(IsNull(MA(C,20)),"N/A","Neutral")));
BBColor=IIf(BB1,colorRed,IIf(BB2,colorGreen,colorLightGrey));
IIf(BB2,i+1,i);

//Moving Average (Short, Mid & Long Term)
MAShort = C>MA(C,15);
IIf(MAShort,i+1,i);
MAMid = C>MA(C,45);
IIf(MAMid,i+1,i);
MALong = C>MA(C,100);
IIf(MALong,i+1,i);
ShortStatus = WriteIf(MAShort,"Bullish",WriteIf(IsNull(MA(C,15)) ,"N/A","Bearish"));
ShortColor = IIf(MAShort,colorGreen,colorRed);
MidStatus = WriteIf(MAMid,"Bullish",WriteIf(IsNull(MA(C,45))," N/A","Bearish"));
MidColor = IIf(MAMid,colorGreen,colorRed);
LongStatus = WriteIf(MALong,"Bullish",WriteIf(IsNull(MA(C,100)) ,"N/A","Bearish"));
LongColor = IIf(MALong,colorGreen,colorRed);

//MACD
MACDBull=MACD(12,26)>Signal(12,26,9);
IIf(MACDBull,i+1,i);
MACDStatus=WriteIf(MACDBull,"Bullish",WriteIf(IsNull(MACD(12,26)),"N/A","Bearish"));
MACDColor=IIf(MACDBull,colorGreen,colorRed);

//Aroon
Period=14;
LLVBarsSince=LLVBars(L,Period)+1;
HHVBarsSince=HHVBars(H,Period)+1;
AroonDown=100*(Period-LLVBarsSince)/(Period-1);
AroonUp=100*(Period-HHVBarsSince)/(Period-1);
AroonOsc=AroonUp-AroonDown;
Aroon=AroonOsc>0;
IIf(Aroon,i+1,i);
AroonStatus=WriteIf(Aroon,"Bullish",WriteIf(IsNull (RSI(14)),"N/A","Bearish"));
AroonColor=IIf(Aroon,colorGreen,IIf(IsNull(RSI(14) ),colorLightGrey,colorRed));

//Stochastic
StochKBull=StochK(14,3)>StochD(14,3,3);
IIf(StochKBull,i+1,i);
StochKStatus=WriteIf(StochKBull,"Bullish",WriteIf( IsNull(StochK(14,3)),"N/A","Bearish"));
StochKColor=IIf(StochKBull,colorGreen,colorRed);

//RSI
R1=RSI(14)>30 AND Ref(RSI(14),-1)<30 AND Ref(RSI(14),-2)<30;
R2=RSI(14)<70 AND Ref(RSI(14),-1)>70 AND Ref(RSI(14),-2)>70;
IIf(R1,i+1,i);
RSIStatus=WriteIf(R1,"Improving",WriteIf(R2,"Decli ning",WriteIf(IsNull(RSI(14)),"N/A","Neutral")));
RSIColor=IIf(R1,colorGreen,IIf(R2,colorRed,colorLightGrey));

//MFI
M1=MFI(14)>80;
M2=MFI(14)<20;
IIf(M2,i+1,i);
MFIStatus=WriteIf(M1,"Overbought",WriteIf(M2,"Over sold",WriteIf(IsNull(MFI(14)),"N/A","Neutral")));
MFIColor=IIf(M1,colorRed,IIf(M2,colorGreen,colorLightGrey));


 TrendScore =

 IIf(BB2,1,0)+
 IIf(MAShort,1,0)+
 IIf(MAMid,1,0) +
 IIf(MAMid,1,0) +
 IIf(MALong,1,0)+
 IIf(MACDBull,1,0) +
 IIf(Aroon,1,0) +
 IIf(StochKBull,1,0)+
 IIf(R1,1,0) +
 IIf(M2,1,0) ;





/*
TrendScore =

IIf(C>=Ref(C,-11),1,-1)+
IIf(C>=Ref(C,-12),1,-1)+
IIf(C>=Ref(C,-13),1,-1)+
IIf(C>=Ref(C,-14),1,-1)+
IIf(C>=Ref(C,-15),1,-1)+
IIf(C>=Ref(C,-16),1,-1)+
IIf(C>=Ref(C,-17),1,-1)+
IIf(C>=Ref(C,-18),1,-1)+
IIf(C>=Ref(C,-19),1,-1)+
IIf(C>=Ref(C,-20),1,-1);
*/





Filter = 1;

//AddColumn(High52,"52 Week High");
//AddColumn(Low52,"52 Week Low");
AddColumn(C,"Close",1,IIf(C>Ref(C,-1),colorGreen,colorRed));
AddColumn(V,"Volume",1,IIf(V>Ref(V,-1),colorGreen,colorRed));
AddTextColumn(BBStatus,"BBand",1,colorWhite,BBColor);
AddTextColumn(ShortStatus,"Short MA(15)",1,colorWhite,ShortColor);
AddTextColumn(MidStatus,"Mid MA(45)",1,colorWhite,MidColor);
AddTextColumn(LongStatus,"Long MA(100)",1,colorWhite,LongColor);
AddTextColumn(MACDStatus,"MACD",1,colorWhite,MACDColor);
AddTextColumn(AroonStatus,"Aroon",1,colorWhite,AroonColor);
AddTextColumn(StochKStatus,"Stochastic",1,colorWhite,StochKColor);
AddTextColumn(RSIStatus,"RSI(14)",1,colorWhite,RSIColor);
AddTextColumn(MFIStatus,"MFI(14)",1,colorWhite,MFIColor);
AddColumn(TrendScore,"Score");
_SECTION_END();
 

TradeOptions

Well-Known Member
#7
Exploration Bottom Fisher

This exploration will show the following columns in the output -

Ticker
Date/Time
Close
Avg Daily Vol
$Avg Range
Av % Range

Code:
/*
Aviator33
7th Feb 2008

Adapted from ideas presented at ozscanner.com. Average Dollar Price Volatility (ADPV) added for possible use as an 
intraday swing technique but seems to work best as a 5-10 Day strategy

Links:
http://www.ozscanner.com/bottom.htm
http://www.ozscanner.com/bottom2.htm

The Bottom Fisher Scan filters the entire market searching for stocks that have 
traded down for at least three consecutive trading sessions and are currently trading higher 
and signaling that a potential short-term bottom might have been formed. Based on swing trading 
methodology.

It can be used for a stock that is in an uptrend or downtrend. 
The trigger event for an entry is for the stock to be up from yesterday’s close. 
As long as a stop loss below today’s low is an acceptable risk while trying to capture 
the price target reward, you can enter the trade. Otherwise, you would have to use intraday support levels.
*/

//=========PARAMETERS====================

myVol=Param("Min Volume (Million)", 0,0,10,0.5);           // Filter out stocks below certain Volume (average over sampled periods). Default 0 (not filtered)
myVol = myVol * 1000000;                                   // Volume * million multiplier
myMaxPrice = Param("Price Max",200,0.0001,200,1);          // Filter for stocks below certain price. Default 0 (not filtered)
myMinPrice = Param("Price Min",0,0.0001,199,1);            // Filter for stocks above certain price. Default 0 (not filtered)
myPercentMin = Param("Min ADPV %",0,0,30,0.5);             // Filter  for minimum Average Dollar Price Volatility %. Default 0 (not filtered)
myMinPriceSteps = Param("Min Price Steps",0,0,500,1);      // Filter for minimum ticks in ADPV (eg H=0.005, L=0.002, price steps=3)
                                                           // Default 0 (not filtered)
myPeriods = Param("No. Of Days To Sample",20,2,90,1);
myPeriods = IIf(myPeriods>BarCount,BarCount,myPeriods);    // Just in case there are less data bars than the number of periods wanted

                                                           // ****** Uncomment next 2 lines for use in Australian ASX market *********
//myTickerMax = ParamList("Stocks only?","Yes|No");        // Filter to exclude options/warrants. Default "Yes" (stocks only)
//myTickerMax = IIf(myTickerMax == "Yes", 3,10);           // Ticker max length. 3 for stocks only.

//==========================================



trig1 = IIf(C<=O,True,False);
trig2 = IIf(Ref(C,-1)<=Ref(O,-1),True,False);
trig3 = IIf(Ref(C,-2)<=Ref(O,-2),True,False);
trig4 = IIf(C<Ref(C,-1) AND Ref(C,-1)<Ref(C,-2), True, False);

ADPV  = H - L;                                  // Average Dollar Price Volatility of current quotation (ie today's H to L range)
MedianPrice = ADPV/2 + L;                       // Median price of current quotation
ADPVpercent = (ADPV  / MedianPrice ) * 100;     // ADPV as percent of median price

// Calculate the same for the last x days, keep a running total for averaging
for( i = 1; i < myPeriods; i++ ) 
{
	x = i * -1; // negate counter to enable count back
	MedianPrice =MedianPrice + Ref(H-L,x)/2 + Ref(L,x);
	ADPV  = ADPV  + Ref(H-L,x);
	ADPVpercent = ADPVpercent + ((ADPV  / MedianPrice ) * 100);
}



MedianPrice = MedianPrice / myPeriods;       // Average median price over x days
ADPV  = ADPV  / myPeriods;                   // Average ADPV over x days
ADPVpercent = ADPVpercent / myPeriods;       // ADPV percentage over x days


Buy = trig1 AND trig2 AND trig3 AND trig4 AND MA(V,20)>500000;
Filter=Buy;
// ==============OUTPUT==================

// Tidy up output
txtADPVpercent=NumToStr(ADPVpercent,10.2 );
txtADPVpercent=txtADPVpercent + " %";
txtADPV = NumToStr(ADPV,3.3);
txtADPV = "$" + txtADPV ;
txtClose=NumToStr(Close,4.3 );
txtClose = "$" + txtClose;

AddTextColumn( txtClose , "Close");
AddColumn( MA(V,myPeriods), "Avg Daily Vol",20.0 );
AddTextColumn( txtADPV  , "$Avg Range",10.3 );
AddTextColumn( txtADPVpercent, "Av % Range",10.2 );
// AddColumn( PriceSteps , "Price Steps",8.0 );     // Remove comment tags to display price steps

// ====================================  END CODE ====================================================
 

TradeOptions

Well-Known Member
#8
Exploration pivot calc

This exploration will show the following columns in the output -

Ticker
Date/Time
Name
Close
RSI
Volume
R 2
R 1
Pivot
S 1
S 2
Code:
P = ParamField("Price field",-1);
Periods = Param("Periods", 20, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );


Filter = L <  BBandBot( P, Periods, Width );

P  =  ((H + L + C) / 3);
R1  =  ((2 * P) - L);
S1  =  ((2 * P)  - H);
R2  =  ((P - S1) + R1);
S2  =  (P - (R1 - S1));

AddTextColumn( FullName(), "Name");
AddColumn( Close, "Close" );
AddColumn (RSI(), "RSI",1.2);
AddColumn( V, "Volume",1 );
AddColumn( r2, "R 2", 1.2);
AddColumn( r1, "R 1", 1.2);
AddColumn( P, "Pivot", 1.2);
AddColumn( S1, "S 1", 1.2);
AddColumn( S2, "S 2", 1.2);
 

TradeOptions

Well-Known Member
#9
Modified Momentum Finder DDT-NB

This exploration will show the following columns in the output -

Ticker
Date/Time
AccTotal
TotalROC
ROCPeriod
ROCHalfPeriod
ROCQuarterPeriod

Code:
//------------------------------------------------------------------------------
//
//  Formula Name:    Modified Momentum Finder DDT-NB
//  Author/Uploader: Frank Snay 
//  E-mail:          [email protected]
//  Date/Time Added: 2002-01-03 15:34:58
//  Origin:          Modification to Dr. S. Nathan Berger's DDT-NB system, first step (Selection of stocks or funds)
//  Keywords:        Ranking System   Momentum Finder
//  Level:           basic
//  Flags:           exploration
//  Formula URL:     http://www.amibroker.com/library/formula.php?id=147
//  Details URL:     http://www.amibroker.com/library/detail.php?id=147
//
//------------------------------------------------------------------------------
//
//  A Ranking System for stocks or mutual funds that uses Rate of Change
//  (momentum) for three time frames and Rate of Change of Rate of Change
//  (acceleration) for two time frames. The system uses weighted Rate of
//  Changes with the most recent periods having more weight. Combined with
//  non-weighted acceleration, changes in momentum are detected earlier than
//  with Rate of Change only.
//
//------------------------------------------------------------------------------

/* Modified Momentum Finder by Frank Snay
   Use to find stocks or mutual funds in First Step of Dr. S. Nathan Berger's
   DDT-NB SYSTEM posted during the final week of 2001.
   Please copy the following formula to the Automatic Analysis window AND
   click on "Explore"*/

/* The description of Dr. Berger's initial routine to "find" the mutual funds
   based upon trying several different time periods, and writing down the results
   for each.  This explore uses three time frames, a user defined Period for
   the longest time frame, and computer derived half and quarter periods of
   the Period.  Several expolres are now reduced to one. 

/* Use any Watch list, use filter, n last days = 1.  
   As I use a select watch list and want results for all stocks, I set the 
   MinChange  to -100%.  User can reset this to any desired level. */
   MinChange = -100  ; /* this is minimum percent change to be filtered */
/* About 8 Trading Weeks for Scan.  User set to desired time */
Period = 40; /* how many bars back */
HalfPeriod = int(.5 + Period/2); // One-half of the period
QuarterPeriod = int(.5 + Period/4);  // One-quarter of the period
ROCPeriod = ROC(Close,Period); //full period rate of change
ROCHalfPeriod = ROC(Close,HalfPeriod);  //Half period rate of change
ROCQuarterPeriod = ROC(Close,QuarterPeriod);  //Quarter period rate of change

/*  Now add the three, weighted for most recent data having most effect 
    This is done by doubling the half, and 4 times the quarter values,
    and dividing the grand total by 3  */
TotalROC = (ROCPeriod + 2*ROCHalfPeriod + 4*ROCQuarterPeriod)/3;

/*  The old physics lessons told us that momentum ( or velocity ) is a rate of
    change per a unit of time.  In this case, closing price per period.  
    The next step is to compute the rate of change of the rate of change.  Back
    to the lessons, this is acceleration.  Acceleration shows the increasing or
    decreasing momentum for a time unit.  To accomplish this, I will take the
    ROCQuarterPeriod today, and subtract the ROCQuarterPeriod a quarter of a
    period ago, ie, ROCQuarterPeriod - ref(ROCQuarterPeriod,-QuarterPeriod).
    I will repeat the process for the ROCHalfPeriod. For ease of
    display, I will call this final result AccTotal and display it before
    TotalROC.  The AccTotal is the TotalROC with the above additivies for 
    acceleration. 
    Very Important - notice how the results based only upon  TotalROC
    are changed by the AccTotal.  The addition of acceleration brings
    the stocks or funds with the latest positive changes in ROC to the top of 
    the list in AccTotal, and if the acceleration is negative, the stock will
    have a lower ranking than with TotalROC.  By themselves per each stock or
    mutual fund, the values in AccTotal and TotalROC mean little - it is ONLY 
    when compared to other stocks or funds that the values take on a meaning. 
    What this means is that the values in AccTotal and TotalROC ARE NOT the 
    expected returns, BUT A RELATIVE RANKING COMPARED TO OTHER STOCKS OR FUNDS.*/
AccTotal = TotalROC + ((ROCHalfPeriod) - Ref(ROCHalfPeriod,-HalfPeriod)) + (ROCQuarterPeriod - Ref(ROCQuarterPeriod,-QuarterPeriod)) ;        

LastBar = Cum(1) == LastValue( Cum(1) );
Filter = ROCPeriod  > MinChange AND LastBar;

NumColumns =5;
Column0 = AccTotal;Column0Name = "AccTotal";Column0Format = 1.2;
Column1 = TotalROC;Column1Name = "TotalROC";Column1Format = 1.2;
Column2 = ROCPeriod;Column2Name = "ROCPeriod";Column2Format = 1.2;
Column3 = ROCHalfPeriod;Column3Name = "ROCHalfPeriod";Column3Format = 1.2;
Column4 = ROCQuarterPeriod;Column4Name = "ROCQuarterPeriod";Column4Format = 1.2;
 

TradeOptions

Well-Known Member
#10
Bollinger Band squeeze highlighter and exploration

This exploration will show the following columns in the output -

Ticker
Date/Time
BB Breakout

Code:
Length = 14;
Price = EMA(Close, Length);
 
// Keltner 
kLength = Length;
kN = 1.5;
kATR = ATR(kLength);
kUpper = Price + kN * kATR;
kLower = Price - kN * kATR;
 
// Bollinger
bbLength = Length;
bbN = 2;
bbStDevValues = StDev(Close, bbLength);
bbUpper = Price + bbN * bbStDevValues;
bbLower = Price - bbN * bbStDevValues;
 
IsBBSqueeze = bbUpper <= kUpper AND bbLower >= kLower;

Proportion = (kUpper - kLower) / (bbUpper - bbLower);
BBBreakout = Cross(1,Proportion); 
Periods = Param("BBPeriods", 14, 2, 300, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorCycle );
Style = ParamStyle("Style");
bbtop=BBandTop( C, Periods, Width );
bbbot=BBandBot( C, Periods, Width );
Plot(bbtop, "", Color, Style ); 
Plot(bbbot , "", Color, Style );

sqeezcolor=ColorRGB(194,220,218);

PlotOHLC( bbtop,bbtop, bbbot,bbbot, "",IIf(IsBBSqueeze,colorYellow,colorLightGrey), styleCloud|styleNoRescale,  Null, Null, Null, -1 );
Plot(Close,"Close",IIf(C>=O,colorBrightGreen,colorRed),styleCandle); 

Filter = BBBreakout;

AddColumn(BBBreakout, "BB Breakout", 1, colorWhite, IIf(BBBreakout==1, colorRed, colorWhite));
//set default sorting to Date/time in descending order in results window
SetSortColumns(-2);
 

Similar threads