Metastock bug?

#1
Hi,

I'm trying something with metastock and the results are not what i was expecting. If you create an indicator with the following code:

a:=0;
a:= Ref(a,-1) + 1;
a;

You get a straight line with the value 1, and i was expecting a line with increasing values, +1 for each new bar. Do you know why this doesn't happen?

I'm using MS Pro 8.0.

Thank you,
Jaime.
 

oxusmorouz

Well-Known Member
#2
Hi,

I'm trying something with metastock and the results are not what i was expecting. If you create an indicator with the following code:

a:=0;
a:= Ref(a,-1) + 1;
a;

You get a straight line with the value 1, and i was expecting a line with increasing values, +1 for each new bar. Do you know why this doesn't happen?

I'm using MS Pro 8.0.

Thank you,
Jaime.
Hi Jamie,
For continuous adding, why don't you use "cum" function instead?

a:= Cum(1);
a;

As far as I can see, metastock does not recognize 2 variables with the same name and I guess is confused it,lol.


Oxymoron.
 
Last edited:
#3
Hi Oxymoron, thanks for the reply.

My goal isn't really continuous adding, i just simplified my script to post the issue, i cannot use Cum()...

Jaime
 

oxusmorouz

Well-Known Member
#4
Hi Oxymoron, thanks for the reply.

My goal isn't really continuous adding, i just simplified my script to post the issue, i cannot use Cum()...

Jaime
Your formula:
a:=0;
a:= Ref(a,-1) + 1;
a;

When metastock reads this formula, I guess it uses the previous value of the 1st "a" variable in the reference function which remains constant at 0. This could explain why there is an error.
Try contacting Equis. Maybe they have a solution.
 
U

uasish

Guest
#6
Hi Oxymoron, thanks for the reply.

My goal isn't really continuous adding, i just simplified my script to post the issue, i cannot use Cum()...

Jaime

Jaime,

Until you clarify ( we are least interested in your code ,writing MS code for others for money is my past time ,but here in traderji,no question of money rather i have freely given my own codes here) ,all this to alley your worry,we will be unable to help you.

Asish
 
#7
Oxymoron,

Its something like that, yes. But it's not the first value of “a” that is used. If you try this code:

a:=0;
a:=1;
a:=2;
a:= Ref(a,-1) + 1;
a;

MS will plot 3. MS Mysteries!


moneypick,
Maybe i'll try that forum even if it seem a little abandoned.
Thanks.


Asish,
Thank you for the reply.
I can tell you that i tried to translate a small program from wealth-lab developer to MS (for others benefit) and i was unable to do it. It seemed i had found a way but because of the issue mentioned, my idea isn't valid.
I need to refer to the past value of a variable and i cannot for reasons i don’t understand. I don't understand why the code i showed doesn't plot an increasing line, why ref(a,-1) shows always the constant i first assign and not the value i assign later.
I have to assign a constant value first to initialize the vars, otherwise they remain forever NA.

Maybe version 9 or 10 behave in a different manner with this code?

Thank you and regards,
Jaime
 
#8
I just read a message regading this issue in a different forum that may explain MS behaviour in this case. It seems that MS takes each line of script at a time and calculates in one go the values for all the bars, then takes the next line of script and does the same.

What i was expecting MS to do was calculate all the lines of the script for one bar, then advance to the next bar and calculate all the values again, and so on for every bar.

The results are different for each algorithm. In the example i gave, MS will calculate "a:=0;" for all the bars, then calculate "a:=ref(a,-1); +1" for all the bars and when ref(a,-1) is called, the value returned is always 0.

I'm not sure i was able to explain correctly.
Thank you all for the help.

Regards,
Jaime.
 

Similar threads