Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
Find Out More Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

Variable Linear Regression Crossover Long Term for Amibroker (AFL)

Rating:
2 / 5 (Votes 4)
Tags:
trend, ambroker

Shows Trend lines of Prices as well as the variable linear regression of the price.

Medium Term:
When Trend is up (If cross TL1 & TL2 lines), trendline is BightGreen.
When Trend is down (If cross TL2 & TL1 lines), trendline is Pink.

Long Term:
When Trend is up (If cross TL3 & TL4 lines), trendline is Blue.
When Trend is down (If cross TL4 & TL3 lines), trendline is Red.

Just modify the period of the regression line to what you would like to use for short/Medium & long terms.

Indicator / Formula

Copy & Paste Friendly
_SECTION_BEGIN("Trend Lines Longterm");

Timeframeset(inWeekly);

GraphType= ParamList("Graph Type", "Type1, Type2, Type3, Type4, Type5, Type6");
PriceField = ParamField("Price Field");

ps1 = Param("TL1 Periods", 20, 5, 50, 1);
ps2 = Param("TL2 Periods", 3,  3, 25, 1);

ps3 = Param("TL1 Periods", 20, 5, 50, 1);
ps4 = Param("TL2 Periods", 4,  3, 25, 1);

ps5 = Param("TL1 Periods", 20, 5, 50, 1);
ps6 = Param("TL2 Periods", 5,  3, 25, 1);

ps7 = Param("TL1 Periods", 20, 5, 50, 1);
ps8 = Param("TL2 Periods", 6,  3, 25, 1);

ps9 = Param("TL1 Periods", 20, 5, 50, 1);
ps10 =Param("TL2 Periods", 7,  3, 25, 1);

ps11 =Param("TL1 Periods", 20, 5, 50, 1);
ps12 =Param("TL2 Periods", 8,  3, 25, 1);


pm1 = Param("TL3 Periods", 80, 5, 200, 1);
pm2 = Param("TL4 Periods", 15, 5, 200, 1);

pm3 = Param("TL3 Periods", 80, 5, 200, 1);
pm4 = Param("TL4 Periods", 17, 5, 200, 1);

pm5 = Param("TL3 Periods", 80, 5, 200, 1);
pm6 = Param("TL4 Periods", 20, 5, 200, 1);

pm7 = Param("TL3 Periods", 80, 5, 200, 1);
pm8 = Param("TL4 Periods", 23, 5, 200, 1);

pm9 = Param("TL3 Periods", 80, 5, 200, 1);
pm10 =Param("TL4 Periods", 28, 5, 200, 1);

pm11 =Param("TL3 Periods", 80, 5, 200, 1);
pm12 =Param("TL4 Periods", 35, 5, 200, 1);


if (GraphType == "Type1")					{ TL1 = LinearReg(PriceField, ps1); 	TL2 = EMA(TL1, ps2);}
if (GraphType == "Type2")					{ TL1 = LinearReg(PriceField, ps3); 	TL2 = EMA(TL1, ps4);}
if (GraphType == "Type3")					{ TL1 = LinearReg(PriceField, ps5); 	TL2 = EMA(TL1, ps6);}
if (GraphType == "Type4")					{ TL1 = LinearReg(PriceField, ps7); 	TL2 = EMA(TL1, ps8);}
if (GraphType == "Type5")					{ TL1 = LinearReg(PriceField, ps9); 	TL2 = EMA(TL1, ps10);}
if (GraphType == "Type6")					{ TL1 = LinearReg(PriceField, ps11); 	TL2 = EMA(TL1, ps12);}


if (GraphType == "Type1")					{ TL3 = LinearReg(PriceField, pm1); 	TL4 = EMA(TL3, pm2);}
if (GraphType == "Type2")					{ TL3 = LinearReg(PriceField, pm3); 	TL4 = EMA(TL3, pm4);}
if (GraphType == "Type3")					{ TL3 = LinearReg(PriceField, pm5); 	TL4 = EMA(TL3, pm6);}
if (GraphType == "Type4")					{ TL3 = LinearReg(PriceField, pm7); 	TL4 = EMA(TL3, pm8);}
if (GraphType == "Type5")					{ TL3 = LinearReg(PriceField, pm9); 	TL4 = EMA(TL3, pm10);}
if (GraphType == "Type6")					{ TL3 = LinearReg(PriceField, pm11); 	TL4 = EMA(TL3, pm12);}


Col1 = IIf(TL1 > TL2, ParamColor("TL1 Up Colour", colorBrightGreen), ParamColor("TL2 Dn Colour", colorCustom12));
Col2 = IIf(TL3 > TL4, ParamColor("TL3 Up Colour", colorBlue), ParamColor("TL4 Dn Colour", colorRed));


Plot(TL1, "TriggerLine 1", Col1, styleLine|styleThick|styleNoLabel);
Plot(TL2, "TriggerLine 2", Col1, styleLine|styleThick|styleNoLabel);

Plot(TL3, "TriggerLine 3", Col2, styleLine|styleThick|styleNoLabel);
Plot(TL4, "TriggerLine 4", Col2, styleLine|styleThick|styleNoLabel);


TimeFrameRestore();
_SECTION_END();

0 comments

Leave Comment

Please login here to leave a comment.

Back