How to plot an indy just in the last 10 bars of chart
-
- 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
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.
- TJ
- Posts: 7743
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2222 times
Re: How to plot an indy just in the last 10 bars of chart
That's a mouthful...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.
please draw a diagram to illustrate your vision.
- 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
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.(...) 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.
As to how to program this, you might want to try TJ's advice. That can save you a lot of time and headaches. :]
-
- Posts: 401
- Joined: 19 Jan 2011
- Location: Netherlands
- Has thanked: 85 times
- Been thanked: 125 times
Re: How to plot an indy just in the last 10 bars of chart
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;
Good luck.
-
- 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
Thanks. That's what I was looking for. The function that returns the total bars in the chart!