Can anyone explain why these two indicators result in differ

Questions about MultiCharts and user contributed studies.
2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Can anyone explain why these two indicators result in differ

Postby 2haerim » 15 Jul 2008

[Indicator 1]

input:num(1);
var:cnt(0),mov1(0),mov2(0),cond1(0);
var:cnt2(0),mov3(0),mov4(0),cond2(0);
var:cnt3(0),mov5(0),mov6(0),cond3(0);
var: sum(0);
if date<>date[1] then begin
cnt=0;
cnt2=0;
cnt3=0;
sum=0;
end;

mov1=Average(c of data1,5);
mov2=Average(c of data1,20);
mov3=Average(c of data2,5);
mov4=Average(c of data2,20);
mov5=Average(c of data3,5);
mov6=Average(c of data3,20);

if mov1 cross above mov2 then begin
cond1=1;
end
else begin
cond1=0;
end;

if mov3 cross above mov4 then begin
cond2=1;
end
else begin
cond2=0;
end;

if mov5 cross above mov6 then begin
cond3=1;
end
else begin
cond3=0;
end;

if cond1=1 then begin
cnt=cnt+1;
end;
if cond2=1 then begin
cnt2=cnt2+1;
end;
if cond3=1 then begin
cnt3=cnt3+1;
end;

sum=cnt+cnt2+cnt3;

plot1(sum);


I tried to rewrite the Indicator 1 using array, but it gives me different result.
Please explain what went wrong with the Indicator 2 below?


[Indicator2]

input:num(1);
var:cnt(0),cnt2(0),mov1(0),mov2(0),cond1(0),count(0),count2(0);
var: sum(0);
array:mov1_a[2](0),mov2_a[2](0),cond1_a[2](false), cnt_a[2](0);

count=0;
count2=0;
if date<>date[1] then begin
cnt=0;
cnt2=0;
for count=0 to 2 begin
cnt_a[count]=0;

end;
sum=0;
end;

for count=0 to 2 begin
mov1_a[count]=Average(c of data(count+1),5);
mov2_a[count]=Average(c of data(count+1),20);
end;

for count2=0 to 2 begin
if mov1_a[count2] cross over mov2_a[count2] then begin
cond1_a[count2]=True;
end
else begin
cond1_a[count2]=false;
end;
if cond1_a[count2] = True then begin
cnt_a[count2]=cnt_a[count2]+1;
end;
end;

sum = cnt_a[0]+cnt_a[1]+cnt_a[2];

plot1(sum);
Last edited by 2haerim on 15 Jul 2008, edited 1 time in total.

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Postby 2haerim » 15 Jul 2008

Peter Chow confirmed this bug as shown below.

I also confirmed this bug by comparing the result from TS2ki in which two indiators show the same result.

TSS please fix this bug.


ref:http://forum.tssupport.com/viewtopic.php?t=5355
BUG REPORT:

I find out that the cross over operand behaves like > when the statement is within a for loop, with and without arrays addressing.


for count2=0 to 2
begin {cross over sometimes count as if greater than within a for statement}
if mov1_a[count2] > {cross over} mov2_a[count2]
then begin
{cond1_a[count2]=True; } cnt_a[count2]=cnt_a[count2]+1;
end ;
end ;

sum = cnt_a[0] ;
plot1(sum);
try it with the > or the cross over will give you the same result when within the for statement.
which accumulate the number of bars mov1 is above the mov2.

if not within the for statement: they give different result with cross over or >

count2 = 0 ;
if mov1_a[count2]{ >} cross over mov2_a[count2]
then begin
{cond1_a[count2]=True; } cnt_a[count2]=cnt_a[count2]+1;
end ;

or


if mov1_a[0]{ >} cross over mov2_a[0]
then begin
{cond1_a[0]=True; } cnt_a[0]=cnt_a[0]+1;
end ;


The cross over operand behave as > greater than when coded within a for loop, causing serious logic error.


{outside a for loop: the > and cross over give different results:}
count2 = 0 ;
if mov1_a[count2] {>} cross over mov2_a[count2]
then begin
{cond1_a[count2]=True; } cnt_a[count2]=cnt_a[count2]+1;
end ;
sum = cnt_a[0] ;
plot1(sum);


{will give the same result with either > or cross over.}
for count2=0 to 2
begin {cross over sometimes count as if greater than within a for statement}
if mov1_a[count2]{ >} cross over mov2_a[count2]
then begin
{ cond1_a[count2]=True; } cnt_a[count2]=cnt_a[count2]+1;
end ;
end ;
sum = cnt_a[0] ;
plot1(sum);


with cross over it should increment once when first encounter the cross over of mov1 over move2,
but sometimes it behave as >, and will increment the counter with every bar when mov1 is above mov2.


Peter K. Chow MultiChart user before it gone GOLD!

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Postby 2haerim » 15 Jul 2008

To simplify the test, I combined two indicators as one shown below:

The print result shows all the same except for the sum1 and sum2 values.
sum2 and sum2 should be the same.

Even if you switch to 'for' loop statement which is commented below, the result was the same.

input:num(1);
var:count(0),count2(0);
var:mov1(0),mov2(0),mov3(0),mov4(0),mov5(0),mov6(0);
var:cnt1(0),cond1(false);
var:cnt2(0),cond2(false);
var:cnt3(0),cond3(false);
array:cnt_a[2](0),mov1_a[2](0),mov2_a[2](0),cond1_a[2](false);
var:sum1(0),sum2(0);

if currentbar=1 then cleardebug;

count=0;
count2=0;
if date<>date[1] then begin
cnt1=0;
cnt2=0;
cnt3=0;
for count=0 to 1 begin
cnt_a[count]=0;
end;
sum1=0;
sum2=0;
end;

mov1=Average(c of data(1),5);
mov2=Average(c of data(1),20);
mov3=Average(c of data(2),5);
mov4=Average(c of data(2),20);
//mov5=Average(c of data(3),5);
//mov6=Average(c of data(3),20);
for count=0 to 1 begin
mov1_a[count]=Average(c of data(count+1),5);
mov2_a[count]=Average(c of data(count+1),20);
end;

if mov1 cross above mov2 then begin
cond1=true;
end
else begin
cond1=false;
end;
if cond1=true then begin
cnt1=cnt1+1;
end;
if mov3 cross above mov4 then begin
cond2=true;
end
else begin
cond2=false;
end;
{
for count2=0 to 1 begin
if mov1_a[count2] cross over mov2_a[count2] then begin
cond1_a[count2]=True;
end
else begin
cond1_a[count2]=false;
end;
if cond1_a[count2] = True then begin
cnt_a[count2]=cnt_a[count2]+1;
end;
end;
}
count2=0;
if mov1_a[count2] cross over mov2_a[count2] then begin
cond1_a[count2]=True;
end
else begin
cond1_a[count2]=false;
end;
if cond1_a[count2] = True then begin
cnt_a[count2]=cnt_a[count2]+1;
end;
count2=1;
if mov1_a[count2] cross over mov2_a[count2] then begin
cond1_a[count2]=True;
end
else begin
cond1_a[count2]=false;
end;
if cond1_a[count2] = True then begin
cnt_a[count2]=cnt_a[count2]+1;
end;


sum1 = cnt1+cnt2{+cnt3};
sum2 = cnt_a[0]+cnt_a[1]{+cnt_a[2]};

plot1(sum1);
plot2(sum2);

print(d:7:0,t:8:0," 1 ",mov1, mov2,mov1 cross over mov2);
print(d:7:0,t:8:0," 1_a",mov1_a[0], mov2_a[0],mov1_a[0] cross over mov2_a[0]);
print("");
print(d:7:0,t:8:0," 2 ",mov3, mov4,mov3 cross over mov4,sum1,sum2);
print(d:7:0,t:8:0," 2_a",mov1_a[1], mov2_a[1],mov1_a[1] cross over mov2_a[1]);
print("");

User avatar
Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007

Postby Marina Pashkova » 16 Jul 2008

Please send us the workspace with the chart on which the calculations are run. As well as the screenshots showing the discrepancies.

Thank you.

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Postby 2haerim » 16 Jul 2008

screenshot and workspace
Attachments
bug_with_forloop.png
bug_with_forloop.png (60.75 KiB) Viewed 371 times
bug_crossover_inside_forloop.wsp
(19.26 KiB) Downloaded 222 times

User avatar
Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007

Postby Marina Pashkova » 16 Jul 2008

Hi HaeRim,

The issue that you are describing has been confirmed as a bug. It will be fixed in the 4.0 release.

Regards.

2haerim
Posts: 502
Joined: 01 Sep 2006
Been thanked: 2 times

Postby 2haerim » 23 Jul 2008

You mean 4.0 official release, not the current 4.0 beta?

If so, when will the the ETA for 4.0 official release?

User avatar
Marina Pashkova
Posts: 2758
Joined: 27 Jul 2007

Postby Marina Pashkova » 24 Jul 2008

The bug has been fixed in the 4.0 beta.

Here's the test that we ran:

var: count(0), sum_a(0);
array: mov1_a[2](0),mov2_a[2](0),cond1_a[2](False),cnt_a[1](0);

for count=0 to 1 begin
mov1_a[count] = Average(c of data(count+1),5);
mov2_a[count] = Average(c of data(count+1),20);
end;

for count=0 to 1 begin
if mov1_a[count] cross over mov2_a[count] then begin
cond1_a[count]=True;
end
else begin
cond1_a[count]=False;
end;

if cond1_a[count] = True then
cnt_a[count]=cnt_a[count]+1;
end;

sum_a = cnt_a[0]+cnt_a[1];

plot1(sum_a);

//--------------------------------------------------------------
//--------------------------------------------------------------

var: sum(0),cnt1(0),cnt2(0),mov1(0),mov2(0),mov3(0),mov4(0),cond1(0),cond2(0);

mov1=Average(c of data1,5);
mov2=Average(c of data1,20);
mov3=Average(c of data2,5);
mov4=Average(c of data2,20);

if mov1 cross over mov2 then cond1=1 else cond1=0;
if mov3 cross over mov4 then cond2=1 else cond2=0;

if cond1=1 then cnt1=cnt1+1;
if cond2=1 then cnt2=cnt2+1;

sum = cnt1+cnt2;

plot2(sum);

-----------------------------------------------------

Plot1 should coincide with plot2

Regards.


Return to “MultiCharts”