# 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[200](0), ArrayCloseDn[200](0);   If BarNumber <> BarNumber[1] then   begin   If Close >= Close[1] then      CounterCloseUp = 1   else      CounterCloseUp = 0;   If Close < Close[1] then      CounterCloseDn = 1   else      CounterCloseDn = 0;   end;         For Value1 = 0 to (EtudeLength-1)      begin      If Close >= Close[1] then         begin         ArrayCloseUp[EtudeLength - Value1] = ArrayCloseUp[(EtudeLength-1)-Value1];         ArrayCloseUp[0] = CounterCloseUp;         end;      If Close < Close[1] then         begin         ArrayCloseDn[EtudeLength - Value1] = ArrayCloseDn[(EtudeLength-1)-Value1];         ArrayCloseDn[0] = CounterCloseDn;         end;      end;   If BarNumber <> BarNumber[0] and BarNumber >= EtudeLength then   begin   PctCloseUp = AverageArray(ArrayCloseUp, EtudeLength);   PctCloseDn = AverageArray(ArrayCloseDn, EtudeLength);   end;Print("DATE: ", formatdate("dd-MM-yyyy ", eldatetodatetime(date)),       newline, " ArrayCloseDn[0] ",ArrayCloseDn[0], " ArrayCloseDn[1] ",ArrayCloseDn[1], " ArrayCloseDn[2] ",ArrayCloseDn[2],        newline, " ArrayCloseUp[0] ",ArrayCloseUp[0], " ArrayCloseUp[1] ",ArrayCloseUp[1], " ArrayCloseUp[2] ",ArrayCloseUp[2]);   Plot1(PctCloseUp, "PctCloseUp");SetPlotColor(1, DarkGreen);SetPlotWidth(1, 2);Plot2(PctCloseDn, "PctCloseDn");SetPlotColor(2, DarkRed);SetPlotWidth(2, 2);`

Nuno

TJ
Posts: 7151
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 988 times
Been thanked: 2041 times

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

nuno-online wrote: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
::

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

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: 7151
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 988 times
Been thanked: 2041 times

### Re: Help : calculate a percentage the number of closes Up &  Topic is solved

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[1] then      CounterCloseUp = 1   else      CounterCloseUp = 0;If Close < Close[1] 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[1].

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: 7151
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 988 times
Been thanked: 2041 times

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

nuno-online wrote: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.