Plot Lowest indicator only at last 10 bars  [SOLVED]

Questions about MultiCharts and user contributed studies.
Dirk8
Posts: 26
Joined: 24 Mar 2014
Has thanked: 10 times
Been thanked: 1 time

Plot Lowest indicator only at last 10 bars

Postby Dirk8 » 29 Jan 2015

Hi,

I have an indicator that plots the lowest value of the close. Tough, it's plotted historical under every bar until the latest. I want it to be plotted only under the latest 10 bar.

Code: Select all

inputs: LengthA( 10 ), Displace( 0 ) ;
variables: var0( 0 ), var1( 0 ) ;

var0 = Lowest( Close, LengthA );

condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ;
if condition1 then
begin
Plot1[Displace]( var0, "Band_L_L" ) ;

end ;
Looked into the manual and searched on 'plot'. Nothing to find. It will need some EL-code
How can I do that?

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

Re: Plot Lowest indicator only at last 10 bars

Postby TJ » 29 Jan 2015

Hi,
I have an indicator that plots the lowest value of the close. Tough, it's plotted historical under every bar until the latest. I want it to be plotted only under the latest 10 bar.

Code: Select all

inputs: LengthA( 10 ), Displace( 0 ) ;
variables: var0( 0 ), var1( 0 ) ;

var0 = Lowest( Close, LengthA );

condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ;
if condition1 then
begin
Plot1[Displace]( var0, "Band_L_L" ) ;

end ;
Looked into the manual and searched on 'plot'. Nothing to find. It will need some EL-code
How can I do that?
please illustrate the problem with a screen shot.

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

Re: Plot Lowest indicator only at last 10 bars

Postby JoshM » 29 Jan 2015

Hi,

I have an indicator that plots the lowest value of the close. Tough, it's plotted historical under every bar until the latest. I want it to be plotted only under the latest 10 bar.

Code: Select all

inputs: LengthA( 10 ), Displace( 0 ) ;
variables: var0( 0 ), var1( 0 ) ;

var0 = Lowest( Close, LengthA );

condition1 = Displace >= 0 or CurrentBar > AbsValue( Displace ) ;
if condition1 then
begin
Plot1[Displace]( var0, "Band_L_L" ) ;

end ;
Looked into the manual and searched on 'plot'. Nothing to find. It will need some EL-code
How can I do that?
I think it might be related to your plot's displacement. While the input's `Displace` value defaults to 0, you didn't specify with which value you applied the indicator to the chart: if the input's value used is larger than 0, then that would explain "it's plotted historical under every bar until the latest".

See Plot for more on displacement (it's called 'offset' on that wiki page).

You could try the following code if you'd want to combine a plot that displaces with a regular plot:

Code: Select all

if (condition1) then begin

// Plot with no displacement when it's the
// last bar on the chart
if (LastBarOnChart_s) then
Plot1(var0, "Band_L_L")

// Plot with displacement when the bar isn't
// the last
else
Plot1[Displace](var0,"Band_L_L");

end;

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

Re: Plot Lowest indicator only at last 10 bars

Postby JoshM » 29 Jan 2015

I want it to be plotted only under the latest 10 bar.
I'm not really sure what your question is, because this sentence above is something quite different than your code (and the other part of your post) suggests.

But this address this part (see my post above for the displacement part): you'll need to create two loops for plotting the line on the last bars.

The first loop will remove the old plot (so that the line "moves" with the new bars being formed and doesn't remain "stuck" where it began), the second loop will then plot the newest values.

In code, that would look like the following:

Code: Select all

Input:
LengthLookback(10);

Variables:
lowestClose(0), x(0);

if (BarStatus(1) = 0) then begin

lowestClose = Lowest(Close, LengthLookback);

// Remove the old plot
for x = 0 to 10 begin

NoPlot[x](1);

end;

// Plot the new plot
for x = 0 to 9 begin

Plot1[x](lowestClose, "LowestLow");

end;

end;
This has the following effect:

Image
Attachments
scr.29-01-2015 15.26.26.png
(2.03 KiB) Downloaded 731 times

Dirk8
Posts: 26
Joined: 24 Mar 2014
Has thanked: 10 times
Been thanked: 1 time

Re: Plot Lowest indicator only at last 10 bars

Postby Dirk8 » 29 Jan 2015

Josh and TJ,

Included an image with the plot of the lowest value. It's plotted constantly. I want it to plot only under the latest x bars. Like the blue line that has been drawn.

In fact it's exact what's on the graph of Josh but when using the formula it does nothing.
Almost there I think.
Attachments
plot.JPG
(37.94 KiB) Downloaded 668 times
Last edited by Dirk8 on 29 Jan 2015, edited 1 time in total.

Dirk8
Posts: 26
Joined: 24 Mar 2014
Has thanked: 10 times
Been thanked: 1 time

Re: Plot Lowest indicator only at last 10 bars

Postby Dirk8 » 29 Jan 2015

Your formula should plot the same as on your chart isn't?

A copy/paste into the editor and after F3, this shows nothing on the chart.
That's strange.

---
After trying several times and looking at the parameters, it's now shown on the ES chart but when I try on another chart, it's nothing.

How comes that's it's not plotted instantly..?

---
When pressing F3 again, the indicator is gone

Dirk8
Posts: 26
Joined: 24 Mar 2014
Has thanked: 10 times
Been thanked: 1 time

Re: Plot Lowest indicator only at last 10 bars

Postby Dirk8 » 29 Jan 2015

When adding, the indicator is not plotted. When reloading the chart 1 or 2 days, then the indicator is (mostly) plotted.
Is there a reason why it's so hard to get that indicator on the chart?

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

Re: Plot Lowest indicator only at last 10 bars  [SOLVED]

Postby JoshM » 30 Jan 2015

Your formula should plot the same as on your chart isn't?

A copy/paste into the editor and after F3, this shows nothing on the chart.
That's strange.

---
After trying several times and looking at the parameters, it's now shown on the ES chart but when I try on another chart, it's nothing.

How comes that's it's not plotted instantly..?

---
When pressing F3 again, the indicator is gone
When adding, the indicator is not plotted. When reloading the chart 1 or 2 days, then the indicator is (mostly) plotted.
Is there a reason why it's so hard to get that indicator on the chart?
I'm not sure if I follow you, but did you notice in the code that the `lowestClose` value is calculated and plotted when `BarStatus(1) = 0`? That way the indicator doesn't recalculate, remove, and redraw itself on every tick, so that it doesn't "blink" on the chart with each tick.

That reason can also explain why it's not plotted instantaneous. But if you rather have it do that on every tick, you're free to change to code of course.

Perhaps this also highlights that copy/pasting code without understanding what it does isn't always the quickest solution.

Dirk8
Posts: 26
Joined: 24 Mar 2014
Has thanked: 10 times
Been thanked: 1 time

Re: Plot Lowest indicator only at last 10 bars

Postby Dirk8 » 30 Jan 2015

Indeed, copy/paste is sometimes a bit too easy but that's how i try to learn it. I'm a real starter.

Should have looked up the meaning of status bar. Changed it and it seems to work better now.

With this a can build further, thanks!


Return to “MultiCharts”