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

Postby nuno-online » 24 Aug 2014

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);
thank you for your help

Nuno

User avatar
TJ
Posts: 7237
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

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

Postby TJ » 24 Aug 2014

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 &

Postby nuno-online » 24 Aug 2014

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);

User avatar
TJ
Posts: 7237
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

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

Postby TJ » 24 Aug 2014

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 &

Postby nuno-online » 25 Aug 2014

TJ

you are a great man ( I was still overthinking ;) )

thank you very much for your help!

Nuno

User avatar
TJ
Posts: 7237
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 991 times
Been thanked: 2058 times

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

Postby TJ » 25 Aug 2014

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”