LastBarOnChart_s & vertical lines conflict?

Questions about MultiCharts and user contributed studies.
User avatar
JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1527 times
Been thanked: 1502 times
Contact:

LastBarOnChart_s & vertical lines conflict?

Postby JoshM » 02 May 2012

Is this expected behaviour?

This code..

Code: Select all

variables:
   trendLine1(0);
   
once begin
   trendLine1 = TL_New(0,0,0,0,0,0);
   cleardebug;
end;

if (LastBarOnChart_s = True) then begin

   Print("Id of 'trendLine1'? ", trendLine1);

   value1 = TL_SetBegin(trendLine1, Date, 1100, 2422);
   Print("Error message of SetBegin? ", value1);

   value2 = TL_SetEnd(trendLine1, Date, 1100, 2432);
   Print("Error message of SetEnd? ", value2);

end;


..gives these outputs:

Code: Select all

Id of 'trendLine1'?    2.00
Error message of SetBegin?    0.00
Error message of SetEnd?    0.00


Image

But removing the LastBarOnChart_s segment, with otherwise the same settings and code (MC 7.4 Build 4906):

Code: Select all

variables:
   trendLine1(0);
   
once begin
   trendLine1 = TL_New(0,0,0,0,0,0);
   cleardebug;
end;

Print("Id of 'trendLine1'? ", trendLine1);

value1 = TL_SetBegin(trendLine1, Date, 1100, 2422);
Print("Error message of SetBegin? ", value1);

value2 = TL_SetEnd(trendLine1, Date, 1100, 2432);
Print("Error message of SetEnd? ", value2);


..gives these outputs:

Code: Select all

Id of 'trendLine1'?    2.00
Error message of SetBegin?    0.00
Error message of SetEnd?    0.00
Id of 'trendLine1'?    2.00
Error message of SetBegin?    0.00
Error message of SetEnd?    0.00
Id of 'trendLine1'?    2.00
Error message of SetBegin?    0.00
Error message of SetEnd?    0.00
Id of 'trendLine1'?    2.00
Error message of SetBegin?    0.00
Error message of SetEnd?    0.00
..and so on


Image

In other words, TL_SetEnd & TL_SetBegin doesn't seems to work with LastBarOnChart_s? Which is a shame, since it's needless computer intensive to move the vertical line every bar if it's only needed on the last bar (especially if one aims to make multiple vertical lines).

Or am I doing something wrong?
Attachments
scr.02-05-2012 11.10.24.png
scr.02-05-2012 11.10.24.png (1.41 KiB) Viewed 922 times
scr.02-05-2012 11.05.42.png
scr.02-05-2012 11.05.42.png (1.34 KiB) Viewed 817 times

SP
Posts: 453
Joined: 06 Feb 2006
Has thanked: 36 times
Been thanked: 283 times

Re: LastBarOnChart_s & vertical lines conflict?

Postby SP » 02 May 2012

Josh,

not sure if it solves it, but if i use LastBarOnChart_s then i use time_s, TL_New_s, TL_SetBegin_S and TL_SetEnd_S and if i use LastBarOnChart then i use time, TL_New, TL_SetBegin and
TL_SetEnd.
These users thanked the author SP for the post:
JoshM

User avatar
JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1527 times
Been thanked: 1502 times
Contact:

Re: LastBarOnChart_s & vertical lines conflict?

Postby JoshM » 02 May 2012

SP wrote:not sure if it solves it, but if i use LastBarOnChart_s then i use time_s, TL_New_s, TL_SetBegin_S and TL_SetEnd_S and if i use LastBarOnChart then i use time, TL_New, TL_SetBegin and TL_SetEnd.

Thanks SP, that's not a bad idea. :)

But using '_s' in trend line drawing gives the same problem as in the first post (namely one point of the line is correct, the other wrong, getting a diagonal line) with this code:

Code: Select all

variables:
   trendLine1(0);
   
once begin
   trendLine1 = TL_New(0,0,0,0,0,0);
   cleardebug;
end;

if (LastBarOnChart_s = True) then begin

   Print("Id of 'trendLine1'? ", trendLine1);

   value1 = TL_SetBegin_s(trendLine1, Date, 130000, 2422);
   Print("Error message of SetBegin? ", value1);

   value2 = TL_SetEnd_s(trendLine1, Date, 130000, 2432);
   Print("Error message of SetEnd? ", value2);

end;


If I look at the drawing (with Format Drawings), then the SetBegin/SetBegin_s set the line, when LastBarOnChart_s is used, to 1900.

(Screenshot generated with the code above in this post)
Image

If LastBarOnChart_s is not used, then the date isn't set to 1900 and the line has it's correct date time coordinates.
Attachments
scr.02-05-2012 12.51.21.png
scr.02-05-2012 12.51.21.png (34.43 KiB) Viewed 775 times

User avatar
TJ
Posts: 7151
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 988 times
Been thanked: 2041 times

Re: LastBarOnChart_s & vertical lines conflict?

Postby TJ » 02 May 2012

JoshM wrote:Is this expected behaviour?
...

Or am I doing something wrong?


What is your chart resolution?

User avatar
TJ
Posts: 7151
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 988 times
Been thanked: 2041 times

Re: LastBarOnChart_s & vertical lines conflict?

Postby TJ » 02 May 2012

Image

Can you label which is the TL begin and which is the TL end?


Once you have done that, you might see your answer.

User avatar
JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1527 times
Been thanked: 1502 times
Contact:

Re: LastBarOnChart_s & vertical lines conflict?

Postby JoshM » 02 May 2012

TJ wrote:What is your chart resolution?

A 5 minute chart.

TJ wrote:Can you label which is the TL begin and which is the TL end?

Once you have done that, you might see your answer.

I've set the lowest point to TL_SetBegin, since according to the wiki:
If the trendline is vertical, the point with the lower price value is considered to be the starting point.

However, if I change this (so giving TL_SetBegin the highest value), it still doesn't work correctly.

For example, with all posibilities of the use of SetBegin/SetEnd and LastBarOnChart_s, I still get this:

Image

Where:
* red: lowest value as Begin, LastBarOnChart,
* cyan: highest value as Begin, LastBarOnChart,
* yellow: lowest value as Begin
* green: highest value as Begin

Code:

Code: Select all

variables:
   trendLine1(0), trendLine2(0), trendLine3(0), trendLine4(0);
   
once begin
   trendLine1 = TL_New_s(0,0,0,0,0,0);
   trendLine2 = TL_New_s(0,0,0,0,0,0);
   trendLine3 = TL_New_s(0,0,0,0,0,0);
   trendLine4 = TL_New_s(0,0,0,0,0,0);   
end;

// Plotting with LastBarOnChart_s
if (LastBarOnChart_s = True) then begin

   // Begin with the lowest value
   value1 = TL_SetBegin_s(trendLine1, Date, 123000, 2420);
   value2 = TL_SetEnd_s(trendLine1, Date, 123000, 2430);
   value3 = TL_SetColor(trendLine1, red);
   
   // Begin with highest value
   value11 = TL_SetBegin_s(trendLine2, Date, 124000, 2430);
   value12 = TL_SetEnd_s(trendLine2, Date, 124000, 2420);
   value13 = TL_SetColor(trendLine2, cyan);
end;

// Now without LastBarOnChart_s
// .. Begin with lowest value
value21 = TL_SetBegin_s(trendLine3, Date, 125000, 2420);
value22 = TL_SetEnd_s(trendLine3, Date, 125000, 2430);
value23 = TL_SetColor(trendLine3, yellow);

// .. Begin with highest value
value31 = TL_SetBegin_s(trendLine4, Date, 130000, 2420);
value32 = TL_SetEnd_s(trendLine4, Date, 130000, 2430);
value33 = TL_SetColor(trendLine4, green);


What am I doing wrong here? It seems that it doesn't work with LastBarOnChart_s.
Attachments
scr.02-05-2012 15.13.57.png
scr.02-05-2012 15.13.57.png (2.77 KiB) Viewed 760 times

User avatar
TJ
Posts: 7151
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 988 times
Been thanked: 2041 times

Re: LastBarOnChart_s & vertical lines conflict?

Postby TJ » 02 May 2012

JoshM wrote:...
I've set the lowest point to TL_SetBegin, since according to the wiki:
If the trendline is vertical, the point with the lower price value is considered to be the starting point.

However, if I change this (so giving TL_SetBegin the highest value), it still doesn't work correctly.
...
What am I doing wrong here? It seems that it doesn't work with LastBarOnChart_s.


Maybe I was not clear on the labelling.

On your chart, label one end of the line "A", and the other end "B".
Then identify whether "A" is beginning or end.


then see the code you have below...

Code: Select all

value1 = TL_SetBegin_s(trendLine1, Date, ....
value2 = TL_SetEnd_s(trendLine1, Date, ....


can you create another chart at the moment AFTER the first statement is executed, but before the 2nd statement is executed, and identify which is the begin and which is the end?
These users thanked the author TJ for the post:
JoshM

User avatar
JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1527 times
Been thanked: 1502 times
Contact:

Re: LastBarOnChart_s & vertical lines conflict?

Postby JoshM » 02 May 2012

TJ wrote:On your chart, label one end of the line "A", and the other end "B".
Then identify whether "A" is beginning or end.

(..)

can you create another chart at the moment AFTER the first statement is executed, but before the 2nd statement is executed, and identify which is the begin and which is the end?

Thanks TJ! :)

It turns out that..

    If you use LastBarOnChart(_s), you first need to use TL_SetEnd(_s) before using TL_SetBegin(_s). Without LastBarOnChart, it doesn't matter which function is called first.

I don't know why this is - but now it works:

Code: Select all

variables:
   trendLine1(0);
   
once begin
   trendLine1 = TL_New_s(0,0,0,0,0,0);
end;

if (LastBarOnChart_s = True) then begin

   value2 = TL_SetEnd_s(trendLine1, Date, 123000, 2430);
   value1 = TL_SetBegin_s(trendLine1, Date, 123000, 2420);
   value3 = TL_SetColor(trendLine1, red);
   
end;


Image

Thanks both TJ & SP for your help. :)
Attachments
scr.02-05-2012 16.47.31.png
scr.02-05-2012 16.47.31.png (1.62 KiB) Viewed 783 times

User avatar
TJ
Posts: 7151
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 988 times
Been thanked: 2041 times

Re: LastBarOnChart_s & vertical lines conflict?

Postby TJ » 02 May 2012

JoshM wrote:Thanks TJ! :)

It turns out that..

    If you use LastBarOnChart(_s), you first need to use TL_SetEnd(_s) before using TL_SetBegin(_s). Without LastBarOnChart, it doesn't matter which function is called first.

I don't know why this is - but now it works:
...
Thanks both TJ & SP for your help. :)


it has nothing to do with LastBarOnChart.


Whenever you move a line... always move the end point first.

User avatar
JoshM
Posts: 2099
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1527 times
Been thanked: 1502 times
Contact:

Re: LastBarOnChart_s & vertical lines conflict?

Postby JoshM » 02 May 2012

TJ wrote:it has nothing to do with LastBarOnChart.

Whenever you move a line... always move the end point first.

Something I and the Wiki didn't know, but I've added it to the wiki now - hopefully that saves someone else some grey hairs. :)

User avatar
TJ
Posts: 7151
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 988 times
Been thanked: 2041 times

Re: LastBarOnChart_s & vertical lines conflict?

Postby TJ » 02 May 2012

JoshM wrote:
TJ wrote:it has nothing to do with LastBarOnChart.

Whenever you move a line... always move the end point first.

Something I and the Wiki didn't know, but I've added it to the wiki now - hopefully that saves someone else some grey hairs. :)


it is simply logic...

When you move the beginning of a line forward,
that beginning point becomes a temporary "end" point.

When you try to move the end point forward,
you were actually moving your new "beginning" point.

When that move does not turn out as one expected,
people tend to think there is a bug.


Image

[tag] trendline setbegin setend
Attachments
TL_SETBEGIN.jpg
TL_SETBEGIN.jpg (16.83 KiB) Viewed 730 times
These users thanked the author TJ for the post (total 2):
JoshMarjfca

bowlesj3
Posts: 2090
Joined: 21 Jul 2007
Has thanked: 197 times
Been thanked: 416 times

Re: LastBarOnChart_s & vertical lines conflict?

Postby bowlesj3 » 02 May 2012

Try this function I wrote. It figures out the logic for all combinations possible.
It is the last zip I placed in this thread.
It does not matter if you created with tl_new_self or just tl_new.
Create lines on bar #1 if you can and move them from that point on.
There is a minute bars version and a second bars version.
Since I wrote this moving trend lines has been easy and I have only seen a bad move maybe 2 times in the last year (considering that is probably a million or more moves that is not bad). I have this in every study now and I use a lot of lines and most are being moved on every new bar. It is a lot better than having to figure it out every time (that is what programs are for).

viewtopic.php?f=5&t=7748&hilit=movetrendline
These users thanked the author bowlesj3 for the post:
JoshM


Return to “MultiCharts”