What is causing this PRINT behavior ?

Questions about MultiCharts and user contributed studies.
User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

What is causing this PRINT behavior ?

Postby TJ » 26 Nov 2009

I am stumped,
Does anyone know what is causing this PRINT behavior ?

this is the code.
I applied it to a MSFT daily chart.

Code: Select all

var: print$("");

if LastBarOnChart then
begin
for value1 = 0 to 20
begin

print$=(getsymbolname
+ " bar="+ text(value1:0:0)
+ " "+ text(ticks[value1]:0:0));

print(print$);
end;
end;
it is a simple 21 round loop to print out the volume of the last 21 bars.

here's the output:
MSFT bar=0 50161052
MSFT bar=0 50161052 <-- bar=0 printed twice
MSFT bar=1 56310696
MSFT bar=2 60544520
MSFT bar=3 61378344
MSFT bar=4 28878664
MSFT bar=5 68016400
MSFT bar=6 42431644 <-- stopped at bar=6
MSFT bar=0 50161052 <-- restart at bar=0 again
MSFT bar=1 56310696
MSFT bar=2 60544520
MSFT bar=3 61378344
MSFT bar=4 28878664
MSFT bar=5 68016400
MSFT bar=6 42431644
MSFT bar=7 50055776
MSFT bar=8 44718408
MSFT bar=9 42810156
MSFT bar=10 54304284
MSFT bar=11 46258756
MSFT bar=12 49900236 <-- stopped at bar=12
MSFT bar=0 50161052 <-- restart at bar=0 again
MSFT bar=1 56310696
MSFT bar=2 60544520
MSFT bar=3 61378344
MSFT bar=4 28878664
MSFT bar=5 68016400
MSFT bar=6 42431644
MSFT bar=7 50055776
MSFT bar=8 44718408
MSFT bar=9 42810156
MSFT bar=10 54304284
MSFT bar=11 46258756
MSFT bar=12 49900236
MSFT bar=13 53738664
MSFT bar=14 44999632
MSFT bar=15 34120376
MSFT bar=16 40771252
MSFT bar=17 62608464
MSFT bar=18 49597144
MSFT bar=19 55807968
MSFT bar=20 45495600 <-- finally done at bar=20

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 26 Nov 2009

when I change the code to a simple print,
the output is ok.

Code: Select all

if LastBarOnChart then
begin
for value1 = 0 to 20
begin
print(value1);
end;
end;
no problem with this output:
0.00
1.00
2.00
3.00
4.00
5.00
6.00
7.00
8.00
9.00
10.00
11.00
12.00
13.00
14.00
15.00
16.00
17.00
18.00
19.00
20.00

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 26 Nov 2009

TJ: your original code works in ts2ki- (I ran it on aapl- see attached).
MC must be handling the code differently.
Attachments
TS2kiPrint.jpg
(270.75 KiB) Downloaded 551 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 26 Nov 2009

TJ: your original code works in ts2ki- (I ran it on aapl- see attached).
MC must be handling the code differently.
Thanks for testing the code.

That's good to know,
the output behaved as expected.



p.s.
1. did you make 2 runs?
because there are 2 outputs.

2. this is not my problem, but your volume seem to be different between the runs.

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Postby SUPER » 26 Nov 2009

Tj,


It runs well on TS 8.6 sound like some issue with MC?


  • MSFT bar=0 32036164
    MSFT bar=1 37341360
    MSFT bar=2 32036164
    MSFT bar=3 32036164
    MSFT bar=4 32036164
    MSFT bar=5 32036164
    MSFT bar=6 32036164
    MSFT bar=7 32036164
    MSFT bar=8 32036164
    MSFT bar=9 32036164
    MSFT bar=10 32036164
    MSFT bar=11 32036164
    MSFT bar=12 32036164
    MSFT bar=13 32036164
    MSFT bar=14 32036164
    MSFT bar=15 32036164
    MSFT bar=16 32036164
    MSFT bar=17 32036164
    MSFT bar=18 32036164
    MSFT bar=19 32036164
    MSFT bar=20 32036164
    MSFT bar=0 32036164
    MSFT bar=1 37341360
    MSFT bar=2 41836364
    MSFT bar=3 42648016
    MSFT bar=4 51967660
    MSFT bar=5 59440916
    MSFT bar=6 75648888
    MSFT bar=7 54129500
    MSFT bar=8 53044976
    MSFT bar=9 55360704
    MSFT bar=10 49693320
    MSFT bar=11 65881036
    MSFT bar=12 57522020
    MSFT bar=13 38909996
    MSFT bar=14 52683312
    MSFT bar=15 63898304
    MSFT bar=16 50294716
    MSFT bar=17 62432608
    MSFT bar=18 73371736
    MSFT bar=19 65232888
    MSFT bar=20 73542320

SUPER
Posts: 646
Joined: 03 Mar 2007
Has thanked: 106 times
Been thanked: 84 times

Postby SUPER » 26 Nov 2009

Tj,

Change Max number of bars study will reference to "User Specified" and see what it does.

It may solve your problem.

geektrader
Posts: 100
Joined: 17 Jul 2009
Location: Germany

Postby geektrader » 26 Nov 2009

I had a similiar problem before in a "FOR X"-loop. It was not with print command though. Might be a bug in the FOR loop within MC.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Postby TJ » 26 Nov 2009

Tj,

Change Max number of bars study will reference to "User Specified" and see what it does.

It may solve your problem.

yup... that's it... it works in "User Specified".


BUT... why does it not work with "Auto Detect" ?

this code works from the last bar backwards,
so maxbarsback should not be an issue.

brodnicki steven
Posts: 407
Joined: 01 Jan 2008
Been thanked: 3 times

Postby brodnicki steven » 26 Nov 2009

TJ: your original code works in ts2ki- (I ran it on aapl- see attached).
MC must be handling the code differently.
Thanks for testing the code.

That's good to know,
the output behaved as expected.



p.s.
1. did you make 2 runs?
because there are 2 outputs.

2. this is not my problem, but your volume seem to be different between the runs.
TJ * Ran it just once

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Postby bowlesj3 » 26 Nov 2009

It is doing a recalculate when it goes back and exceeds the maxbarsback. That is what sets it back to zero. With the auto setting, the compiler I guess is not smart enough to figure out the proper maxbarsback in the more complex print statement.

To prove this, Try the more complex statement and add a print statement to print the maxbarsback. Print that at the first bar on the chart. You will find it gets printed at the various settings MC resets it too before it reruns the study. You can also work out something using GVs to count the number of times it does the recalculate (add to the GV on the first bar on chart and you will find it totals more than a value of 1 execution of first bar on chart). I have code kicking around here somewhere for that but I will have to get back to this thread and update my post later. Of course you need to have something to set your GV to zero before you start the study with the more complex print statement in it and a way to view the GV after.

I first dicovered this when I was placing arrows on the chart and having the binary search go back and find the bar that matched the date and time they were positioned at. It would redo the study (restart it) up to 7 times on average until it got a large enough value for maxbarsback.

This may not be a problem until your study needs a GV which has an initial setting for the day and also the same study does updates to this GV as it runs. In that case the recalculated 2nd and greater runs will not get the intial values that are expected from that GV.

Janus and I have both requested some sort of notification from MC (as an option) to tell the user that MC has done a recalculate. Something like "Study X has been restarted with a larger MaxBarsBack setting of 20" would do.


Return to “MultiCharts”