Get Trendline Values

#1
Hello there,

Is there any way in Amibroker to get the values (price and time) of the start and end point of a trendline as a reference for a trading system?
Any function that can be used for that?

Thanks
 

pkamalesh

Well-Known Member
#2
Hello there,

Is there any way in Amibroker to get the values (price and time) of the start and end point of a trendline as a reference for a trading system?
Any function that can be used for that?

Thanks
The start and end of a trend line is dependent on u brother...i mean u draw it from a particular low or high..there is no such application in any SW that gives auto trend lines..even if there are they arnt accurate..try learning the TL's from the gurus here...they can help..all the best
 
#3
Maybe I did not explain myself.
I draw a trendline in the chart. Then I need the value of that trendline at any given time in a system to trade based on the trendline I drew.
For example sell if price breaks below the trendline. But I do not know the price of the trendline when that happens because the trendline is not horizontal.
Is there any function that captures the price of a trendline at any point in time?
 

pkamalesh

Well-Known Member
#4
Oh kk...i dont know if there is any such system..but manually what u can do is u can draw a vertical line or a particular day and then u get the point where the TL will be broken on the higher or lower side that day..note those two points....
 
#5
Try this if if can help you out

_SECTION_BEGIN("Automatic Trend");
x = Cum(1);

perchg = 0.3*LastValue( Highest( ROC( Low, 50 ) ));

startvalue = LastValue( Trough( Low, perchg, 1 ) );
endvalue1 = LastValue( Trough( Low, perchg, 2 ) );

startbar = LastValue( ValueWhen( Low == startvalue, x, 1 ) );
endbar = LastValue( ValueWhen( Low == endvalue1, x, 1 ) );

Aa = (endvalue1-startvalue)/(endbar-startbar);
b = startvalue;

trendline = Aa * ( x - startbar ) + b;

Plot( Close, "Price", colorBlue, styleCandle );
Plot( IIf( x >= endbar, trendline, Null ), "Trendline", colorRed );
_SECTION_END();
 
#6
Can try this also,

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

_SECTION_BEGIN("Trend Line");

function GetXSupport(lLow, Percentage, Back)
{
return ((BarCount - 1) - LastValue(TroughBars(lLow, Percentage,Back)));
}
function GetYSupport(lLow, Percentage, Back)
{
return (LastValue(Trough(lLow, Percentage, back)));
}

function GetXResistance(hHigh, Percentage, Back)
{
return ((BarCount - 1) -LastValue(PeakBars(hHigh, Percentage, Back)));
}
function GetYResistance(hHigh, Percentage, Back)
{
return (LastValue(Peak(hHigh, Percentage, Back)));
}
////////////////////////////////////////////////////////////////////////
//Parameters
Percentage = Param("Percentage", 0.01, 0.01, 100. ,0.01);
Back = Param("How many lines?", 1, 1, BarCount-2);
DrawR = ParamToggle("Draw Resistance", "No|Yes", 1);
DrawS = ParamToggle("Draw Support", "No|Yes", 1);
Extend = ParamToggle("Extend Lines?", "No|Yes", 1);
DrawAllLines = ParamToggle("Draw All Lines?", "No|Yes", 1);
Main = C;
lLow = L;
hHigh = H;
////////////////////////////////////////////////////////////////////////
//Plotting Area
Plot(Main, "", colorGreen, styleCandle);
if(DrawAllLines)
for(i = 2; i<=Back+1; i++)
{
if(DrawS){
x0 = GetXSupport(lLow, Percentage, i);
x1 = GetXSupport(lLow, Percentage, i-1);
y0 = GetYSupport(lLow, Percentage, i);
y1 = GetYSupport(lLow, Percentage, i-1);
x = LineArray(x0, y0, x1, y1, Extend);
Plot(x, "Support", colorYellow, styleLine|styleDots|styleThick);
}
if(DrawR){
x0 = GetXResistance(hHigh , Percentage, i);
x1 = GetXResistance(hHigh , Percentage, i-1);
y0 = GetYResistance(hHigh , Percentage, i);
y1 = GetYResistance(hHigh , Percentage, i-1);
x = LineArray(x0, y0, x1, y1, Extend);
Plot(x, "Resistance", colorBlue , styleLine|styleDots|styleThick);
}
}
else
{
if(DrawS){
x0 = GetXSupport(lLow, Percentage, Back+1);
x1 = GetXSupport(lLow, Percentage, Back);
y0 = GetYSupport(lLow, Percentage, Back+1);
y1 = GetYSupport(lLow, Percentage, Back);
x = LineArray(x0, y0, x1, y1, Extend);
Plot(x, "Support", colorYellow, styleLine|styleDots|styleThick);
}
if(DrawR){
x0 = GetXResistance(hHigh , Percentage, Back+1);
x1 = GetXResistance(hHigh , Percentage, Back);
y0 = GetYResistance(hHigh , Percentage, Back+1);
y1 = GetYResistance(hHigh , Percentage, Back);
x = LineArray(x0, y0, x1, y1, Extend);
Plot(x, "Resistance", colorBlue , styleLine|styleDots|styleThick);
}
}


regards
Antony
 
#7
Hello there,

Is there any way in Amibroker to get the values (price and time) of the start and end point of a trendline as a reference for a trading system?
Any function that can be used for that?

Thanks
Hello,

Draw a trend line in AmiBroker as per your requirement and give it some name, say TL by right-clicking and going into its properties, in Study ID text box. Make sure that the trend line is right extended in case you want to check its break for some action.

Then edit AFL of the chart where you have drawn this trend line and add following code :

Sell = Cross(C, Study("TL", GetChartID()));

You may also mention a filter with above condition and check it every 1 min (or whatever duration you want) in Automatic Analysis Window by selecting Run Every : check box and filling in appropriate time period. You may mention condition for Exploration as below.

Filter = Cross(C, Study("TL", GetChartID()));

Further, you can add audible alert when this condition is reached by inserting this code.

AlertIF( Sell, "SOUND C:\\Windows\\Media\\Ding.wav", "Audio alert", 2 );
Ensure that Ding.wav file really exists in your Windows\media folder. :)

You may check User Guide of AmiBroker for explanation on each of these topic.

Important : AmiBroker comes with 900+ pages User Guide in which, explanation for each and every function, feature, usage examples is given and it is accessible by pressing F1.

I hope this helps.

Best regards,

AmiBroker-India
 

Similar threads