Page 1 of 1

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

Posted: 24 Aug 2014
by nuno-online
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

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

Posted: 24 Aug 2014
by TJ
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.

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

Posted: 24 Aug 2014
by nuno-online
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);

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

Posted: 24 Aug 2014
by TJ
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].

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

Posted: 25 Aug 2014
by nuno-online
TJ

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

thank you very much for your help!

Nuno

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

Posted: 25 Aug 2014
by TJ
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.