Help : calculate a percentage the number of closes Up & Dn

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great! nuno-online
Posts: 174
Joined: 31 Jan 2006
Has thanked: 74 times
Been thanked: 5 times

Help : calculate a percentage the number of closes Up & Dn

hello

how to calculate a percentage, over one year, the number of closes up and down?

I tried many "things" without success.

here is my script

Code: Select all

Inputs:
EtudeLength(200);

Variables:
CounterCloseUp(0), CounterCloseDn(0), Counter(0),
PctCloseUp(0), PctCloseDn(0);

Arrays:
ArrayCloseUp(0), ArrayCloseDn(0);

If BarNumber <> BarNumber then
begin
If Close >= Close then
CounterCloseUp = 1
else
CounterCloseUp = 0;
If Close < Close then
CounterCloseDn = 1
else
CounterCloseDn = 0;
end;

For Value1 = 0 to (EtudeLength-1)
begin
If Close >= Close then
begin
ArrayCloseUp[EtudeLength - Value1] = ArrayCloseUp[(EtudeLength-1)-Value1];
ArrayCloseUp = CounterCloseUp;
end;
If Close < Close then
begin
ArrayCloseDn[EtudeLength - Value1] = ArrayCloseDn[(EtudeLength-1)-Value1];
ArrayCloseDn = CounterCloseDn;
end;
end;

If BarNumber <> BarNumber and BarNumber >= EtudeLength then
begin
PctCloseUp = AverageArray(ArrayCloseUp, EtudeLength);
PctCloseDn = AverageArray(ArrayCloseDn, EtudeLength);
end;

Print("DATE: ", formatdate("dd-MM-yyyy ", eldatetodatetime(date)),
newline, " ArrayCloseDn ",ArrayCloseDn, " ArrayCloseDn ",ArrayCloseDn, " ArrayCloseDn ",ArrayCloseDn,
newline, " ArrayCloseUp ",ArrayCloseUp, " ArrayCloseUp ",ArrayCloseUp, " ArrayCloseUp ",ArrayCloseUp);

Plot1(PctCloseUp, "PctCloseUp");
SetPlotColor(1, DarkGreen);
SetPlotWidth(1, 2);

Plot2(PctCloseDn, "PctCloseDn");
SetPlotColor(2, DarkRed);
SetPlotWidth(2, 2);
thank you for your help

Nuno

TJ
Posts: 7210
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2052 times

Re: Help : calculate a percentage the number of closes Up &

hello

how to calculate a percentage, over one year, the number of closes up and down?

I tried many "things" without success.

here is my script
::
thank you for your help

Nuno
You are over thinking it.

do a sum of CounterUpClose for the past year and you will have the number of up closes.

if you need to do the exact calendar year,
then take note of the barnumber at the beginning of the year
and compare it to the current barnumber, and you will have the total number of days to sum. nuno-online
Posts: 174
Joined: 31 Jan 2006
Has thanked: 74 times
Been thanked: 5 times

Re: Help : calculate a percentage the number of closes Up &

Hello TJ

thank you for your help

I 'm trying to write this script with your idea

what do you think?

Code: Select all

Inputs:
EtudeLength(200);

Variables:
CounterCloseUp(0), CounterCloseDn(0), Counter(0),
PctCloseUp(0), PctCloseDn(0);

For Value1 = 0 to (EtudeLength-1)
begin
If Close[Value1] >= Close[Value1+1] then
CounterCloseUp = CounterCloseUp + 1;
If Close[Value1] < Close[Value1+1] then
CounterCloseDn = CounterCloseDn + 1;
end;

PctCloseUp = CounterCloseUp / EtudeLength;
PctCloseDn = CounterCloseDn / EtudeLength;

Plot1(CounterCloseUp, "CounterCloseUp");
SetPlotColor(1, DarkGreen);
SetPlotWidth(1, 2);

Plot2(CounterCloseDn, "CounterCloseDn");
SetPlotColor(2, DarkRed);
SetPlotWidth(2, 2);

TJ
Posts: 7210
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2052 times

Re: Help : calculate a percentage the number of closes Up &

You are still overthinking it...

Try this:

Code: Select all

Inputs:
EtudeLength(200);

Variables:
CounterCloseUp(0), CounterCloseDn(0), SumCloseUp(0), SumCloseDn(0)
PctCloseUp(0), PctCloseDn(0);

If Close >= Close then
CounterCloseUp = 1
else
CounterCloseUp = 0;

If Close < Close then
CounterCloseDn = 1
else
CounterCloseDn = 0;

SumCloseUp = summation( CounterCloseUp, EtudeLength );
SumCloseDn = summation( CounterCloseDn, EtudeLength );

PctCloseUp = SumCloseUp / EtudeLength;
PctCloseDn = SumCloseDn / EtudeLength;

Plot100( PctCloseUp - PctCloseDn, "Pct Over/Under");

ps. PctCloseUp + PctCloseDn might not equals to 1 because there will be days where Close=Close. nuno-online
Posts: 174
Joined: 31 Jan 2006
Has thanked: 74 times
Been thanked: 5 times

Re: Help : calculate a percentage the number of closes Up &

TJ

you are a great man ( I was still overthinking )

thank you very much for your help!

Nuno

TJ
Posts: 7210
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2052 times

Re: Help : calculate a percentage the number of closes Up &

TJ
you are a great man ( I was still overthinking )
thank you very much for your help!
Nuno
You are welcome. I can see you are making a great effort.

Good trading to you.

Return to “User Contributed Studies and Indicator Library”