I have left amibroker quite some time back. But here's something for you.
The program tries to find out the trend in different periods, long term by 140 days, medium by 60 days and short term by 8 days.
Filter = 1; // all symbols and quotes accepted.
DTL=140; // DTL = Define Trend Long Self explanatory
DTM=60; // DTM = Define Trend Medium Self explanatory
DTS=8; // DTS = Define Trend Short Self explanatory
//////////////////////////////////////////////////////////////
TL=LinRegSlope(MA(C, DTL),2); // TL = Trend Long This is the Linear Regression Slope of a simple moving average of the long term trend period, here 140 days
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); This checks whether linear Reg skope is > 0, ie uptrend
TMM=IIf(LinRegSlope(MA(C, DTM),2) > 0,True, False);
TSS=IIf(LinRegSlope(MA(C, DTS),2) > 0,True, False);
This checks the strength of the trend by checking the long term LinRegSlope and assigning +, ++ and +++ according to the defined threshold
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,"- - -",""))))));
Same for medium term and eventually short term
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,"- - -",""))))));
//////////////////////////////////////////////////////////////
This is the output of the exploration. here along with the Strength, the color is decided using the direction of the trend
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 );
//////////////////////////////////////////////////////////////
Here the message in an exploration col output defines the trend
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 );
//////////////////////////////////////////////////////////////
This is the part where the program is pointing whether the trend id starting, or mature etc
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 );
//////////////////////////////////////////////////////////////