View Full Version: Triple SCreen Trading System Using Amibroker

ChartistsUnited > Trading Strategies & Systems > Triple SCreen Trading System Using Amibroker



Title: Triple SCreen Trading System Using Amibroker
Description: Trading System


jest1081 - June 28, 2006 06:17 PM (GMT)
Hi all, just wanna share something that i have programmed (not fully by me contributions from fellow traders in amibroker as well). I have tried and tested, and thinks it works very closely to the system that has been taught. End of e day must remember, system wun bring u money, don't search for holy grail...be a disciplined trader.

ONLY FOR USE IN AMIBROKER TA CHARTS

WEEKLY CHARTS WITH MONTHLY IMPULSE SYSTEM

// Weekly Bar Chart
_SECTION_BEGIN("Weekly Graph");

SetChartOptions(0,chartShowArrows|chartShowDates);
// 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);

TimeFrameSet( inWeekly );
// 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);
}

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);
}

Histogram = MACD_val - Signal_val;


// 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);

wh_rising = DayEMA > Ref(DayEMA, -1) AND Histogram > Ref(Histogram, -1);
wh_falling = DayEMA < Ref(DayEMA, -1) AND Histogram < Ref(Histogram, -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, colorBrightGreen, IIf(wh_falling, colorRed, colorLightGrey));
mkol = IIf( mh_rising, colorBlue, IIf(mh_falling, colorYellow, colorLightGrey));

TimeFrameSet( inWeekly );
// Plot them all!
if (Plot_fashion == 1)
{
Plot(Close, "Close", colorTeal, styleBar);
PlotShapes(shapeUpArrow * Impulse_Up, colorBrightGreen, 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, colorBrightGreen, IIf(impulse_Down, colorRed, colorCustom11));
Plot(C, "Close", bar_kol, styleBar);
}

//Plot(10, "Weekly Ribbon", kol, styleOwnScale|styleArea|styleNoLabel, WR_P1, WR_P2); // Weekly trend GREEN = RISING, RED = FALLING, WHITE = NEUTRAL
Plot(10, "Monthly Ribbon", mkol, styleOwnScale|styleArea|styleNoLabel, MR_P1, MR_P2); // Monthly Trend BLUE = RISING, YELLOW = FALLING, WHITE = NEUTRAL
TimeFrameRestore();

_SECTION_END();

_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 200, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("ZIG - Zig");
TimeFrameSet( inWeekly );
P = ParamField( "Price field" );
change = Param("% change",5,0.1,25,0.1);
Plot( Zig(P, change), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
TimeFrameRestore();
_SECTION_END();


WEEKLY MACD

// Weekly MACD Histogran
_SECTION_BEGIN("Weekly MACD");
TimeFrameSet( inWeekly );
MACDw = MACD( 12, 26 ) - Signal( 12, 26, 9 );
MACDwLINE = MACD( 12, 26 ) ;
MACDwSignal = Signal( 12, 26, 9 );

Color = IIf(Ref(MACDw, -1)>MACDw, colorRed, colorBrightGreen);

TimeFrameRestore();
Plot(MACDw,"MACD Weekly",Color,styleHistogram | styleThick);
Plot(MACDwLINE,"MACD Weekly Line",colorRed,styleLine);
Plot(MACDwSignal,"MACD Weekly Signal Line",colorBrightGreen,styleLine);
_SECTION_END();


WEEKLY FORCE INDEX 13day MA

_SECTION_BEGIN("Force Index2");
TimeFrameSet( inWeekly );
periods = Param("Periods", 13, 1, 100, 1);

FI = EMA(((Close - Ref(Close, -1)) * V), periods);
FI_kol = IIf(fi < 0, colorRed, colorBrightGreen);

Plot(Close, "Close", colorRed, 2);
Plot(FI, "Force Index", FI_kol, styleLine|styleThick);
Plot(0,"", colorViolet, styleLine | styleThick | styleNoLabel);

Title = Name() +
EncodeColor(colorWhite) + " - Force Index - " + WriteVal(periods, 1) + " days," +
EncodeColor(colorRed) + " Close " +
EncodeColor(colorWhite) + " = " + WriteVal(Close) + ", " +
EncodeColor(colorBlue) + "Force Index = " +
EncodeColor(colorWhite) + WriteVal(FI, 1.2);
TimeFrameRestore();
_SECTION_END();

_SECTION_BEGIN("Volume");
TimeFrameSet( inWeekly );
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorBlueGrey ), ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick, maskHistogram ), 2 );
TimeFrameRestore();
_SECTION_END();


DAILY CHART WITH WEEKLY IMPULSE SYSTEM

_SECTION_BEGIN("Elder Impulse");

SetChartOptions(0,chartShowArrows|chartShowDates);
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", 5.2, -1000, 1000, 0.1);
WR_P2 = Param("Weekly Ribbon Height", 199, -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);
wh_none = (NOT wh_rising) AND (NOT wh_falling);

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);
wh_none = TimeFrameExpand( wh_none, inWeekly, expandLast);
mh_rising = TimeFrameExpand(mh_rising, inMonthly, expandLast);
mh_falling = TimeFrameExpand(mh_falling, inMonthly, expandLast);

kol = IIf( wh_rising, colorBrightGreen, IIf(wh_falling, colorRed, IIf(wh_none, colorCustom11, 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, colorBrightGreen, 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, colorBrightGreen, IIf(impulse_Down, colorRed, colorCustom11));
Plot(C, "Close", bar_kol, styleBar);
}

Plot(10, "Weekly Ribbon", kol, styleOwnScale|styleArea|styleNoLabel, WR_P1, WR_P2); // Weekly trend GREEN = RISING, RED = FALLING, WHITE = NEUTRAL
//Plot(10, "Monthly Ribbon", mkol, styleOwnScale|styleArea|styleNoLabel, MR_P1, MR_P2); // Monthly Trend BLUE = RISING, YELLOW = FALLING, WHITE = NEUTRAL

// Auto Envelope
PlotForeign(GetBaseIndex(),IndustryID(1),colorWhite,styleLine|styleLeftAxisScale);

LookBkPd = 100 ;
AvgPd = 22 ;
ExternalBarPct = 15 ;
ConvergePct = 2 ;
Middle = EMA( C,AvgPd ) ;
Rng = HHV( H,LookBkPd ) - LLV( L,LookBkPd ) ;
X = Rng ;
deltaX = X/2 ;
do
{
Over = H > Middle + X ;
Under = L < Middle - X ;
OuterPct = 100*( Sum( Over, LookBkPd ) + Sum( Under, LookBkPd )
)/LookBkPd ;
OP = LastValue(OuterPct) ;
X=X+sign( OP - ExternalBarPct )*deltaX ;
deltaX = deltaX/2 ;
}while ( abs( OP - ExternalBarPct ) > ConvergePct ) ;
Plot( Middle, "MA", colorYellow, styleLine|styleNoTitle ) ;
Plot( Middle+X, "MA", colorSkyblue, styleDashed|styleNoTitle ) ;
Plot( Middle-X, "MA", colorSkyblue, styleDashed|styleNoTitle ) ;


// 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();

_SECTION_BEGIN("ZIG - Zig");
P = ParamField( "Price field" );
change = Param("% change",5,0.1,25,0.1);
Plot( Zig(P, change), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


DAILY MACD

// Weekly MACD Histogran
_SECTION_BEGIN("Weekly MACD");
TimeFrameSet( inDaily );
MACDw = MACD( 12, 26 ) - Signal( 12, 26, 9 );
MACDwLINE = MACD( 12, 26 ) ;
MACDwSignal = Signal( 12, 26, 9 );

Color = IIf(Ref(MACDw, -1)>MACDw, colorRed, colorBrightGreen);

TimeFrameRestore();
Plot(MACDw,"MACD Daily",Color,styleHistogram | styleThick);
Plot(MACDwLINE,"MACD Daily Line",colorRed,styleLine);
Plot(MACDwSignal,"MACD Dail Signal Line",colorBrightGreen,styleLine);
_SECTION_END();


DAILY FORCE INDEX 2DAY MA

_SECTION_BEGIN("Force Index2");

periods = Param("Periods", 2, 1, 100, 1);

FI = EMA(((Close - Ref(Close, -1)) * V), periods);
FI_kol = IIf(fi < 0, colorRed, colorBrightGreen);

Plot(Close, "Close", colorRed, 2);
Plot(FI, "Force Index", FI_kol, styleLine|styleThick);
Plot(0,"", colorViolet, styleLine | styleThick | styleNoLabel);

Title = Name() +
EncodeColor(colorWhite) + " - Force Index - " + WriteVal(periods, 1) + " days," +
EncodeColor(colorRed) + " Close " +
EncodeColor(colorWhite) + " = " + WriteVal(Close) + ", " +
EncodeColor(colorBlue) + "Force Index = " +
EncodeColor(colorWhite) + WriteVal(FI, 1.2);
_SECTION_END();

_SECTION_BEGIN("Volume");
Plot( Volume, _DEFAULT_NAME(), ParamColor("Color", colorBlueGrey ), ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick, maskHistogram ), 2 );
_SECTION_END();


ELDER THERMOMETER

_SECTION_BEGIN("Market Thermometer");

H1 = Ref(H, -1);
L1 = Ref(L, -1);

T = IIf(H<H1 AND L>L1, 0, IIf(H-H1>L1-L, H-H1, L1-L));

Val1 = H-H1;
Val2 = L1-L;
Val = IIf(Val1>Val2, Val1, Val2) ;


Avgval = Median(Val, 22);

color= IIf (Val < Avgval, colorBlue, IIf(Val >= Avgval AND Val < Avgval * 3, colorViolet, IIf(Val > Avgval * 3, colorOrange, colorViolet)));


Plot(T, _DEFAULT_NAME(), color, styleHistogram | styleThick);
P = ParamField("Price field",-1);
Periods = Param("Periods", 22, 2, 200, 1, 10 );

Plot( EMA( P, Periods ), "EMA 22", colorGreen, styleThick);

_SECTION_END();

ELDER BULL

// Daily BullPower
_SECTION_BEGIN("Bull Power EMA");
///*Bull Power*/
Lookback = Param ("EMA Lookback",13);
BullPower = High - EMA(Close,Lookback);
Plot (BullPower, "", ParamColor ("Color", colorCustom11), styleHistogram );
Title = Name() + " " + Date() + " Bull Power" + WriteVal (Lookback, 3.0) + " Day: " + WriteVal (BullPower, 5.3);
GraphXSpace = 5;
_SECTION_END();


ELDER BEAR

// Daily BearPower
_SECTION_BEGIN("Bear Power EMA");
///*Bear Power*/
Lookback = Param ("EMA Lookback", 13);
BearPower = Low - EMA(Close,Lookback);
Plot (BearPower, "", ParamColor ("Color", colorRed), styleHistogram );
Title = Name() + " " + Date() + " Bear Power" + WriteVal (Lookback, 3.0) + " Day: " + WriteVal (BearPower, 5.3);
GraphXSpace = 5;
_SECTION_END();


ELDER TRIPLE SCREEN SCAN

// Elder Triple Screen Trading System.
// Coded by Dennis Skoblar 7/05/2005.
// Derrived from "Trading For A Living" and "Come Into My Trading Room" by Alexander Elder.

// This scan finds candidates by the Weekly MACD Historgam slope, and the Daily 2 Period Force Index dipping above or below it's Zero Line. Plot a Weekly 26 Period EMA to
// help confirm the weekly direction. It should be rising along with an uptick on the Weekly MACD Histogram to go long. However, Elder writes that divergences in the MACD
// Histogram override the EMA. The Daily 2 Period Force Index will be below it's Zero Line. Look for the stock to pullback to around it's Daily 13 Period EMA. Also use the
// Daily 22 Period EMA to confirm the direction of the daily trend. Do the opposite for shorts. Use the Long/Short EMA Weekly Direction Tabs as filters to cull through the
// scan to only display the Weekly EMA going in the intended trading direction. Use the Long/Short Elder Ray Tabs (BullPower AND BearPower) to fine tune the entry signals.
// This tab is best used when in agreement with the Long/Short EMA Weekly Direction Tabs. A 50 Period EMA > 100000 is used to Filter Volume. A minimum of a 5 point run in
// one Month is used as a Filter for a stock's range. This scan is best used as an Exploration.

TimeFrameSet( inWeekly );
WeeklyMACD = MACD(12,26) - Signal(12,26,9);
WeekHistRising = Ref(WeeklyMACD, -1) < Ref(WeeklyMACD, 0);
WeekHistFalling = Ref(WeeklyMACD, -1) > Ref(WeeklyMACD, 0);
FIWeekly = EMA(V*(C-Ref(C,-1)),13);
WeeklyForceIndexLong = FIWeekly > 0;
WeeklyForceIndexShort = FIWeekly < 0;
TimeFrameRestore();

// Weekly criteria
MACDLongW = WeekHistRising;
MACDShortW= WeekHistFalling;
FILongW = WeeklyForceIndexLong;
FIShortW = WeeklyForceIndexShort;

// Daily criteria
FIDaily = EMA(V*(C-Ref(C,-1)),2);
FILongD = FIDaily < 0;
FIShortD = FIDaily > 0;
VFilter = EMA(V,50) > 100000;
TenTwentyFilter = HHV(H,20)-LLV(L,20); // How much price has gone in one month (>=10 points preferable)
FiftyDayHVFilter = round(StDev(log(C/Ref(C,-1)),50)*100*sqrt(256)); // One year volotility (>=40 preferable)
bullpower= High - EMA(Close,13);
bearpower= Low - EMA(Close,13);

// Scan criteria
ElderLong = MACDLongW AND FILongD AND FILongW;
ElderShort = MACDShortW AND FIShortD AND FIShortW;

// Columns for exploration

NumColumns = 12;

Column0 = FullName();
Column0Name = "Ticker name";

Column1 = " ";
Column1Name =" ";

Column2 = ElderLong;
Column2Name = "Long";

Column3 = ElderLong AND EMA(C,130) > Ref(EMA(C,130),-5);
Column3Name = "Long EMA Weekly Direction";

Column4 = Column3 AND (bearpower < 0 AND bullpower > 0);
Column4Name = "Long Elder Ray Filter";

Column5 = " ";
Column5Name =" ";

Column6 = ElderShort;
Column6Name = "Short";

Column7 = ElderShort AND EMA(C,130) < Ref(EMA(C,130),-5);
Column7Name = "Short EMA Weekly Direction";

Column8 = Column7 AND (bearpower < 0 AND bullpower > 0);
Column8Name = "Short Elder Ray Filter";

Column9 = " ";
Column9Name =" ";

Column10 = TenTwentyFilter;
Column10Name = "One Month Point Range";

Column11 = FiftyDayHVFilter;
Column11Name = "Historical Volotility 50 Day";

AddTextColumn( IndustryID(1), "Industry" );

AddTextColumn( MarketID(1), "Market" );

// Filters
Filter = VFilter AND (ElderLong OR ElderShort);
Buy = ElderLong;
Sell = 0;
Short = ElderShort;
Cover = 0;

Hc - June 29, 2006 12:38 AM (GMT)
Thanks for sharing the codes.

BTW, have you use Metastock before? How does Amibroker compared to Metastock?

Hope to see your comments on Amibroker.

jest1081 - June 29, 2006 02:54 PM (GMT)
Nope i have no experience with metastock...

Amibroker delivers...at the very basic, you need to know a little bit of coding to make a basic trading system.

I dun quite like the charts...its not very crisp. You can take alook at my blogsite it contains a few pictures, click

One thing for sure is the longer i trade, the more satisfaction i want to get from it, the charts works fine but lacks depth, if u know what i mean, just don't give you that 'feeling'.

Then again i might still stick to amibroker when i go real time on futures and indexes.




Hosted for free by InvisionFree