how to plot amibroker diagonal line?

onlinegtrash

Well-Known Member
#1
Code:
SELL  09:18:08  at 8421.85  
Exit   11:05:52  at 8380.00
That's my trade, with entry and exit... I want to plot a line in Amibroker through AFL.. instead of manually click and drag the trend line tool.... how to do that?

Thanks!
 

mastermind007

Well-Known Member
#2
Code:
SELL  09:18:08  at 8421.85  
Exit   11:05:52  at 8380.00
That's my trade, with entry and exit... I want to plot a line in Amibroker through AFL.. instead of manually click and drag the trend line tool.... how to do that?

Thanks!
Code:
Plot(LineArray(SelectedValue(ValueWhen(TimeNum() == 091808, BarIndex())),8421.85,SelectedValue(ValueWhen(TimeNum() == 110552, BarIndex())), 8380, 0, False), "Trade Line", colorBlack, styleLine);
 
Last edited:

trash

Well-Known Member
#4
It partly works... but it's not properly working with out date.. specified...
How to add proper date in the above code?
There is no date specified in post #1. You have to know yourself what date your trade was executed.

So either add Datenum condition that includes Now(3) function or whatever (like manual input date). Look up in documentation what Now(3) means.

Also since your Timenum values include seconds the trades will be visible in 1-seconds or tick interval only. So in order to make trades visible in other intervals like hourly etc too you have to create a function that rounds the defined timenum value to currently selected interval (You have to find out content of roundtointerval function yourself. I won't tell.).

Understood?

No? OK.


Code:
function RoundToInterval( TimeValue ) { 

    // ....
    // you have to find out content yourself
    // ....

    result = Hours + NewMinutes * 10000;
    return result;
}


function dtconvert( mydate, mytime ) {
    return DateTimeConvert( 2, mydate, RoundtoInterval(mytime) );
}

bp = 1.0925;
date1 = 1150716;
time1 = 091808;

sp = 1.0885;
date2 = date1;
time2 = 130552;

tn = TimeNum();
bi = BarIndex();
dt = DateTime();

x0 = LastValue(ValueWhen(dt == dtconvert( date1, time1 ), bi));
y0 = bp;

x1 = LastValue(ValueWhen(dt == dtconvert( date2, time2 ), bi));
y1 = sp;

myline = LineArray( x0, y0, x1, y1, 0, False );

Plot( myline, "Trade Line", colorRed, styleLine, Null, Null, 0, 1, 0 );
Plot( C, "Price", colorDefault, styleCandle );

Title = StrFormat( "{{INTERVAL}} - {{DATE}} - Buy time: %06.0f, Sell time: %06.0f", time1, time2 );
 

onlinegtrash

Well-Known Member
#5
Hey Trash,

Thanks for your inputs, will tryout this evening...

I couldn't resist saying this, you have a great taste in selecting username!

Thanks!
 

Similar threads

Zerodha – Open Paperless Account

Open online account with Zerodha. Free delivery trading and Max Rs 20 for Intraday, F&O, Currency and Commodity Trading. Intraday High leverage with MIS, CO and BO.

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