"Extremes", "highest/lowest" functions affecting maxbarback

Questions about MultiCharts and user contributed studies.
LSs
Posts: 6
Joined: 28 Aug 2012
Has thanked: 1 time

"Extremes", "highest/lowest" functions affecting maxbarback

Postby LSs » 28 Aug 2012

This is in reference to the error I have been getting "Tried to reference back more bars ....Please increase the Max Bars Back setting." The code doesn't seem to obey the Max Bars Back setting that I set.

After breaking down and testing smalls snippets of the following code, I think the "extremes" function is the cause of the error. I performed the following to diagnose this:

1. Set Max Bars Back to 10.
2. Applying the indicator, it doesn't obey the setting and appears to randomly starts at any point.
2. By replacing 'barCount ' with 1, the code respect the Max Bars Back setting.

Code: Select all

vars:
lowPivot ( 0 ),
highPivot ( 0 ),
barCount ( 0 ),
highBar ( 0 ),
lowBar ( 0 );

if currentBar = 1 then begin
LowPivot = L[0];
HighPivot = H[0];
barCount = 1;

end
else begin

barCount = barCount + 1;

if L[0] < lowPivot and C[0] >= lowPivot then begin
lowPivot = L[0];
end;

if (H[0] > highPivot and C[0] <= highPivot) then begin
highPivot = H[0];
end;

if (C[0] > O[0] and C[0] > highPivot) then begin
highPivot = H[0];
value1 = extremes(low, barCount, -1, lowPivot, lowBar);
barCount = 1;
end;

if (C[0] < O[0] and C[0] < lowPivot) then begin
lowPivot = L[0];
value2 = extremes(high, barCount, 1, highPivot, highBar);
barCount = 1;
end;
end;

plot1[0](highPivot, "highPivot");
plot2[0](lowPivot, "lowPivot");
I tried replacing with 'highest/lowest' function but still receive this error.

Any help on this?

Thanks.
Attachments
Test.jpg
(85.92 KiB) Downloaded 1236 times

sptrader
Posts: 742
Joined: 09 Apr 2010
Location: Texas
Has thanked: 483 times
Been thanked: 274 times
Contact:

Re: "Extremes", "highest/lowest" functions affecting maxbarb

Postby sptrader » 28 Aug 2012

It works fine with the current MC8 64 bit version build 5622..(with 10 bars back or auto bars)..

LSs
Posts: 6
Joined: 28 Aug 2012
Has thanked: 1 time

Re: "Extremes", "highest/lowest" functions affecting maxbarb

Postby LSs » 28 Aug 2012

Thanks sptrader, that's interesting to know.

I'm using 32bit version.

I'll try to test on 64bit, but is there a reason why this doesn't work on 32bit?

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: "Extremes", "highest/lowest" functions affecting maxbarb

Postby Andrew MultiCharts » 29 Aug 2012

Thanks sptrader, that's interesting to know.

I'm using 32bit version.

I'll try to test on 64bit, but is there a reason why this doesn't work on 32bit?
On the same charts (same data source, same symbols, same resolution, same sessions, same quote type, same data range and other settings) the script will or will not require more than 10 MaxBarsBack. Bitness of MC is not the case.

LSs
Posts: 6
Joined: 28 Aug 2012
Has thanked: 1 time

Re: "Extremes", "highest/lowest" functions affecting maxbarb

Postby LSs » 29 Aug 2012

So, is there a calculation mechanism or an error in the code which prevent the script to obey the Max Bars Back parameters set?

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: "Extremes", "highest/lowest" functions affecting maxbarb

Postby Andrew MultiCharts » 30 Aug 2012

So, is there a calculation mechanism or an error in the code which prevent the script to obey the Max Bars Back parameters set?
MaxBarsBack value totally depends on your script. For example, if your script references 50 bars back in its calculation, then the MaxBarsBack value should be set at least to 50. If it is set to 100, first 50 bars will be in fact ignored, next 50 bars will be considered in script calculation and its results on bar # 101. If MaxBarsBack value is set to, let's say 25, it will be automatically increased until the number is ok for the script calculation. By the way, the step to increase the value will not always be the same. If you need 50 MaxBarsBack and it is set to 25, in the end it may become 65 (script tried 45, 45 is not enough, next variant is 65, 65 is ok, leave it 65).
If you don't reference any bars back, for example the whole script is "plot1(close);", MaxBarsBack value is 0.

LSs
Posts: 6
Joined: 28 Aug 2012
Has thanked: 1 time

Re: "Extremes", "highest/lowest" functions affecting maxbarb

Postby LSs » 01 Sep 2012

Thanks Andrew.

Your explanation on the MaxBarsBack calculation is really helpful. This gives me some idea to proceed on.


Return to “MultiCharts”