Simple Coding Help - No Promise.

Sir just use this code and double click on drawn line and give study id as ZZ, you will see angle of drawn line in Title. :)

Code:
drawnline = Study( "ZZ", GetChartID() );

x0 = LastValue( ValueWhen( ExRem( drawnline, 0 ), BarIndex() ) );
x1 = LastValue( ValueWhen( drawnline, BarIndex() ) );
y0 = LastValue( ValueWhen( ExRem( drawnline, 0 ), drawnline ) );
y1 = LastValue( ValueWhen( drawnline, drawnline ) );

if( x0 != 0 )
{
    slope = ( y1 - y0 ) / ( x1 - x0 );
    angle = atan( slope );
    angle_in_degrees = angle * 180 / 3.14 ;

    Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) + "\nAngle of drawn line is " + angle_in_degrees + " °";
}

Good Luck :)
:up:

Instead of Title we can also use Gfx for display


.
 

MSN1979

Well-Known Member
Sir just use this code and double click on drawn line and give study id as ZZ, you will see angle of drawn line in Title. :)

Code:
drawnline = Study( "ZZ", GetChartID() );

x0 = LastValue( ValueWhen( ExRem( drawnline, 0 ), BarIndex() ) );
x1 = LastValue( ValueWhen( drawnline, BarIndex() ) );
y0 = LastValue( ValueWhen( ExRem( drawnline, 0 ), drawnline ) );
y1 = LastValue( ValueWhen( drawnline, drawnline ) );

if( x0 != 0 )
{
    slope = ( y1 - y0 ) / ( x1 - x0 );
    angle = atan( slope );
    angle_in_degrees = angle * 180 / 3.14 ;

    Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) + "\nAngle of drawn line is " + angle_in_degrees + " °";
}

Good Luck :)

Thank you so much, you are a genius
 

yusi

Well-Known Member
Code:
    slope = ( y1 - y0 ) / ( x1 - x0 );
Got to wondering if this was actionable. A Rs 300 stock rising to 310 over 11 bars would be 45 degrees. So would a Rs 1000 scrip rising to 1010 over the same period.

Perhaps an angle in terms of percentages is more appropriate (given that the angle is for x and y in different units) :

Code:
    slope = ( someMultiple * ( y1 - y0 ) / y0 ) / ( x1 - x0 );
 

trash

Well-Known Member
Sir just use this code and double click on drawn line and give study id as ZZ, you will see angle of drawn line in Title. :)

Code:
drawnline = Study( "ZZ", GetChartID() );

x0 = LastValue( ValueWhen( ExRem( drawnline, 0 ), BarIndex() ) );
x1 = LastValue( ValueWhen( drawnline, BarIndex() ) );
y0 = LastValue( ValueWhen( ExRem( drawnline, 0 ), drawnline ) );
y1 = LastValue( ValueWhen( drawnline, drawnline ) );

if( x0 != 0 )
{
    slope = ( y1 - y0 ) / ( x1 - x0 );
    angle = atan( slope );
    angle_in_degrees = angle * 180 / 3.14 ;

    Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) + "\nAngle of drawn line is " + angle_in_degrees + " °";
}

Good Luck :)

Still copying material from other websites and making it look like as it is based from your brain, you piece of a joke??

https://www.amibroker.com/kb/2006/03/07/getting-x-y-co-ordinates-of-study/
https://forum.amibroker.com/t/atan-returning-radians-and-i-need-degrees/4973
etc....
 

Similar threads

Broker Special Offers

Intraday Higher Leverage

Save up to 90% in brokerage and get higher leverage for intraday trades.

Name:Phone:
Email:City:
State:
Are you a day trader?