Help: Reverse Bar Counter

Questions about MultiCharts and user contributed studies.
Spaceant
Posts: 254
Joined: 30 May 2009
Has thanked: 1 time
Been thanked: 3 times

Help: Reverse Bar Counter

Postby Spaceant » 02 Feb 2010

Hi,

If a chart of 100 bars are loaded,
Plot1(Currentbar)
The above will show the number of bars, with the current bar as 100 and the first bar loaded as 1.

Could anyone help me to code an indicator showing the reverse bar counter?

i.e. the current bar is always to be 1, instead of 100; while the first loaded bar to be 100 instead.

Thanks!

Sa

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

Postby TJ » 02 Feb 2010

this depends on what and how you want to use the "number".

you have to create a bar counter,
and a variable to store the count.
and a loop to recount the count.


making the current bar's count as #1 is easy...

however when a bar is incremented, the new bar becomes #1,
and the previous bar becomes #2.


are you using it for backtest?
or real time analysis?

will you only have 100 bars?
or only concerned with the latest 100 bars?



there are a number of ways to do it...
not all the method is applicable to all scenario.
understanding the intent would help.

Spaceant
Posts: 254
Joined: 30 May 2009
Has thanked: 1 time
Been thanked: 3 times

Postby Spaceant » 02 Feb 2010

TJ,

I have thought of using a loop to do it, but I don't want to as I am going to use it with more bars loaded. Using a loop will slow down the ting when the number increases.

There is a "valuewhen" function in Metastock that can be used to store the number (in this case, total number of bars loaded). I can't find any similar function in EL, that is why I seek your help.

Any possibility to plot it without using a loop function?

Sa
p/s I may use it in backtesting and then for realtime trading...

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

Postby TJ » 02 Feb 2010

a loop is not an absolute must...

it depends on how you want to use the count.
ie. how do you reference the previous bars' counts.


e.g.

the current count is #1
the previous count is #2
and so on...

you don't really need to know the total barnumber.

Spaceant
Posts: 254
Joined: 30 May 2009
Has thanked: 1 time
Been thanked: 3 times

Postby Spaceant » 02 Feb 2010

TJ,

Don't get it. Can you elaborate it in a code? Thanks!

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

Postby TJ » 02 Feb 2010

TJ,

Don't get it. Can you elaborate it in a code? Thanks!

how you structure the code is dependent on how you want to use the reverse count.

Spaceant
Posts: 254
Joined: 30 May 2009
Has thanked: 1 time
Been thanked: 3 times

Postby Spaceant » 03 Feb 2010

What I want to plot, say for a 100 bar chart, is that the current bar as 1, the previous bar as 2, then previous before previous is 3, ..... , so the first bar is 100.

I have tried various of ways, but failed.... TJ or others, pls give me a clue that I can do it....

Thanks

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

Postby TJ » 04 Feb 2010

I don't understand what you mean.
can you draw a mock up?

Spaceant
Posts: 254
Joined: 30 May 2009
Has thanked: 1 time
Been thanked: 3 times

Postby Spaceant » 04 Feb 2010

I don't understand what you mean.
can you draw a mock up?
Here is the chart showing the indicator that I want, chart plotted by Metastock, with 500 bars loaded.

Sa
Attachments
DOW JONES INDUSTRIAL AVERAGE IN.jpg
(212.05 KiB) Downloaded 758 times

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

Postby TJ » 04 Feb 2010

you are not describing your intention,
therefore it is difficult to give you specifics.

let me summarize my view:

1. if you just need a number... no loop is needed.

2. if you just need a line... it is easier to use TL_NEW

3. if you want to plot... you will need a loop, or even an array

3a. you will need to know in advance how many bars you want to reference. e.g. It is just not a good idea to plot 1 years of 1 min bars.

3b. are you re-starting the count at the beginning of every day? this requirement will make the code structured differently


anyway... this coding is more involving then I have time for. But you get an idea of what options/challenges are in front of you.

HTH


Return to “MultiCharts”