weird 100% spikes

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

weird 100% spikes

Postby arnie » 11 Oct 2009

Hi

I elaborated a bit more my previous formula and I though that it would be better to open a new thread about it since this is a separate issue.

Why at the first day of each year the indicator spikes til 100% or 0%?

I can't see where the problem might be :oops:

Code: Select all

// this indicator shows the percentage of days in which data2 closes in accordance with data1
// the objective is to shows us a simple way to measure performance (in time) of a stock or sector against, for example, an index

variables:
dat1UpCl (true),
dat1DnCl (true),
dat2UpCl (true),
dat2DnCl (true),
upCount (0),
dnCount (0),
stYear (false),
count (0),
pctPer (0),
misDays (0);

if bartype = 2 then begin

if Year(date) <> Year(date)[1] then begin
stYear = true;
count = 0;
upCount = 0;
dnCount = 0;
end;

if stYear then begin
dat1UpCl = close of data1 >= close [1] of data1;
dat2UpCl = close of data2 >= close [1] of data2;
dat1DnCl = close of data1 <= close [1] of data1;
dat2DnCl = close of data2 <= close [1] of data2;
count = count + 1;

if dat1UpCl and dat2UpCl then
upcount = upcount + 1;
if dat1DnCl and dat2DnCl then
dnCount = dncount + 1;

misDays = count - (upCount + dnCount);
pctPer = (1 - (misDays / count)) * 100;

end;
end
else begin
alert(text("This indicator is only applied to daily charts"));
end;

plot1(pctPer);


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

Postby TJ » 13 Oct 2009

you just have to work through the values in the variables...


misDays = count - (upCount + dnCount);
pctPer = (1 - (misDays / count)) * 100;



e.g.
on the first day of the year... the market is closed.

on my freequote, somehow there is a price quoted.
the price is the same as the previous close.

thus your formula will translate to:

misdays = 1 - (1 + 1) = -1
pctPer = (1 - ( -1 / 1 )) * 100
= (1 +1 ) * 100
= 200

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Postby arnie » 15 Oct 2009

misdays = 1 - (1 + 1) = -1
Hi TJ.

I don't understand the -1 result.

Count starts at stYear (the first trading day of the year) and since upCount and dnCount only are true when their respective conditions are true, they will always be lower than Count. It's impossible to have a negative result.

I've checked and misDays are being correctly processed.

What am I missing?

I knew that I should have paid more attention to my math teacher :oops:

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

Postby TJ » 15 Oct 2009

1 -2 = -1


can you check the first data of the year?

I know it should be Jan 2,
but some dataproviders mistakenly posts a data for jan 1.
thus causing error.


your count starts on Jan2,
but your calculation should start on Jan3, right?

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

Postby TJ » 15 Oct 2009

misdays = 1 - (1 + 1) = -1
Hi TJ.

I don't understand the -1 result.

Count starts at stYear (the first trading day of the year) and since upCount and dnCount only are true when their respective conditions are true, they will always be lower than Count. It's impossible to have a negative result.

I've checked and misDays are being correctly processed.

What am I missing?

I knew that I should have paid more attention to my math teacher :oops:
your misDays is correctly processed,

but:

the logic behind misdays need to be reviewed.

try to consider the data for the first day.
if the close is unchanged from previous close, what value would you give the following logic?

if dat1UpCl and dat2UpCl then
upcount = upcount + 1;
if dat1DnCl and dat2DnCl then
dnCount = dncount + 1;

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Postby arnie » 15 Oct 2009

1 -2 = -1

can you check the first data of the year?

your count starts on Jan2,
but your calculation should start on Jan3, right?
Yes, the first data of the year is Jan2, and Yes, the calculation should start Jan3, although this way, count should also start Jan3, right?

if the close is unchanged from previous close, what value would you give the following logic?
That were the first conditions to be stablished:

Code: Select all

dat1UpCl = close of data1 >= close [1] of data1;
dat2UpCl = close of data2 >= close [1] of data2;
dat1DnCl = close of data1 <= close [1] of data1;
dat2DnCl = close of data2 <= close [1] of data2;

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

Postby TJ » 15 Oct 2009

That were the first conditions to be stablished:

Code: Select all

dat1UpCl = close of data1 >= close [1] of data1;
dat2UpCl = close of data2 >= close [1] of data2;
dat1DnCl = close of data1 <= close [1] of data1;
dat2DnCl = close of data2 <= close [1] of data2;

what I am alluding to is, both upcount and dnCount will receive +1.
Is that how you wanted it?
I just want to confirm your intention.


.
Last edited by TJ on 15 Oct 2009, edited 3 times in total.

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

Re: weird 100% spikes

Postby TJ » 15 Oct 2009

...Why at the first day of each year the indicator spikes til 100% or 0%?
...

can you post the data points for the following?

last trading day of the year closing price
first trading day of the year closing price
second trading day of the year closing price

hand calculated values for
dat1UpCl
dat2UpCl
dat1DnCl
dat2DnCl
count
upCount
dnCount
misDays
pctPer



these should verify whether the calculation is doing what you anticipated.

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Re: weird 100% spikes

Postby arnie » 15 Oct 2009

last trading day of the year closing price - 1468,36
first trading day of the year closing price - 1447,16
second trading day of the year closing price - 1447,16
third trading day of the year closing price - 1411,63

first trading day of the year
dat1UpCl - false
dat2UpCl - false
dat1DnCl - true
dat2DnCl - true
count - 1
upCount - 0
dnCount - 1
misDays - 0
pctPer - 100

second trading day of the year
dat1UpCl - true
dat2UpCl - true
dat1DnCl - false
dat2DnCl - false
count - 2
upCount - 1
dnCount - 1
misDays - 0
pctPer - 100

third trading day of the year
dat1UpCl - false
dat2UpCl - false
dat1DnCl - false
dat2DnCl - false
count - 3
upCount - 1
dnCount - 1
misDays - 1
pctPer - 66,67%

It's amazing how such simple task (analysing the first 3 days of the year) is able to show us the problem.

Indeed, misDays is the problem. Only on the third day we have the first misDay, allowing the pctPer to be calculated.

So we need to start Count on the third day to accurately calculate the pctPer.

Hey TJ, I have no words to thank you.

Now let me see if I'm able to start the calculation only on the third day...

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

Postby TJ » 15 Oct 2009

Hi Arnie:

No need to thank me... we have all gone through hair pulling days.


Let me show you a debug tip:

add a print statement to your code, and let the indicator help you trace the bug:

Code: Select all

print(
"D="+ numtostr(19000000+date,0)
+ ", C=" + text(c)
+ ", dat1UpCl=" + text(dat1UpCl)
+ ", dat2UpCl=" + text(dat2UpCl)
+ ", dat1DnCl=" + text(dat1DnCl)
+ ", dat2DnCl=" + text(dat2DnCl)
+ ", count=" + numtostr(count,0)
+ ", upCount=" + numtostr(upCount,0)
+ ", dnCount=" + numtostr(dnCount,0)
+ ", misDays=" + numtostr(misDays,0)
+ ", pctPer=" + text(pctPer)
);

enjoy !
TJ

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Postby arnie » 17 Oct 2009

Hey TJ

That debug tip... what a lifesaver.

OK, I thing I was capable of solve the problem, though it took some time to put things in perpective.

See if my thinking is correct.
I need to calculate upcount and dncount only if count > 2 and within it, calculate misDays and pctPer.

Code: Select all

variables:
dat1UpCl (true),
dat1DnCl (true),
dat2UpCl (true),
dat2DnCl (true),
upCount (0),
dnCount (0),
stYear (false),
count (0),
pctPer (0),
misDays (0);


if Year(date) <> Year(date)[1] then begin
stYear = true;
count = 0;
upCount = 0;
dnCount = 0;
end;

if stYear then begin
dat1UpCl = close of data1 >= close [1] of data1;
dat2UpCl = close of data2 >= close [1] of data2;
dat1DnCl = close of data1 <= close [1] of data1;
dat2DnCl = close of data2 <= close [1] of data2;
count = count + 1;
end;

if count > 2 then begin
if dat1UpCl and dat2UpCl then
upcount = upcount + 1;
if dat1DnCl and dat2DnCl then
dnCount = dncount + 1;

misDays = count - (upCount + dnCount);
pctPer = (1 - (misDays / count)) * 100;
end;

plot1(pctPer);

Using 2 sample prints of the same symbol, but different years:
D=20061229, C=1418.30, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=251, upCount=99, dnCount=74, misDays=78, pctPer= 68.92
D=20070103, C=1416.60, dat1UpCl=FALSE, dat2UpCl=TRUE, dat1DnCl=TRUE, dat2DnCl=FALSE, count=1, upCount=0, dnCount=0, misDays=78, pctPer= 68.92
D=20070104, C=1418.34, dat1UpCl=TRUE, dat2UpCl=FALSE, dat1DnCl=FALSE, dat2DnCl=TRUE, count=2, upCount=0, dnCount=0, misDays=78, pctPer= 68.92
D=20070105, C=1409.71, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=3, upCount=0, dnCount=1, misDays=2, pctPer= 33.33
D=20070108, C=1412.84, dat1UpCl=TRUE, dat2UpCl=FALSE, dat1DnCl=FALSE, dat2DnCl=TRUE, count=4, upCount=0, dnCount=1, misDays=3, pctPer= 25.00
D=20070109, C=1412.11, dat1UpCl=FALSE, dat2UpCl=TRUE, dat1DnCl=TRUE, dat2DnCl=FALSE, count=5, upCount=0, dnCount=1, misDays=4, pctPer= 20.00
D=20070110, C=1414.85, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=6, upCount=1, dnCount=1, misDays=4, pctPer= 33.33
In here, on the third day we have 1 upcount, giving us a 33% performance (pctPer)
D=20081230, C= 890.64, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=252, upCount=98, dnCount=99, misDays=55, pctPer= 78.17
D=20081231, C= 903.25, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=253, upCount=99, dnCount=99, misDays=55, pctPer= 78.26
D=20090102, C= 931.80, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=1, upCount=0, dnCount=0, misDays=55, pctPer= 78.26
D=20090105, C= 927.45, dat1UpCl=FALSE, dat2UpCl=TRUE, dat1DnCl=TRUE, dat2DnCl=FALSE, count=2, upCount=0, dnCount=0, misDays=55, pctPer= 78.26
D=20090106, C= 934.70, dat1UpCl=TRUE, dat2UpCl=FALSE, dat1DnCl=FALSE, dat2DnCl=TRUE, count=3, upCount=0, dnCount=0, misDays=3, pctPer= 0.00
D=20090107, C= 906.65, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=4, upCount=0, dnCount=1, misDays=3, pctPer= 25.00
D=20090108, C= 909.73, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=5, upCount=1, dnCount=1, misDays=3, pctPer= 40.00
D=20090109, C= 890.35, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=6, upCount=1, dnCount=2, misDays=3, pctPer= 50.00
In here, on the third day we have 3 misDays, giving us 0%.

It is quite difficult to transport our ideas to a written formula. I'm always thinking if this is the result that I want :oops:

For example, seeing that 0% pctPer made me questioning if the formula is correct. But since upcount and dncount only start when count > 2, it's perfectly normal that on the third day, having a 3 misDays, the result is 0%.

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Postby arnie » 17 Oct 2009

Hey TJ, please allow me to merge this thread Help with formula with this one.

That print that I requested was to print in PLE output window, similar to what you wrote above.

Basically what I want is to print only the pctPer of the last day of the year, instead of all days of the year as the one you wrote.

Something similar to this:


D=20011231, C=1148.16, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=248, upCount=68, dnCount=72, misDays=108, pctPer= 56.45
D=20021231, C= 879.82, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=252, upCount=79, dnCount=102, misDays=71, pctPer= 71.83
D=20031231, C=1111.92, dat1UpCl=TRUE, dat2UpCl=FALSE, dat1DnCl=FALSE, dat2DnCl=TRUE, count=252, upCount=109, dnCount=85, misDays=58, pctPer= 76.98
D=20041231, C=1211.92, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=252, upCount=101, dnCount=69, misDays=82, pctPer= 67.46
D=20051230, C=1248.29, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=252, upCount=114, dnCount=77, misDays=61, pctPer= 75.79
D=20061229, C=1418.30, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=251, upCount=99, dnCount=74, misDays=78, pctPer= 68.92
D=20071231, C=1468.36, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=251, upCount=114, dnCount=81, misDays=56, pctPer= 77.69
D=20081231, C= 903.25, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=253, upCount=99, dnCount=99, misDays=55, pctPer= 78.26
D=20091016, C=1087.68, dat1UpCl=FALSE, dat2UpCl=TRUE, dat1DnCl=TRUE, dat2DnCl=FALSE, count=200, upCount=82, dnCount=71, misDays=47, pctPer= 76.50
Imagine that I want to see the % of the 50 year database that I have. Having access only to the year's final % would make a lot easier to study it.

Thank you.

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

Postby TJ » 17 Oct 2009

Hey TJ, please allow me to merge this thread Help with formula with this one.

That print that I requested was to print in PLE output window, similar to what you wrote above.

Basically what I want is to print only the pctPer of the last day of the year, instead of all days of the year as the one you wrote.

Something similar to this:
...

Imagine that I want to see the % of the 50 year database that I have. Having access only to the year's final % would make a lot easier to study it.

Thank you.

you can use this trick:

if year(date) <> year(date)[1] then...

note the [1] I have added to each variable.

I am asking MC that when a new year has begun,
go print previous bar's variable !

Code: Select all

if year(date) <> year(date)[1] then
print(
"D="+ numtostr(19000000+date[1],0)
+ ", C=" + text(c[1])
+ ", dat1UpCl=" + text(dat1UpCl[1])
+ ", dat2UpCl=" + text(dat2UpCl[1])
+ ", dat1DnCl=" + text(dat1DnCl[1])
+ ", dat2DnCl=" + text(dat2DnCl[1])
+ ", count=" + numtostr(count[1],0)
+ ", upCount=" + numtostr(upCount[1],0)
+ ", dnCount=" + numtostr(dnCount[1],0)
+ ", misDays=" + numtostr(misDays[1],0)
+ ", pctPer=" + text(pctPer[1])
);

enjoy !

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Postby arnie » 18 Oct 2009

Perfect. Thanks TJ.

Meanwhile, I made a different version of the indicator, to see the performance from a selected year/date and something strange is happening.

I've tried with different symbols and all have the same reaction.

Imagine loading a symbol from 2000-01-01, and then apply the indicator from that same date.

Why does the indicator only calculates the data from 2000-01-11 and not from the selected date, since there is available loaded data from that same selected date?
Actually, I need to load at least 10 more days (in this case, 1999-12-20) so the indicator can calculate from 2000-01-01 (or from the first traded day of the selected year)

Is this a MC issue or a formula issue?

Here's the study and the print log:

Code: Select all

Input:
StartDate (20000101);

variables:
stDate (StartDate - 19000000),
dat1UpCl (true),
dat1DnCl (true),
dat2UpCl (true),
dat2DnCl (true),
upCount (0),
dnCount (0),
stYear (false),
count (0),
pctPer (0),
misDays (0);

if Date > stDate then begin
dat1UpCl = close of data1 >= close [1] of data1;
dat2UpCl = close of data2 >= close [1] of data2;
dat1DnCl = close of data1 <= close [1] of data1;
dat2DnCl = close of data2 <= close [1] of data2;
count = count + 1;
end;

if count > 2 then begin
if dat1UpCl and dat2UpCl then
upcount = upcount + 1;
if dat1DnCl and dat2DnCl then
dnCount = dncount + 1;

misDays = count - (upCount + dnCount);
pctPer = (1 - (misDays / count)) * 100;
end;

plot1(pctPer);
This is the print log from 2000-01-01:
D=20000111, C=1438.56, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=1, upCount=0, dnCount=0, misDays=0, pctPer= 0.00
D=20000112, C=1432.04, dat1UpCl=FALSE, dat2UpCl=TRUE, dat1DnCl=TRUE, dat2DnCl=FALSE, count=2, upCount=0, dnCount=0, misDays=0, pctPer= 0.00
D=20000113, C=1449.68, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=3, upCount=1, dnCount=0, misDays=2, pctPer= 33.33
D=20000114, C=1465.15, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=4, upCount=2, dnCount=0, misDays=2, pctPer= 50.00
D=20000118, C=1455.14, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=5, upCount=2, dnCount=1, misDays=2, pctPer= 60.00
D=20000119, C=1455.90, dat1UpCl=TRUE, dat2UpCl=FALSE, dat1DnCl=FALSE, dat2DnCl=TRUE, count=6, upCount=2, dnCount=1, misDays=3, pctPer= 50.00
And this is the print log from 1999-12-20:
D=19991231, C=1469.26, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=0, upCount=0, dnCount=0, misDays=0, pctPer= 0.00
D=20000103, C=1455.17, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=1, upCount=0, dnCount=0, misDays=0, pctPer= 0.00
D=20000104, C=1399.42, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=2, upCount=0, dnCount=0, misDays=0, pctPer= 0.00
D=20000105, C=1402.11, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=3, upCount=1, dnCount=0, misDays=2, pctPer= 33.33
D=20000106, C=1403.45, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=4, upCount=2, dnCount=0, misDays=2, pctPer= 50.00
D=20000107, C=1441.47, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=5, upCount=3, dnCount=0, misDays=2, pctPer= 60.00
D=20000110, C=1457.60, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=6, upCount=4, dnCount=0, misDays=2, pctPer= 66.67
D=20000111, C=1438.56, dat1UpCl=FALSE, dat2UpCl=FALSE, dat1DnCl=TRUE, dat2DnCl=TRUE, count=7, upCount=4, dnCount=1, misDays=2, pctPer= 71.43
D=20000112, C=1432.04, dat1UpCl=FALSE, dat2UpCl=TRUE, dat1DnCl=TRUE, dat2DnCl=FALSE, count=8, upCount=4, dnCount=1, misDays=3, pctPer= 62.50
D=20000113, C=1449.68, dat1UpCl=TRUE, dat2UpCl=TRUE, dat1DnCl=FALSE, dat2DnCl=FALSE, count=9, upCount=5, dnCount=1, misDays=3, pctPer= 66.67

Fernando

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

Postby TJ » 18 Oct 2009

Perfect. Thanks TJ.

Meanwhile, I made a different version of the indicator, to see the performance from a selected year/date and something strange is happening.

I've tried with different symbols and all have the same reaction.

Imagine loading a symbol from 2000-01-01, and then apply the indicator from that same date.

Why does the indicator only calculates the data from 2000-01-11 and not from the selected date, since there is available loaded data from that same selected date?
Actually, I need to load at least 10 more days (in this case, 1999-12-20) so the indicator can calculate from 2000-01-01 (or from the first traded day of the selected year)

Is this a MC issue or a formula issue?

Here's the study and the print log:
...

This is the print log from 2000-01-01:
...

Fernando

It has to do with MaxBarsBack

this thread might help:
http://forum.tssupport.com/viewtopic.ph ... axbarsback

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Postby arnie » 18 Oct 2009

Once again, thanks TJ.

Regards,
Fernando

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Postby arnie » 19 Oct 2009

Hi TJ.

Sorry to bother you again in such short time but I discovered another weird thing.

I've changed the formula so it can be applied to intraday charts but I'm getting values over 100%, something that cannot be possible, although, it's happening.

See the image attached.

The math seems to be OK, and in daily charts I haven't notice this.

Code: Select all

variables:
dat1UpCl (true),
dat1DnCl (true),
dat2UpCl (true),
dat2DnCl (true),
upCount (0),
dnCount (0),
stDay (false),
count (0),
pctPer (0),
misDays (0);


if date <> date[1] then begin
stDay = true;
count = 0;
upCount = 0;
dnCount = 0;
end;

if stDay then begin
dat1UpCl = close of data1 >= close [1] of data1;
dat2UpCl = close of data2 >= close [1] of data2;
dat1DnCl = close of data1 <= close [1] of data1;
dat2DnCl = close of data2 <= close [1] of data2;
count = count + 1;
end;

if count > 2 then begin
if dat1UpCl and dat2UpCl then
upcount = upcount + 1;
if dat1DnCl and dat2DnCl then
dnCount = dncount + 1;

misDays = count - (upCount + dnCount);
pctPer = (1 - (misDays / count)) * 100;
end;

plot1(pctPer);
Attachments
SPY_XLF.png
(71.24 KiB) Downloaded 1452 times

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

Postby TJ » 19 Oct 2009

to figure out the reason,
1. find the error days
2. manually go through the calculations
3. check the print log to see if the calculations match your manual calculation


computers are dumb, it only does what you tell it to do.

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Postby arnie » 20 Oct 2009

to figure out the reason,
1. find the error days
2. manually go through the calculations
3. check the print log to see if the calculations match your manual calculation


computers are dumb, it only does what you tell it to do.

Found it, resolved it :)

The problem was when close matched the previous close. When both symbols had the same type of bar the misDays variable didn't know what to do.

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

Postby TJ » 20 Oct 2009

Found it, resolved it :)

The problem was when close matched the previous close. When both symbols had the same type of bar the misDays variable didn't know what to do.

good to know you solved it...
I was trying to tell you this problem since post #2.

;-)

User avatar
arnie
Posts: 1594
Joined: 11 Feb 2009
Location: Portugal
Has thanked: 481 times
Been thanked: 514 times

Postby arnie » 21 Oct 2009

I was trying to tell you this problem since post #2.
;-)
:shock: :oops:

By the way, is it possible to have more problems in the future with it? :wink:


Regards,
Fernando

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

Postby TJ » 21 Oct 2009

:shock: :oops:

By the way, is it possible to have more problems in the future with it? :wink:


Regards,
Fernando

I think you are good to go !


Return to “User Contributed Studies and Indicator Library”