Monday – Friday : 9:00 AM – 6:30 PM

Constant Trendline Plot

 Amibroker data feed, even if obtained for free, can be used to create a constant trendline plot. Traders can utilize AFL to draw and analyze trendlines that remain consistent, providing a reference point for price movements. This is particularly useful for technical analysis, helping traders identify and react to key support and resistance levels effectively.

_SECTION_BEGIN("Constant Trendline Plot");
/*THIS IS A TECHNIQUE FOR DRAWING TRENDLINES EVERYWHERE ON A CHART WITHOUT A LOOPING FORMULA.  I developed this technique because, as far as I could tell, the trendline methods made readily available in Amibroker (e.g. the example in the LinReg formula in AFL reference section of help), are limited in that they can either plot only one trendline, or must be called by a looping formula. This is simply an alternative to a looping formula, and I think it is a pretty good method for plotting trendlines.  My code plots a trendline between troughs of Perchg size.  The line you see on the chart is an extension of a trendline starting at the low of the trough one trough prior to the one where the line begins.  A new trendline is drawn every time a new trough occurs.  There are lots of possible variations on this code and refinements which could define the trend more precisely and more robustly.*/


Perchg = 10;
//Bars since current trough
Length1 = TroughBars(L,Perchg,1);
//Bars since prev trough
Length2 = TroughBars(L,Perchg,2);

DistBetTroughs = Length2 - Length1;


PriceDiff = Trough(L,Perchg,1) - Trough(L,Perchg,2);


Slope = PriceDiff/DistBetTroughs;

Trendline = (Length2 * Slope) + Trough(L,Perchg,2);

PlotOHLC( Open, High, Low, Close, "Price", colorBrown,styleCandle); 

Open chat
Hi, how can I help you?