Scanner: # of bars calculated [SOLVED]
- fbertram
- Posts: 166
- Joined: 16 Oct 2014
- Location: Seattle, USA
- Has thanked: 36 times
- Been thanked: 76 times
- Contact:
Scanner: # of bars calculated
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
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
Re: Scanner: # of bars calculated
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
INTRADAY
Regards.
Ben
DAILY
INTRADAY
Regards.
Ben
- fbertram
- Posts: 166
- Joined: 16 Oct 2014
- Location: Seattle, USA
- Has thanked: 36 times
- Been thanked: 76 times
- Contact:
Re: Scanner: # of bars calculated
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
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
Re: Scanner: # of bars calculated
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 :
Sorry that I can't help any further.
Regards.
Ben
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
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Scanner: # of bars calculated
Please go to wiki and look up the definition of CurrentBar.Hi Ben,
::
* my indicator however is only seeing 70 bars
::
Re: Scanner: # of bars calculated
MC Wiki <CurrentBar> ....Please go to wiki and look up the definition of 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.
Thank you.
Ben
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Scanner: # of bars calculated
Let me rephrase the wiki example above:MC Wiki <CurrentBar> ....Please go to wiki and look up the definition of CurrentBar.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.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.
Thank you.
Ben
For example, if Maximum Bars Back is set to 20,
on the 21st bar of the chart, CURRENTBAR will be assigned the number "1".
Re: Scanner: # of bars calculated
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.
Regards.
Ben.
Regards.
Ben.
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Scanner: # of bars calculated
ps.
EasyLanguage ® Functions & Reserved Words Reference
CurrentBar (Reserved Word)...... pg. 525
EasyLanguage ® Functions & Reserved Words Reference
CurrentBar (Reserved Word)...... pg. 525
Re: Scanner: # of bars calculated
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
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
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Scanner: # of bars calculated
You might wish to look up the definition of MaxBarsBack in an old TS manual.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.
::
Re: Scanner: # of bars calculated
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.You might wish to look up the definition of MaxBarsBack in an old TS manual.
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.
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Scanner: # of bars calculated
I am a registered owner of both TS 3.5 and TS 4. I still have the original floppy disks.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.You might wish to look up the definition of MaxBarsBack in an old TS manual.
But to help to specify the problem I described above would be very helpful.
Thank you. Regards.
Ben
Re: Scanner: # of bars calculated
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>.I am a registered owner of both TS 3.5 and TS 4.
Thank you. Good night
Ben
- fbertram
- Posts: 166
- Joined: 16 Oct 2014
- Location: Seattle, USA
- Has thanked: 36 times
- Been thanked: 76 times
- Contact:
Re: Scanner: # of bars calculated
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
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
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Scanner: # of bars calculated
Either I don't understand your question/intent,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
or you still haven't understood MaxBarsBack.
ps. disregard what Ben said. Go to the wiki or the manual and get your answers there.
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Scanner: # of bars calculated
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.
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.
- fbertram
- Posts: 166
- Joined: 16 Oct 2014
- Location: Seattle, USA
- Has thanked: 36 times
- Been thanked: 76 times
- Contact:
Re: Scanner: # of bars calculated
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
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
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Scanner: # of bars calculated
Please look up the meaning of MaxBarsBack in wiki or manual before you proceed further.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
Try the text in post #9.
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Scanner: # of bars calculated
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
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
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Scanner: # of bars calculated
I can categorically say that you are wrong in your perception on MaxBarsBack.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
Please comply with my instruction in post #11.
Please do not distribute further misinformation to confuse users.
- fbertram
- Posts: 166
- Joined: 16 Oct 2014
- Location: Seattle, USA
- Has thanked: 36 times
- Been thanked: 76 times
- Contact:
Re: Scanner: # of bars calculated
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
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
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Scanner: # of bars calculated
Felix: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
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 !
- TJ
- Posts: 7744
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2223 times
Re: Scanner: # of bars calculated
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
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
- fbertram
- Posts: 166
- Joined: 16 Oct 2014
- Location: Seattle, USA
- Has thanked: 36 times
- Been thanked: 76 times
- Contact:
Re: Scanner: # of bars calculated
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
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
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Scanner: # of bars calculated
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: 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?
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);
What exactly does not work as expected when the required MaxBarsBack is specified by the code/manually?
- fbertram
- Posts: 166
- Joined: 16 Oct 2014
- Location: Seattle, USA
- Has thanked: 36 times
- Been thanked: 76 times
- Contact:
Re: Scanner: # of bars calculated
Hi Henry,
thanks a lot for your follow up. Please have a look at this code for an indicator:
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:
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:
After adding this line, the indicator won't show any results at all in the scanner. So I tried something else:
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
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");
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];
I tried adding SetMaxBarsBack to my study but without success:
Code: Select all
SetMaxBarsBack(25);
Code: Select all
SetMaxBarsBack(110);
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 242 times
- Henry MultiСharts
- Posts: 9165
- Joined: 25 Aug 2011
- Has thanked: 1264 times
- Been thanked: 2957 times
Re: Scanner: # of bars calculated [SOLVED]
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.
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:
2. If that is possible to detect the minimum required amount of bars for calculation, like in this example:
The auto detection algorithm will look as the following:
200 * 1,618 = 323
For the following study: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:
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.
- MaxBarsBack = how many bars to use for history.
- CurrentBar = bars to calculate.
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);
Code: Select all
aa = HH[0] / HH[200];
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);
Code: Select all
0.00
6.00
12.00
21.00
35.00
58.00
323.00
“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.