Drawing trendlines in EasyLanguage [SOLVED]

Questions about MultiCharts and user contributed studies.
biffhero
Posts: 47
Joined: 22 Sep 2020
Has thanked: 29 times
Been thanked: 7 times

Drawing trendlines in EasyLanguage [SOLVED]

Postby biffhero » 30 Oct 2020

I have found the TL_New command, and I'm trying to use it in a loop, to draw lines on my $TICK chart.

Here is my code.

Code: Select all

{ Plot horizontal lines at places on the $TICK chart. } Inputs: doPlus1200(1), doPlus1000(1), doPlus800(1), doPlus600(1), doPlus0(1), doMinus600(1), doMinus800(1), doMinus1000(1), doMinus1200(1), plus1200(1200), plus1000(1000), plus800(800), plus600(600), plus0(0), minus600(-600), minus800(-800), minus1000(-1000), minus1200(-1200); Array: tickLines[8,2](0); Variables: j(0), k(0), maxArraySize(100), firstDate(0), secondDate(0), tlid1(-1), tlid2(-1); tickLines[0,0] = doPlus1200; tickLines[1,0] = doPlus1000; tickLines[2,0] = doPlus800; tickLines[3,0] = doPlus600; tickLines[4,0] = doPlus0; tickLines[5,0] = doMinus600; tickLines[6,0] = doMinus800; tickLines[7,0] = doMinus1000; tickLines[8,0] = doMinus1200; tickLines[0,1] = plus1200; tickLines[1,1] = plus1000; tickLines[2,1] = plus800; tickLines[3,1] = plus600; tickLines[4,1] = plus0; tickLines[5,1] = minus600; tickLines[6,1] = minus800; tickLines[7,1] = minus1000; tickLines[8,1] = minus1200; tickLines[0,2] = blue; tickLines[1,2] = blue; tickLines[2,2] = blue; tickLines[3,2] = blue; tickLines[4,2] = white; tickLines[5,2] = red; tickLines[6,2] = red; tickLines[7,2] = red; tickLines[8,2] = red; firstDate = 1201001; secondDate = 1201231; for j = 0 to 8 begin if (tickLines[j, 0] = 1) then TL_New(firstDate, 0000, tickLines[j, 1], secondDate, 2359, tickLines[j, 1]); k = TL_New(firstDate, 0000, tickLines[j, 1], secondDate, 2359, tickLines[j, 1]); TL_setColor(k, tickLines[j, 2]); end;
Here are my questions.

1. How do I set firstDate to be the first date on this chart? I have tried numerous things, none of them work.

2. How do I get the ID of the lines? The way I'm doing it here is ... interesting, where it's a throwaway. Can I get ahold of those outside of this loop? I suppose I could have j, 3 to hold that value...

Thank you,
Rob
Last edited by biffhero on 14 Nov 2020, edited 1 time in total.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Drawing trendlines in EasyLanguage

Postby TJ » 30 Oct 2020

Well . . . you have wrapped yourself too deep.

You should try something simpler first.

Draw a diagram -- how do you want the line to look like on a chart.
What are the criteria for the line?

Let's start from there.

Forget about the array for now.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Drawing trendlines in EasyLanguage

Postby JoshM » 31 Oct 2020

1. How do I set firstDate to be the first date on this chart? I have tried numerous things, none of them work.
You can use the `Symbol_Date` variable to get the date for any bar of the data series, including the first (beyond the script's MaxBarsBack).

Code: Select all

Symbol_Date[Symbol_CurrentBar - 1]
2. How do I get the ID of the lines? The way I'm doing it here is ... interesting, where it's a throwaway. Can I get ahold of those outside of this loop? I suppose I could have j, 3 to hold that value...
The ID of a trend line is returned by the function that makes the line. Usually you don't want to throw that value away, since you'll need it later to access/modify the line. In your case I would put those inside a dynamic array (populated inside the loop), so that after the loop ends, you still have access to your collection of trend lines.

biffhero
Posts: 47
Joined: 22 Sep 2020
Has thanked: 29 times
Been thanked: 7 times

Re: Drawing trendlines in EasyLanguage

Postby biffhero » 14 Nov 2020

In your case I would put those inside a dynamic array (populated inside the loop), so that after the loop ends, you still have access to your collection of trend lines.
Yes, this is what I did, save for the dynamic part. Thank you for the help.

Rob


Return to “MultiCharts”