How to plot an indy just in the last 10 bars of chart

Questions about MultiCharts and user contributed studies.
earmarques
Posts: 13
Joined: 07 Dec 2013
Has thanked: 1 time
Been thanked: 1 time

How to plot an indy just in the last 10 bars of chart

Postby earmarques » 01 Mar 2014

Hi, who knows how can I plot an indicator only by the last x bars? This means that in each bar, in real time I need to know how many bars are in the chart to calculate if the current bar is in the last 10 or x bars.

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

Re: How to plot an indy just in the last 10 bars of chart

Postby TJ » 01 Mar 2014

Hi, who knows how can I plot an indicator only by the last x bars? This means that in each bar, in real time I need to know how many bars are in the chart to calculate if the current bar is in the last 10 or x bars.
That's a mouthful...

please draw a diagram to illustrate your vision.

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

Re: How to plot an indy just in the last 10 bars of chart

Postby JoshM » 01 Mar 2014

(...) This means that in each bar, in real time I need to know how many bars are in the chart to calculate if the current bar is in the last 10 or x bars.
Symbol_Length returns the amount of bars on the chart; CurrentBar the current bar number. And you can use GetAppInfo to differentiate between historical and real-time data.

As to how to program this, you might want to try TJ's advice. That can save you a lot of time and headaches. :]

evdl
Posts: 401
Joined: 19 Jan 2011
Location: Netherlands
Has thanked: 85 times
Been thanked: 124 times

Re: How to plot an indy just in the last 10 bars of chart

Postby evdl » 01 Mar 2014

Code: Select all

{can only be used with time based charts (not tickcharts, because the amount of bars is different every day).

Example: minute chart and RTH is 8,5 hours. Then the total amount of bars per day is 510

}

Inputs:
Total_bars(510),
Amount_x_lastbars(10);

Vars:
Bar_count_today(0),
Bar_counter(0),
Count_down_bars(0);


// calculate amount of bars during the day
If barstatus(1) = 2 then begin
Bar_count_today = Bar_count_today + 1;
end;

// reset barcount at the beginning of every day
If date <> date[1] then begin
Bar_count_today = 0;
end;

// set bar count to a variable
Bar_counter = Bar_count_today;

// calculate the bar to start plotting
Count_down_bars = Total_bars - bar_counter;

If count_down_bars <= Amount_x_lastbars then begin

//Plot (your indicator)

end;
Maybe this can get you started (not tested though).

Good luck.

earmarques
Posts: 13
Joined: 07 Dec 2013
Has thanked: 1 time
Been thanked: 1 time

Re: How to plot an indy just in the last 10 bars of chart

Postby earmarques » 01 Mar 2014

Thanks. That's what I was looking for. The function that returns the total bars in the chart!


Return to “MultiCharts”