Recognize the "last value" of a data array from any bar

Questions about MultiCharts and user contributed studies.
OZ Trade
Posts: 39
Joined: 08 Nov 2013
Has thanked: 11 times
Been thanked: 18 times

Recognize the "last value" of a data array from any bar

Postby OZ Trade » 01 Jan 2014

Hi,

I know Multicharts can simply recognize the lastcalcdate and lastcalctime from any previous bar on a chart.. but is there a way to simply recognize the last value (value at last bar) of some data array from any previous bar, whether it be a bar value (OHLCV) or the value of a function.

Metastock for instance had the function: LastValue(data array)

Thank you and Happy New Year

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Recognize the "last value" of a data array from any bar

Postby bowlesj3 » 01 Jan 2014

Your questions tend to suggest you do not fully understand how MC works yet.

lastcalcdate and lastcalctime get you the values of the "lastBarOnChart" before that bar is actually processed. In other words while processing CurrentBar = 1 you can look ahead using these two functions to get the date and time of the very last bar on the chart (in other words before the code that will be processed if it is within an if statement that contains LastBarOnChart). There is no help for these commands nor are they in the wiki (not sure why). They are functions that come with MC. So how does MC do this. It has the data for the charts in memory (showing on the screen) then one by one it executes each study bar by bar to process the chart which is in memory(on the screen) until it completes the last bar on the chart and from then on as each tick comes in MC will process the code within the LastBarOnChart if command (plus any code that is not restricted to historic bars in some way). Here is an easy way to understand it. Lets say you have 10 studies applied to a chart. If you issue a recalculate command to one of these studies the chart is still there on your screen but the study is restarted so it goes back and executes currentbar = 1 code for the first bar and then every bar after that until LastBarOnChart. When MC first starts up it has to get the data from where ever and put it on the chart then once this is done it will execute the studies in alphabetical order to get them all processing the data on that chart then Once it does this as each tick comes in it will again process each of these studies one by one in alphabetical order. I do not really remember reading this in any manual. I just kind of thought about it and figured it out.

As far as getting the last element of an array it is a good idea to have an arraysize index and you just reference it with the array itself. by having such an index if you want to increase the size of this array (a fixed array) you just change the array and the arraysize index and your change is done. If you are loading an array up to some max index value (not loading the whole array every time) you would have an index for this and you reference the array with this index. Maybe it could be called ArrayLastIndexLoaded so it is really easy to remember what this means.

I assume you know to get data from the previous bar using Close[1].

If you want to really learn MC well, this link is worth reading. I do not use all of MC but for the areas that I do use, I have done most of it but I would like to find time to do it all again.
MultiCharts/EasyLanguage learning strategies
viewtopic.php?f=5&t=11741

OZ Trade
Posts: 39
Joined: 08 Nov 2013
Has thanked: 11 times
Been thanked: 18 times

Re: Recognize the "last value" of a data array from any bar

Postby OZ Trade » 01 Jan 2014

Thanks for the reply..

Sorry to give that impression, I am already well beyond the beginner level with programming in TS and MC

It looks like a I caused some confusion by using the word "array".. forget I mentioned that word at all.

I already understand that multicharts calculates left to right through the bars and then recalcs the last bar on every new tick..

In your first line of your response you say "lastcalcdate and lastcalctime get you the values of the "lastBarOnChart" before that bar is actually processed"..

That in essence is my question, if we can see lastcalcdate and lastcalctime from a previous bar, is it possible to see the OHLC values or the value of some other calculation occurring at the last bar?

There is an easy way to do this with ELCollection but I am trying to see if there is a simpler way without having to call ELCollection.dll

User avatar
Roman MultiCharts
Posts: 50
Joined: 28 Nov 2011
Has thanked: 21 times
Been thanked: 67 times

Re: Recognize the "last value" of a data array from any bar

Postby Roman MultiCharts » 03 Jan 2014

Hello OZ Trade,
That in essence is my question, if we can see lastcalcdate and lastcalctime from a previous bar, is it possible to see the OHLC values or the value of some other calculation occurring at the last bar?
The last calculation on the previous bar is always performed on the close of that bar. So The simpliest way to refer to these values is the one that bowlesj3 suggested you, i.e. to use Close[1].

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Recognize the "last value" of a data array from any bar

Postby bowlesj3 » 03 Jan 2014

That in essence is my question, if we can see lastcalcdate and lastcalctime from a previous bar, is it possible to see the OHLC values or the value of some other calculation occurring at the last bar?
Interesting. Maybe if you study those functions you can figure it out.

I am also thinking about how I place text and lines out front of the last bar on the chart. I do this by calculating a future time and then use the TL_new command to place the line out front. I do the same with text, lines and arrows. The move statements are done the same way to keep these out front. However you can not have a negative reference such as close[-1]. It makes your study abort (I have had that happen hundreds of times - LOL). If it could be done you could compute the number of bars and get the values of those future bars.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Recognize the "last value" of a data array from any bar

Postby bowlesj3 » 04 Jan 2014

Again regarding
That in essence is my question, if we can see lastcalcdate and lastcalctime from a previous bar, is it possible to see the OHLC values or the value of some other calculation occurring at the last bar?
It occurred to me that I read about a new command that allows the power langauge to get at the absolute bars of the chart rather than referencing them as part of the MaxBarsBack structure of the current bar being processed back by the amount of bars as specified by the MaxBarsBack value. Unfortunately I have never had the need to do this so I have not kept the command handy. I will see if I can find that command. I am thinking that maybe it can reference both before and after the MaxBarsBack table (the past and the future). If this is true you may be able to get a these values using that method. What would be really cool would be if these bars could be obtained using currly brackets. In other words Close{1} would be the closing value of the bar just before the last bar on the chart and High{5} would be the high value of the bar which is 5 bars before the last bar on the chart. Gee, you could actually cheat in your backtesting, trick yourself into thinking your system was great, and loose lots of money very fast - LOL. Fancy that. What a great idea - LOL. On a more serious note, I could see it being used to debug one's code to automatically set up a trap to see if code is being processed properly once that bar is obtained. I am sure some creative people could come up with other valid uses that will help them make money rather than loose money.

OZ Trade
Posts: 39
Joined: 08 Nov 2013
Has thanked: 11 times
Been thanked: 18 times

Re: Recognize the "last value" of a data array from any bar

Postby OZ Trade » 05 Jan 2014

Yes even if you could see the max bars or "lastbarnumber" from any previous bar it would open up a lot of possibilities.. then you should be able to reference values for the last bar from any other bar..

Anyway it seems there is no way to do it at this stage, so I will continue to use the 3rd party .dll to achieve this

thanks

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

Re: Recognize the "last value" of a data array from any bar

Postby TJ » 05 Jan 2014

Yes even if you could see the max bars or "lastbarnumber" from any previous bar it would open up a lot of possibilities.. then you should be able to reference values for the last bar from any other bar..
Anyway it seems there is no way to do it at this stage, so I will continue to use the 3rd party .dll to achieve this
thanks
No 3rd party .dll is required...
if you want to see values of any variables from any previous bars, simply use the [x] reference.

eg.
if you want to see the lastcalcdate of 10 bars ago, use
DATE[10]

if you want to see the lastcalctime of 10 bars ago, use
TIME[10]

if you want to see the lastcalctime of a sub-minute chart 10 bars ago, use
TIME_s[10]

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Recognize the "last value" of a data array from any bar

Postby bowlesj3 » 06 Jan 2014

But that is not what he wants to see. When a study is first started and is currently processing a historic bar such as currentbar=1 he wants to be able to look ahead in time and get the values of bars. In other words to be able to find close[-1] rather than close[1]. More specifically the close or high or low or whatever of the last bar on the chart at the time that currentbar=1 is being processed. You can get at the date and time for the last bar on the chart but you can not get at the open,high,low,close information. I can see that we for sure could not get at plot information created by a study since this information will not have been created yet. however the Open,High,Low,close is out there before any studies start to execute so there is no reason that reserve words can not be created to get at this data.

Here is a related question. I searched the Wiki and I could not find this command. I am sure there was a reserve word put into MC that would allow us to reference bar information farther back than the MaxBarsBack setting. In other words it allowed us to reference bar information in absolute terms rather than relative to the current bar being processed back only as far as the maxbarsback setting. I just checked my "useful EL commands" and unfortunately I did not make an entry when I saw it (I had no need for it so I guess I figured it was not useful - LOL - I still have no need for it actually but I am curious now). I remember Janus commenting on it because he was writing all these DLLs to reference the bars in absolute terms.

User avatar
Roman MultiCharts
Posts: 50
Joined: 28 Nov 2011
Has thanked: 21 times
Been thanked: 67 times

Re: Recognize the "last value" of a data array from any bar

Postby Roman MultiCharts » 07 Jan 2014

Hello bowlesj3,

You can try the Symbol_CurrentBar keyword. It returns a numerical value indicating the number of the current bar plus Maximum Bars Back setting for the study.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Recognize the "last value" of a data array from any bar

Postby bowlesj3 » 08 Jan 2014

Hi Roman,

I studied the Wiki entry for the command. I am not sure how one would use it. Is there a way to get at the open, high, low and close of a data series with this command? Maybe I should do some forum searches to see if anyone has submitted examples (something for later today).

Thanks,
John

User avatar
Roman MultiCharts
Posts: 50
Joined: 28 Nov 2011
Has thanked: 21 times
Been thanked: 67 times

Re: Recognize the "last value" of a data array from any bar

Postby Roman MultiCharts » 08 Jan 2014

Hi bowlesj3,

Symbol_CurrentBar can be used for getting OHLC prices of ANY bar on the chart. The code will be like:

Code: Select all

vars:
var0(0),
var1(0),
var2(0),
var3(0);

if Symbol_CurrentBar = 5 then begin
var0 = open;
var1 = high;
var2 = low;
var3 = close;
end;

print("Current Bar is ", Symbol_CurrentBar, " O = ", var0, " H = ", var1, " L = ", var2, " C =", var3);


And in the Output tab you will see the following (I used @YM# from IQFeed):

Current Bar is 1.00 O= 0.00 H= 0.00 L= 0.00 C= 0.00
Current Bar is 2.00 O= 0.00 H= 0.00 L= 0.00 C= 0.00
Current Bar is 3.00 O= 0.00 H= 0.00 L= 0.00 C= 0.00
Current Bar is 4.00 O= 0.00 H= 0.00 L= 0.00 C= 0.00
Current Bar is 5.00 O=16394.00 H=16396.00 L=16394.00 C=16396.00

So we save OHLC variables into the variable only when current bar (on the chart) is 5.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Recognize the "last value" of a data array from any bar

Postby bowlesj3 » 09 Jan 2014

I was thinking that the simple commamd I know "currentbar" could be used for the above code. I think there is some confusion regarding the original question which I have decided to follow up on. The question is "How can we get at chart absolute bar data which is outside the maxbarsback range?". To make the question clear I created a spread sheet and took a picture image of it so I could attach it as a png file (not being sure if I could attach an excel sheet). It shows how a study with a maxbarsback setting of 5 would process a 20 bar chart. I included the question in the sheet in a slightly different format to make it more clear.

After one reviews the picture one should understand this comment. I am thinking the command would need to be a subscript command with the very first bar on the chart being subscript value 1 and the very last bar on the chart being available via a reserve word. I am sure MC has this information since it has the chart displayed.
Attachments
New Bitmap Image.PNG
(78.81 KiB) Downloaded 1496 times


Return to “MultiCharts”