Scanner: # of bars calculated  [SOLVED]

Questions about MultiCharts and user contributed studies.
User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 73 times
Contact:

Scanner: # of bars calculated

Postby fbertram » 15 Nov 2014

Dear MultiCharts fans,

I am working on an indicator for the scanner which needs about 200 bars to work properly. I am stuck with the scanner calculating less bars than that - and can't seem to figure out how to increase the window.

Here is what I tried:
* editing the properties of my indicator in PowerLanguage editor to 'user specified' = 250. I can see that this has some effect, as MaxBarsBack is 250
* formatting the instrument settings in the scanner to 'use custom date range' of 320 bars back. I cannot see any effect of this change

When I add my indicator to the scanner, I see that:
* CurrentBar is going up to 70
* MaxBarsBack is 250

How can I make the scanner calculate more bars than the 70 I am seeing right now?

I checked this article
https://www.multicharts.com/trading-sof ... ng_Symbols
... and also this thread
viewtopic.php?f=1&t=47484&p=110005&hili ... rs#p110005
It seems I have done exactly that. What's wrong?



Thank you,
best regards, Felix

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Scanner: # of bars calculated

Postby bensat » 15 Nov 2014

Have you set the correct settings ? May, when setting a symbol up for intra-day data, it has not enough bars to set and work with. Here one example on my side and re-tested with an indicator which shows the current bar count.

DAILY


Image

INTRADAY

Image

Regards.

Ben

User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 73 times
Contact:

Re: Scanner: # of bars calculated

Postby fbertram » 15 Nov 2014

Hi Ben,

thanks a lot for your reply. It seems things look different (better) on your end. Please see the attached screenshot:
* I have set the custom data range to 320 bars
* I actually have enough data for 320 bars, see the chart and data window
* my indicator however is only seeing 70 bars

Any further hints would be highly appreciated.

Thank you,
best regards, Felix
Attachments
scanner_bars.png
(458.14 KiB) Downloaded 2471 times

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Scanner: # of bars calculated

Postby bensat » 16 Nov 2014

Hey Felix, I just see two possible issues.

1. Using "Days back" instead of "Bars back". You may found a bug.
2. Your indicator may just count the current bar wrong (code needs to be provided)

When you insert an indicator like Plot1(close[100],"test") is it showing the correct value of close[100]?

Ben


EDIT : After stepping in your problem seriously, I have to edit my post.

Please watch the vid I made and uploaded on YouTube.
Link : http://www.youtube.com/watch?v=IxXyZ8PyAgY

After making this research I got totally confused and stuck. I'm not able to reproduce the numbers I showed you in my screenshots. I don't know why. As you can see I implemented the same symbol, almost the same indicator and it's different. I reloaded the data with <STRG-R>. Still the same.

I get different numbers today while some numbers in the beginning are not included in the CurrentBar/BarNumber count today. Further you can see in the right chart of the workspace, the first 6 bars are not included in the count when I write the indicator to plot the currentbar/barnumber-count like this var.0 = currentbar or var.0 = barnumber. Yesterday it worked. So if the currentbar/barnumber count would be the same I set the input there would be a Plot like "1 / 100 / Equal" in green color. But no matches at all.

I'm totally confused and have no answer. As you can see I tried different symbols and different amount of data. Here you can find my indicator I wrote to check the numbers. I hope I was just stupid enough not to see a mistake on my side. I guess it is the issue ;)

Indicator to check currentbar/barnumber count vs. bars to load from the feed :

Code: Select all

input : // INPUT

Version(1),
Explanation("1=CurrentBar; 2=BarNumber; 3-4=BarCounter with CB/BN"),
SetBarsToCalc(100),
PosText("Equal"),
NegText("Failed");

var : // VARIABLES

i.Version(0),
i.SetBarsToCalc(0),
i.PosTextOutput(""),
i.NegTextOutput(""),
var.VersionOutput(""),
var.NumOutput(""),
var.EndOutput(""),
var.BarCount(0),
var.0(0),
var.Color(0);

i.Version = Version;
i.SetBarsToCalc = SetBarsToCalc;
var.VersionOutput = NumToStr(i.Version,0);
i.PosTextOutput = PosText;
i.NegTextOutput = NegText;

If i.Version = 1 then
begin
var.0 = CurrentBar;
end
else
if i.Version = 2 then
begin
var.0 = BarNumber;
end
else
if i.Version = 3 then
begin
if CurrentBar <> 0 then
begin
var.Barcount = var.BarCount + 1;
var.0 = var.BarCount;
end;
end
else
if i.Version = 4 then
begin
if BarNumber <> 0 then
begin
var.BarCount = var.BarCount + 1;
var.0 = var.BarCount;
end;
end;

var.NumOutput = NumToStr(var.0, 0);

If var.0 = i.SetBarsToCalc then
begin
var.EndOutput = var.VersionOutput + " / " + var.NumOutput + " / " + i.PosTextOutput;
var.Color = color_green;
end
else
if var.0 <> i.SetBarsToCalc then
begin
var.EndOutput = var.VersionOutput + " / " + var.NumOutput + " / " + i.NegTextOutput;
var.Color = color_tomato;
end;

Plot1( var.EndOutput, "Test V. 1-4", var.Color);


Sorry that I can't help any further.

Regards.

Ben

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: Scanner: # of bars calculated

Postby TJ » 16 Nov 2014

Hi Ben,
::
* my indicator however is only seeing 70 bars
::
Please go to wiki and look up the definition of CurrentBar.

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Scanner: # of bars calculated

Postby bensat » 16 Nov 2014

Please go to wiki and look up the definition of CurrentBar.
MC Wiki <CurrentBar> ....

Code: Select all

Returns the number of the current bar.

Each bar, subsequent to the initial number of bars specified by the Maximum Bars Back setting, is assigned a sequential number; the initial bars specified by the setting are not numbered.

For example, if Maximum Bars Back is set to 20, the 21st bar will be assigned a number of 1.
So with my understanding of the <CurrentBar> definition, if MaxbarsBack is set at 250 he should be able to see and plot <CurrentBar> as less/equal 250. Correct ? A short explanation would be helpful.

Thank you.

Ben

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: Scanner: # of bars calculated

Postby TJ » 16 Nov 2014

Please go to wiki and look up the definition of CurrentBar.
MC Wiki <CurrentBar> ....

Code: Select all

Returns the number of the current bar.
Each bar, subsequent to the initial number of bars specified by the Maximum Bars Back setting, is assigned a sequential number; the initial bars specified by the setting are not numbered.
For example, if Maximum Bars Back is set to 20, the 21st bar will be assigned a number of 1.
So with my understanding of the <CurrentBar> definition, if MaxbarsBack is set at 250 he should be able to see and plot <CurrentBar> as less/equal 250. Correct ? A short explanation would be helpful.
Thank you.
Ben
Let me rephrase the wiki example above:
For example, if Maximum Bars Back is set to 20,
on the 21st bar of the chart, CURRENTBAR will be assigned the number "1".

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Scanner: # of bars calculated

Postby bensat » 16 Nov 2014

I understand : "Maximum Number Of Bars Study Will Reference" as "Reference To" the last 250 bars from CurrentBar 320, like in the following chart. I saw it like this in TS for almost 17 years now. Why I should exclude the first bars, not knowing (for instance in intra-day range, volume, tick charts) how much bars I have loaded. Weird. So I made it wrong all the years and my studies were wrong all the years ... Ooooops. But it doesn't sound correct for me.

Image

Regards.

Ben.

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: Scanner: # of bars calculated

Postby TJ » 16 Nov 2014

ps.
EasyLanguage ® Functions & Reserved Words Reference
CurrentBar (Reserved Word)...... pg. 525

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Scanner: # of bars calculated

Postby bensat » 16 Nov 2014

I already got your thoughts. Thank you TJ.

But the current explanation of MaxBarsBack is a relict from times where close to nobody was analyzing tick-, range- or volume charts etc.. Why was <MaxBarsBack> implemented ? To limit the amount of data to be used for calculations and so on. We had times the amount of ram and power of cpu was very limited and costly.

In daily and minute charts the number of bars is always known and <MaxBarsBack> makes sense in the current state. But with the implementation of all the extra charting styles it is just out of time. I used it in the wrong prospects of getting freed data out of calculations for time/data periods I don't need anymore.

if I'm working with tick-, volume- and/or range charts set to 5 days, nobody can tell me witch number <CurrentBar> currently has with <MaxBarsBack> set to 1000. So if I only need 50 bars for my study calculations from last bar back, with the current setting for <MaxBarsBack> the calculations would go on for every bar in the back until <MaxBarsBack> is met/reached. Is this necessary ? Performance wise I don't think so. I think, in this case <MaxBarsBack> is totally useless and calculations could continue 1000 times for the bars in the past. Specially when I'm testing/executing all my strategies out of single tick charts. As I said, everything below minute charts is a problem.

When MC/PL would use <MaxBarsBack> in the sense of it's name and the real sense of <Maximum Number Of Bars Referenced By A Study>, the calculations for a study would occur only from last bar to the bar set with <MaxBarsBack> ===> Currentbar - MaxBarsBack. This would be a huge huge performance advantage, specially for tick-, volume- and range charts and others. What about less Ram-usage or the feature just plotting for the last X bars with <MaxBarsBack> instead of plotting for all bars till <MaxBarsBack> in it's current state is met ?

Just setting a high number of <MaxBarsBack> and start with <if CurrentBar = 1 then ...> doesn't really help, because the amount of bars following <CurrentBar = 1> is unknown. Just setting <Bars Back> to the amount of bars to be loaded you need for your calculations does not help while using different studies in one chart which are using different data periods.

Regards.

Ben

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: Scanner: # of bars calculated

Postby TJ » 16 Nov 2014

I already got your thoughts. Thank you TJ.

But the current explanation of MaxBarsBack is a relict from times where close to nobody was analyzing tick-, range- or volume charts etc.. Why was <MaxBarsBack> implemented ? To limit the amount of data to be used for calculations and so on. We had times the amount of ram and power of cpu was very limited and costly.
::
You might wish to look up the definition of MaxBarsBack in an old TS manual.

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Scanner: # of bars calculated

Postby bensat » 16 Nov 2014

You might wish to look up the definition of MaxBarsBack in an old TS manual.
You don't need to load and keep less data with <MaxBarsBack> set compared without it ? No ? You may want to ask a TS 3.5/4 developer what the original intention behind <MaxBarsBack> was and why it was miscalled and misused, but the name never changed. So MC does.

But to help to clarify the problem I described above would be very helpful.

Thank you. Regards.

Ben
Last edited by bensat on 16 Nov 2014, edited 1 time in total.

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: Scanner: # of bars calculated

Postby TJ » 16 Nov 2014

You might wish to look up the definition of MaxBarsBack in an old TS manual.
You don't need to load and keep less data with <MaxBarsBack> set compared without it ? No ? You may want to ask a TS 3.5/4 developer what the original intention behind <MaxBarsBack> was and why it was miscalled and misused, but the name never changed. So MC does.
But to help to specify the problem I described above would be very helpful.
Thank you. Regards.
Ben
I am a registered owner of both TS 3.5 and TS 4. I still have the original floppy disks.

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Scanner: # of bars calculated

Postby bensat » 16 Nov 2014

I am a registered owner of both TS 3.5 and TS 4.
Me too. Just made it to TS4, ProSuite 2000i, TS6, TS7, TS8 until 9.1. This has nothing to do asking you what the original intention of the implementation was, does not answer the questions about data usage with or without <MaxBarsBack> nor answers my questions about the problem and efficiency increase if we would re-think about the sense of <MaxBarsBack>.

Thank you. Good night ;)

Ben

User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 73 times
Contact:

Re: Scanner: # of bars calculated

Postby fbertram » 21 Nov 2014

Hi Ben, Hi TJ,

thank you so much for both your detailed responses. I am sorry for not getting back earlier, but I was traveling for business...

I think I have understood MaxBarsBack and CurrentBar, thanks for your explanations. However, I'd like to go back to my original question. How can I control the numbers of bars calculated by an indicator in the scanner? By printing CurrentBar in my indicator, I understand that I see the number of bars calculated... which is 70. Unfortunately, that is not enough to create valid results for my indicator.

So I see 2 options.

(1) I can change the number of bars calculated in the scanner. So far, I had no luck doing that and it seems Ben didn't either.

(2) Now that I understood MaxBarsBack, I can go and calculate whatever I need in a once block. I am hesitant to do that, as I would need to duplicate quite a bit of code, which I'd like to avoid.


Any comments highly welcome!


Thank you,
best regards, Felix

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: Scanner: # of bars calculated

Postby TJ » 21 Nov 2014

Hi Ben, Hi TJ,
thank you so much for both your detailed responses. I am sorry for not getting back earlier, but I was traveling for business...
I think I have understood MaxBarsBack and CurrentBar, thanks for your explanations. However, I'd like to go back to my original question. How can I control the numbers of bars calculated by an indicator in the scanner? By printing CurrentBar in my indicator, I understand that I see the number of bars calculated... which is 70. Unfortunately, that is not enough to create valid results for my indicator.

So I see 2 options.

(1) I can change the number of bars calculated in the scanner. So far, I had no luck doing that and it seems Ben didn't either.

(2) Now that I understood MaxBarsBack, I can go and calculate whatever I need in a once block. I am hesitant to do that, as I would need to duplicate quite a bit of code, which I'd like to avoid.


Any comments highly welcome!


Thank you,
best regards, Felix
Either I don't understand your question/intent,
or you still haven't understood MaxBarsBack.

ps. disregard what Ben said. Go to the wiki or the manual and get your answers there.

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: Scanner: # of bars calculated

Postby TJ » 21 Nov 2014

Set MaxBarsBack to Auto.
MultiCharts will automatically take care of the number of bars required for your indicator calculations.
Unless you have a specific reason, there is no need to change this "Auto" setting.

User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 73 times
Contact:

Re: Scanner: # of bars calculated

Postby fbertram » 22 Nov 2014

Hi TJ,

From what I have seen, MaxBarsBack only auto-adjusts to about 50. Unfortunately, I need more than that. Also, that is not fully solving my problems. I am not only referencing bars in the past (which MaxBarsBack allows me to do), but I also need to reference results from previous calculations (which MaxBarsBack does not help me doing).

To access these results from previous calculations, I can either calculate enough bars - this would be the easy and preferred method to solve this.

In case that's not possible, I would need to try and make these calculations in a once block. This is the not-so-fun way as (best case) that would require some duplicate code.

Thank you,
Best regards, Felix

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: Scanner: # of bars calculated

Postby TJ » 22 Nov 2014

Hi TJ,

From what I have seen, MaxBarsBack only auto-adjusts to about 50. Unfortunately, I need more than that. Also, that is not fully solving my problems. I am not only referencing bars in the past (which MaxBarsBack allows me to do), but I also need to reference results from previous calculations (which MaxBarsBack does not help me doing).

To access these results from previous calculations, I can either calculate enough bars - this would be the easy and preferred method to solve this.

In case that's not possible, I would need to try and make these calculations in a once block. This is the not-so-fun way as (best case) that would require some duplicate code.

Thank you,
Best regards, Felix
Please look up the meaning of MaxBarsBack in wiki or manual before you proceed further.


Try the text in post #9.

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: Scanner: # of bars calculated

Postby TJ » 22 Nov 2014

Image
Attachments
2je78fm.png
(41.17 KiB) Downloaded 2850 times

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Scanner: # of bars calculated

Postby bensat » 22 Nov 2014

Sadly, just pointing any explanation to a Wiki without thinking about it is correct or not doesn't help anybody nor yourself.

Sadly again, MaxBarsBack is screwed up and it is handled wrong, it is miscalled and full of errors & mistakes. After talking with some experienced MC/PL users, later I will open a new thread with explanations, charts and data to provide my view why <MaxBarsBack> is mishandled.

Regards.

Ben

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: Scanner: # of bars calculated

Postby TJ » 22 Nov 2014

Sadly, just pointing any explanation to a Wiki without thinking about it is correct or not doesn't help anybody nor yourself.

Sadly again, MaxBarsBack is screwed up and it is handled wrong, it is miscalled and full of errors & mistakes. After talking with some experienced MC/PL users, later I will open a new thread with explanations, charts and data to provide my view why <MaxBarsBack> is mishandled.

Regards.

Ben
I can categorically say that you are wrong in your perception on MaxBarsBack.

Please comply with my instruction in post #11.

Please do not distribute further misinformation to confuse users.

User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 73 times
Contact:

Re: Scanner: # of bars calculated

Postby fbertram » 22 Nov 2014

Hi TJ,

Thanks again for your follow-up. As said before, I think I understand what MaxBarsBack is doing and I agree with your picture. I am not sure how to use that information to solve my problem though.

Let's assume a line of code like this:
HH = Highest(High, 20)

Here it is quite clear that I will reference MaxBarsBack, when I am calling this for the bar numbers < 20. And if I need the highest high of 100 bars, I can increase MaxBarsBack and all is good.

Now assume that I have another line of code doing something with this result (let's not discuss if this code is useful or not):
A = HH[0] / HH[100]

Here, MaxBarsBack does nothing for me. HH[100] will only return the expected result for CurrentBar >100. For earlier bars, it will return whatever is available in the past, e.g. for CurrentBar =70 it will return HH[70]... which is not the value I need.

That is the reason why I believe I have to crank up the number of bars calculated in the scanner... but still fail to do. It is possible to rewrite the algorithm to make use of MaxBarsBack instead- but that is not a trivial thing to do and I'd like to avoid that if I can.

Any pointers appreciated.

Thank you,
Best regards, Felix

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: Scanner: # of bars calculated

Postby TJ » 23 Nov 2014

Hi TJ,

Thanks again for your follow-up. As said before, I think I understand what MaxBarsBack is doing and I agree with your picture. I am not sure how to use that information to solve my problem though.

Let's assume a line of code like this:
HH = Highest(High, 20)

Here it is quite clear that I will reference MaxBarsBack, when I am calling this for the bar numbers < 20. And if I need the highest high of 100 bars, I can increase MaxBarsBack and all is good.

Now assume that I have another line of code doing something with this result (let's not discuss if this code is useful or not):
A = HH[0] / HH[100]

Here, MaxBarsBack does nothing for me. HH[100] will only return the expected result for CurrentBar >100. For earlier bars, it will return whatever is available in the past, e.g. for CurrentBar =70 it will return HH[70]... which is not the value I need.

That is the reason why I believe I have to crank up the number of bars calculated in the scanner... but still fail to do. It is possible to rewrite the algorithm to make use of MaxBarsBack instead- but that is not a trivial thing to do and I'd like to avoid that if I can.

Any pointers appreciated.

Thank you,
Best regards, Felix
Felix:

You still have a misunderstanding of the meaning and purpose of MaxBarsBack.
Obviously you have not looked up the definitions in the text I quoted in post #9.


You do not need to tangle with MaxBarsBack.
MaxBarsBack is the number of bars that is required to calculate your indicators.
{edited} MaxBarsBack is the number of bars that is required by MultiCharts to calculate the first valid result for your indicators. It has nothing to do with you having to look back on the data.
MaxBarsBack value is determined automatically by MultiCharts; it is measured from the 1st bar on the chart. Some people mistaken it as the number of bars to look back from the current bar.

For example, if you have a 10 period moving average on the chart,
and that is the only indicator on the chart,
MultiCharts (or TS) will automatically set your MaxBarsBack to 10. Because that is the number of bars MultiCharts must look back to give you the 1st correct calculation of a 10 period moving average.

That's all there is to MaxBarsBack.
It is meant to be set to auto.
It is meant to be left alone. (for exceptions, see Advanced Tips)
It has nothing to do with you looking back in your analysis.

On the 11th bar of the chart, the CURRENTBAR is assigned the value of 1.
This is your 1st official bar.
This is the 1st valid bar for the purposes of your analysis with this 10 period moving average.

You might ask... Why is this called MaxBarsBack ?

Say, you have 3 moving averages on the chart -- a 10, a 20, and a 30 period moving average. MultiCharts MUST look back to the "maximum" period (30 in this case) to calculate your indicators... That's the "Max" in the MaxBarsBack.

My advice to you is....
Set your MaxBarsBack to auto and forget about it. Go forth with your analysis and enjoy !

User avatar
TJ
Posts: 7231
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2056 times

Re: Scanner: # of bars calculated

Postby TJ » 23 Nov 2014

For further readings on MaxBarsBack, google for the following free ebooks:

The TS Technologies EasyLanguage Reference Guide

Getting Started with TS EasyLanguage

These are for TS version 6. They are old texts (2001), but the principles have not changed.


http://www.tradersxchange.com/viewtopic.php?f=52&t=840

User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 73 times
Contact:

Re: Scanner: # of bars calculated

Postby fbertram » 23 Nov 2014

Hi TJ,

thanks again for your note. I have understood MaxBasrBack now and I am thankful for you pointing that out to me. I agree I don't need to play around with it. Unfortunately we are not getting closer to answering my original question: how can I control the number of bars calculated in the scanner?

Have a look at the two lines of code I provided in my last post. They don't behave the same. HH is calculated just fine and MaxBarsBack is automatically adjusted for me and everything is fine. A in turn is not. MultiCharts cannot automatically provide a history for intermediate results. Therefore, this line of code would typically be enclosed by an
If CurrentBar > 100 then

Unfortunately, if I do that the scanner won't calculate it at all thanks to the low number of bars calculated.

Thank you,
Best regards, Felix

User avatar
Henry MultiСharts
Posts: 9132
Joined: 25 Aug 2011
Has thanked: 1260 times
Been thanked: 2929 times

Re: Scanner: # of bars calculated

Postby Henry MultiСharts » 25 Nov 2014

Felix,

The minimum MaxBarsBack is the largest amount of historical data points required by functions in your code. If your code is A = HH[0] / HH[100] then the required MaxBarsBack = 100. You can set it from the code:

Code: Select all

SetMaxBarsBack(100);
or in the study properties->Properties->Max number of bars study will reference->User specified.

What exactly does not work as expected when the required MaxBarsBack is specified by the code/manually?

User avatar
fbertram
Posts: 166
Joined: 16 Oct 2014
Location: Seattle, USA
Has thanked: 36 times
Been thanked: 73 times
Contact:

Re: Scanner: # of bars calculated

Postby fbertram » 25 Nov 2014

Hi Henry,

thanks a lot for your follow up. Please have a look at this code for an indicator:

Code: Select all

variables:
var_one(0),
var_sum(0);

var_one = 1;
var_sum = Summation(var_one, 100);

Plot1(var_sum, "sum");
Plot2(CurrentBar, "current bar");
While this is not what I am doing in my indicator, it shows the same issue. I am referencing a history of 100 bars of data - but this is not historical price data but intermediate calculations. The result will only be correct (100) if at least 100 bars are calculated.

When I insert this study on a chart, you can see how var_sum ramps up until it reaches 27 at CurrentBar = 27 or BarNumber = 150.

When I insert this study in the scanner, you can see the same values. When I play around with 'Use Custom Data Range', I see that I need to set that to 255 bars back, so that the scanner actually calculates 100 bars, leading to var_sum reaching a value of 100.

Chaning one line of code changes things:

Code: Select all

var_one = H[20] / H[20];
Now I need to set 'Use Custom Data Range' to 242 in order to have var_sum reach a value of 100. So somehow, referencing a history of 20 bars shifts the split between bars calculated and history buffer by 13.

I tried adding SetMaxBarsBack to my study but without success:

Code: Select all

SetMaxBarsBack(25);
After adding this line, the indicator won't show any results at all in the scanner. So I tried something else:

Code: Select all

SetMaxBarsBack(110);
Now I see that var_sum ramps up to 50 at BarNumber = 160.

With my actual algorithm, this becomes all even more unforeseeable. This leads to the following questions:
* how does MultiCharts figure out how many bars to use for history and how many bars to calculate?
* how can I control the minimum number of bars that MultiCharts will calculate in the scanner?

Thanks in advance for any further insight!

Best regards, Felix
Attachments
screenshots.zip
screenshots chart & scanner
(1.63 MiB) Downloaded 139 times

User avatar
Henry MultiСharts
Posts: 9132
Joined: 25 Aug 2011
Has thanked: 1260 times
Been thanked: 2929 times

Re: Scanner: # of bars calculated  [SOLVED]

Postby Henry MultiСharts » 02 Dec 2014

Felix, basically TJ has already explained everything in details in his post #24 but I can still see misunderstanding here. You should not mix up the MaxBarsBack with the CurrentBar data.
  • MaxBarsBack = how many bars to use for history.
  • CurrentBar = bars to calculate.
MaxBarsBack are the bars that are revealed by MultiCharts to the study. This amount of bars is used for initial script calculation, to get the initial valid value of functions, variables. It means the study is calculated on 100 historical bars with MaxBarsBack = 100. You will have the valid result available/plotted/output on CurrentBar #1 (or MaxBarsBack+1). There is no way to access the intermediate results of the study calculation that are done on the MaxBarsBack bars, and there is no need for that, because the only first valid value is after processing 100 bars (in your case), i.e. on CurrentBar #1 (or MaxBarsBack+1).
Since CurrentBar #1, the MaxBarsBack “window” with the length 100 starts moving together with the current bar. So your study has access only to the specified 100 bars you want to look at (this saves resources).

This is what BenSat and TJ were explaining in the images they have posted above.

What you have described is the result received on CurrentBar #100, where your study was calculated on 100 MaxBarsBack bars, then on 100 CurrentBar bars (total = 200 bars on a chart). This is what your study shows. You can consider this result to be the correct one, but the result on CurrentBar #1 is also correct.
It is up to you to decide which result is acceptable for you and how exactly to configure the application.

The “Use custom data range” in Format Instrument in the scanner window controls the amount of bars loaded in the scanner for calculation.
When the option is disabled – the scanner automatically adjusts the amount of bars to load to provide enough bars for the studies’ calculation (depends on MaxBarsBack).
When the option is enabled – the amount of bars is user specified. If the loaded amount of bars is not enough for the studies calculation – scanner will show the message “Not enough data” in the respective indicator cell.

You can see the values jumping because the MaxBarsBack is set to Auto-detect. Here is how it works:
MaxBarsBack are detected during the study calculation. When there are not enough bars – the calculation is interrupted and auto detection algorithm is started. There are two consecutive steps:
1. When it is unknown how many bars are required:
Calculation starts with 1 (bar), 6, each next value ~ previous value * 1,618.
The algorithm works this way in the following example:

Code: Select all

HH = Highest(High, 50);
2. If that is possible to detect the minimum required amount of bars for calculation, like in this example:

Code: Select all

aa = HH[0] / HH[200];
The auto detection algorithm will look as the following:
200 * 1,618 = 323

For the following study:

Code: Select all

var: HH(0), aa(0);
once print(MaxBarsBack);

HH = Highest(High, 50);
aa = HH[0] / HH[200];
plot1(close);
As the MaxBarsBack is “auto detected” only when there is not enough bars – the calculation will be done until the HH = Highest(High, 50); is calculated, then auto detection algorithm will start to detect the amount of bars for aa = HH[0] / HH[200]; The auto detection algorithm result will look as the following:

Code: Select all

0.00
6.00
12.00
21.00
35.00
58.00
323.00
Long story short:
“Use custom data range” should be disabled or user specified = higher than the MaxBarsBack required for your study.
If you do not want to miss any bars that can be skipped by the MaxBarsBack auto detection algorithm – you need to explicitly specify the MaxBarsBack for the study. You can do that in the code SetMaxBarsBack(100); or in the study properties->Properties->Max number of bars study will reference->User specified.


Return to “MultiCharts”