Skip to main content
No. of Recommendations: 6
I don't give a whole lot to the board anymore, so here's a very small contribution for those who have Amibroker and Pinnacle Data. If someone can figure out how to normalize the Seasonality lines to something like this http://www.seasonalcharts.com/classics_dj_ia.html and how to backtest it that would awesome. I doubt you can backtest seaonality in amibroker until you can normalize it.

The post assumes you know how to use the toggle function in the parameters dialogue box. Ignore green comments, they haven't been updated.

NH-NL Pinnacle data plots and backtest first
Seasonality plots second


Cheers Kev

NH-NL File........................

//TMF Post from Zee on 7/21 or 7/22/08 ref blends

//Evaluation Variables
//NEW HIGHS AND LOWS


Weekly = ParamToggle("Weekly=Yes, Daily=No", "No | Yes");
Amex = ParamToggle("AMEX Data", "No | Yes");
Nasdaq = ParamToggle("Nasdaq Data", "No | Yes");
NYSE = ParamToggle("NYSE Data", "No | Yes");
WholeMkt = ParamToggle("All Mkts Data", "No | Yes");

B = 0;
F = 0;

if (Weekly)
{
if( Amex )
{
B = Foreign("AMWHIGHS", "C");
F = Foreign("AMWLOWS", "C");
}
if( Nasdaq )
{
B = Foreign("NDWHIGHS", "C");
F = Foreign("NDWLOWS", "C");
}
if( NYSE )
{
B = Foreign("NYWHIGHS", "C");
F = Foreign("NYWLOWS", "C");
}
if( WholeMkt )
{
B = Foreign("AMWHIGHS", "C") + Foreign("NDWHIGHS", "C") + Foreign("NYWHIGHS", "C");
F = Foreign("AMWLOWS", "C") + Foreign("NDWLOWS", "C") + Foreign("NYWLOWS", "C");
}
}
else
{
if( Amex )
{
B = Foreign("AM-Highs", "C");
F = Foreign("AM-Lows", "C");
}
if( Nasdaq )
{
B = Foreign("ND-Highs", "C");
F = Foreign("ND-Lows", "C");
}
if( NYSE )
{
B = Foreign("NY-Highs", "C");
F = Foreign("NY-Lows", "C");
}
if( WholeMkt )
{
B = Foreign("AM-HIGHS", "C") + Foreign("ND-HIGHS", "C") + Foreign("NY-HIGHS", "C");
F = Foreign("AM-LOWS", "C") + Foreign("ND-LOWS", "C") + Foreign("NY-LOWS", "C");
}
}
//EMALong = Param("EMA Long", 40, 0, 300, 1);//EMA 23 and 7 all indexes 1.1.00 - 5.14.10, 39/5 - 1.1.05 - 5.14.10
EMALong = Optimize("EMA Long", 37, 21, 60, 1);
//EMAShort = Param("EMA Short", 2, 0, 300, 1);// MA 27 and 7
EMAShort = Optimize("EMA Short", 2, 1, 50, 2);

Q = (B) - (F);//Total Mkt
Q1 = (EMA(Q, EMALong)+ Ref(EMA(Q, EMALong),-1)+ Ref(EMA(Q, EMALong),-2))/3;
Q2 = (EMA(Q, EMAShort)+ Ref(EMA(Q, EMAShort),-1)+ Ref(EMA(Q, EMAShort),-2))/3;
NHNLValue = Optimize("NH-NL Value", -4, -200, 200, 2);//-4 Long&Short

Plot(Q, "NH-NL", colorWhite, styleLine);
Plot(Q1, "Long EMA of NH-NL", colorRed, styleLine);
Plot(Q2, "Short EMA of NH-NL", colorBrightGreen, styleLine);
Plot(-4, "Bullish Line", colorYellow, styleLine);

//Longs
Buy = Q2 > Q1 AND Q2 > NHNLValue;
Sell = Q2 < Q1 AND Q2 < NHNLValue;
Short = Sell;
Cover = Buy;

//Shorts
/*Buy = Q2 < Q1 AND Q2 < 0;
Sell = Q2 > Q1 AND Q2 > 0;
Short = Sell;
Cover = Buy;


//N-bar stop
//Sell = 0;
//
//ApplyStop( stopTypeNBar, stopModeBars, N );




Next File.......................Seasonality

/*Alex,

Nice work you have done on this topic.

In my opinion 5 years are NOT enough to express meaningful seasonal
patterns: MRCI does it with at least 15 years. So I took your code AND did a
little improvement by adding a Second Plot of a 15 years long Study. You can
find it below.

What strikes me is that the overall trend tends to hide seasonal patterns.
if you consider oil futures in the last years the upside trend also affects
the seasonal plots, which makes it difficult to spot seasonal tops OR
bottoms.

A workaround could be to use instead of closing prices "C", the rate of
change "roc( C , 1 )".

alberto*/

// days per year

dp_y = 252;

// day's avg Close for 5, 10, 20, 40 yrs and 15 yrs Close

ac5y =
(Ref(C,-dp_y*5)+Ref(C,-dp_y*4)+Ref(C,-dp_y*3)+Ref(C,-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_y*6)+
Ref(C,-dp_y*5)+Ref(C,-dp_y*4)+Ref(C,-dp_y*3)+Ref(C,-dp_y*2)+Ref(C,-dp_y))/40;

// plot price and seasonality overlay

//Plot(C, "", colorWhite, styleBar);
//SetChartOptions(0, chartShowDates);
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );

FiveYear = ParamToggle("5YrPlot", "No | Yes");
TenYear = ParamToggle("10YrPlot", "No | Yes");
TwentyYear = ParamToggle("20YrPlot", "No | Yes");
FortyYear = ParamToggle("40YrPlot", "No | Yes");

if( FiveYear )
{
Plot(ac5y, "5yr", colorYellow, styleOwnScale);
}
if( TenYear )
{
Plot(ac10y, "10yr", colorLightOrange, styleOwnScale);
}
if( TwentyYear )
{
Plot(ac20y, "20yr", colorRed, styleOwnScale);
}
if( FortyYear )
{
Plot(ac40y, "40yr", colorBrightGreen, styleOwnScale);
}
Print the post  

Announcements

What was Your Dumbest Investment?
Share it with us -- and learn from others' stories of flubs.
When Life Gives You Lemons
We all have had hardships and made poor decisions. The important thing is how we respond and grow. Read the story of a Fool who started from nothing, and looks to gain everything.
Contact Us
Contact Customer Service and other Fool departments here.
Work for Fools?
Winner of the Washingtonian great places to work, and Glassdoor #1 Company to Work For 2015! Have access to all of TMF's online and email products for FREE, and be paid for your contributions to TMF! Click the link and start your Fool career.