Dynamic array bounds error on market scanner  [SOLVED]

Questions about MultiCharts and user contributed studies.
Louis88
Posts: 24
Joined: 11 May 2013
Has thanked: 28 times
Been thanked: 1 time

Dynamic array bounds error on market scanner

Postby Louis88 » 07 Jun 2015

Hello,
I'm on 15 seconds timeframe.
I want to know how many trading days are there on a chart and how many bars are there in any of these trading days.
So I wrote these rows:

Code: Select all

Variables:
BarCounter (0),
DayCounter (1);

Arrays:
Array_Day[50] (0),
Array_DailyBars[50] (0);

if (CurrentBar = 1) then ClearPrintLog;

if (Symbol_Date <> Symbol_Date[1]) then begin

if (DayCounter = 1) then begin
Array_Day[DayCounter] = Symbol_Date[1];
Array_DailyBars[DayCounter] = Symbol_CurrentBar[1] - 1;
end
else begin
Array_Day[DayCounter] = Symbol_Date[1];
Array_DailyBars[DayCounter] = Symbol_CurrentBar - (Array_Sum(Array_DailyBars, 1, DayCounter) + 1);
end;

Print(DayCounter:10:0,
" ",
FormatDate("yyyy-MM-dd", DateToJulian(Array_Day[DayCounter])),
Array_DailyBars[DayCounter]:10:0);

DayCounter = DayCounter + 1;
end;

if LastBarOnChart_s then begin
if Symbol_Date > Array_Day[DayCounter] then begin
Array_Day[DayCounter] = Symbol_Date;
Array_DailyBars[DayCounter] = Symbol_CurrentBar - Array_Sum(Array_DailyBars, 1, DayCounter - 1);
end;

Print(DayCounter:10:0,
" ",
FormatDate("yyyy-MM-dd", DateToJulian(Array_Day[DayCounter])),
Array_DailyBars[DayCounter]:10:0);
end;
If I put this indicator on a chart it works and prints what I'm expecting.
If I add this row of code:

Code: Select all

Plot1(DayCounter, "Days");
and put the indicator on a market scanner I get a "Dynamic array bounds" error.
Then I rightclick and go to "Format 'PR DayCount' study for all instruments", and click OK and the error disappears and it works.
What's the problem with this code?
Thanks for your time.

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Dynamic array bounds error on market scanner

Postby JoshM » 07 Jun 2015

I want to know how many trading days are there on a chart and how many bars are there in any of these trading days.
Perhaps I misunderstand what you're trying to achieve, but at first glance I get the impression you might be complicating things by using arrays.

If you want to use arrays in your project, that's fine, but I think that the code below also calculates the number of trading days on the chart and the average number of bars per day:

Code: Select all

Variables:
tradingDays(0),
barsPerDay(0);

if (BarStatus(1) = 2) then begin

if (Date <> Date[1]) then
tradingDays = tradingDays + 1;

if (LastBarOnChart_s = true) then begin

barsPerDay = Symbol_Length / tradingDays;

Print("There are ", NumToStr(tradingDays, 0),
" trading days on the chart.");

Print("The average number of bars per day = ",
NumToStr(barsPerDay, 4));

end;

end;

Louis88
Posts: 24
Joined: 11 May 2013
Has thanked: 28 times
Been thanked: 1 time

Re: Dynamic array bounds error on market scanner

Postby Louis88 » 07 Jun 2015

Hello JoshM,
thanks for your interest.
The number of bars a stock auctions every day is very very variable. And this is true for heavily traded stocks and for thin stocks. This variable is really erratic.
Furthermore I'm going back not more than 15 calendar days (about 10-11 trading days) in my analysis and, as a matter of fact, I can download from eSignal only a limited number of days on these timeframes.
Too few, in my opinion, to know if this random variable (number of daily bars) is normally distributed or not and if the aritmetic mean is a good estimator of it.
Number of bars is another 'market generated' information which could tell us something more about the interest of players about a certain stock during a certain period of time.
I want the market scanner to do this kind of work for me: to compare (as an example) every five minutes if the number of bars traded today up to now is higher or lower than the number of bars traded yesterday (same hour) or than those traded two days ago and to drop me an alert if something unusual is going on. And to do this I need a number as precise as possible and not an estimation. This kind of data should be used together with volume data ...
But, at the moment and for a reason I can't understand, on the market scanner side I'm on a dead end...
Thanks

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Dynamic array bounds error on market scanner  [SOLVED]

Postby Henry MultiСharts » 09 Jun 2015

Hello Louis88,

Your indicator is not designed to handle a situation when there is only one day of data available.
When DayCounter = 1, then DayCounter - 1 is 0 here:

Code: Select all

Array_DailyBars[DayCounter] = Symbol_CurrentBar - Array_Sum(Array_DailyBars, 1, DayCounter - 1);

Louis88
Posts: 24
Joined: 11 May 2013
Has thanked: 28 times
Been thanked: 1 time

Re: Dynamic array bounds error on market scanner

Postby Louis88 » 10 Jun 2015

Hello Henry,
I've modified the following condition:

Code: Select all

if (Symbol_Date > Array_Day[DayCounter]) and (DayCounter > 1) then begin
and now it seems to work (if more than one day of data is loaded).
Many thanks for your help.


Return to “MultiCharts”