extend line to the left

Questions about MultiCharts and user contributed studies.
User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

extend line to the left

Postby arnie » 20 May 2015

I'm having an issue here regarding extending a line to the left.
What am I missing? I'd like the line to extend to the first bar of the chart or at least 3 or 4 days ago, not only half of yesterday's.

Image

Code: Select all

inputs:
Color (white),
RightShift (50),
ExtendLeft (true),
ExtendRight (true);

variables:
firstBar (0),
intrabarpersist lastPrice (0);

if currentbar = 1 then
firstBar = currentbar;

lastPrice = close;

if ExtendLeft = true then begin
for value1 = 0 to (currentbar - firstBar) begin
plot1[value1](lastPrice,"lastPrice", Color);
end;
end;

if ExtendRight = true then begin
for value1 = 0 to RightShift begin
Plot1[-value1](lastPrice, "lastPrice", Color);
end;
end;

noplot(1);
Attachments
left_ext.png
(27.61 KiB) Downloaded 511 times

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

Re: extend line to the left

Postby JoshM » 20 May 2015

I'm having an issue here regarding extending a line to the left.
What am I missing? I'd like the line to extend to the first bar of the chart or at least 3 or 4 days ago, not only half of yesterday's.
It's due to MaxBarsBack of the indicator. When I change the following of your code:

Code: Select all

if (LastBarOnChart_s) then begin

if (ExtendLeft = true) then begin

Print("length: ", Symbol_Length, ", maxbarsback: ", MaxBarsBack);

for value1 = 0 to Symbol_Length - MaxBarsBack begin

plot1[value1](lastPrice, "lastPrice", Color);

end;

end;

end;
I get the following output:
length: 173.00 maxbarsback: 0.00
length: 173.00 maxbarsback: 6.00
length: 173.00 maxbarsback: 12.00
length: 173.00 maxbarsback: 21.00
length: 173.00 maxbarsback: 35.00
length: 173.00 maxbarsback: 58.00
length: 173.00 maxbarsback: 95.00
So MaxBarsBack automatically increments when set to Auto-detect (as it should). What I find odd, however, is that setting the MaxBarsBack setting explicitly to a low value (like 10), I get this output:
length: 174.00, maxbarsback: 10.00
length: 174.00, maxbarsback: 17.00
length: 174.00, maxbarsback: 29.00
length: 174.00, maxbarsback: 48.00
length: 174.00, maxbarsback: 79.00
length: 174.00, maxbarsback: 129.00
length: 174.00, maxbarsback: 129.00
length: 174.00, maxbarsback: 129.00
length: 174.00, maxbarsback: 129.00
That's odd because the script starts calculating with a MaxBarsBack of 10 (like I specified), but then automatically increments it exactly as specified in the documentation.

In this situation, I'd expect the script to throw the "Tried to reference back more bars. Please increase the Max Bars Back setting" error message, and not to override the manual setting.

(Although I might misunderstand how MaxBarsBack set to 'User Specified' should work).

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

Re: extend line to the left

Postby JoshM » 20 May 2015

Of course, we can always use a trend line to draw a line to the beginning of the chart, although that still requires a little gap for the `MaxBarsBack` value. I, at least, couldn't draw/update a trend line to the very first bar on the chart.

Code: Select all

Inputs:
Color(red),
RightShift(50),
ExtendLeft(true),
ExtendRight(true);

Variables:
intrabarpersist lastPrice(0),
pastLine(0), futureLine(0), barsBack(0);

if (CurrentBar = 2) then begin

pastLine = TL_New_s(Date[1], Time_s[1], Close[1],
Date, Time_s, Close);

TL_SetColor(pastLine, Color);

end;

lastPrice = close;

if (LastBarOnChart_s) then begin

barsBack = Symbol_Length - MaxBarsBack;

if (ExtendLeft = true) then begin

TL_SetEnd_s(pastLine, Date,
Time_s, lastPrice);

TL_SetBegin_s(pastLine, Symbol_Date[barsBack],
Symbol_Time_s[barsBack], lastPrice);

end;

end;
Image
Attachments
scr.20-05-2015 13.55.29.png
(8.96 KiB) Downloaded 505 times

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: extend line to the left

Postby arnie » 20 May 2015

Of course, we can always use a trend line to draw a line to the beginning of the chart,
The problem with the trendline is that annoying lag that exist between last price and when the trendline actualy move to the last price.
A line does not show that lag which is more suited for the purpose of this study.


Return to “MultiCharts”