Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
wblam, The problem you are encountering is because the MetaStock Formula Language fully evaluates every expression. You were in fact trying to get MS to do some very large number maths, so what we have to do is trick MS into not seeing the seeds of these very large number calculations: Here is your function reworked, please try to see the 'fooling' of MS, you might need it again the future? Code:
time:=Input("number of periods",2,2000,100);
scale:=Input("y scale - linear(1)/log(2)",1,2,2);
cc:=If(scale=1,C,Log(C));
hh:=If(scale=1,H,Log(H));
ll:=If(scale=1,L,Log(L));
pt:=LastValue(LinearReg(cc,time));
slope:=LastValue(LinRegSlope(cc,time));
end:=LastValue(Cum(1));
start:=BarsSince(Cum(1)>=end-(time-1));
center:=If(start=0,pt-(slope*(end-Cum(1))),0);
topdis:=LastValue(HHV(hh-center,time));
botdis:=LastValue(HHV(center-ll,time));
dis:=Max(topdis,botdis);
{lets fool MS}
l1:=If(scale=2,center+dis,0);
l2:=If(scale=2,center,0);
l3:=If(scale=2,center-dis,0);
ul:=If(scale=1,center+dis,Exp(l1));
cl:=If(scale=1,center,Exp(l2));
ll:=If(scale=1,center-dis,Exp(l3));
{plot/return}
ul;cl;ll;
Hope this helps. wabbit [:D] P.S. Of course, instead of: {lets fool MS} l1:=If(scale=2,center+dis,0); l2:=If(scale=2,center,0); l3:=If(scale=2,center-dis,0); you could write: {lets fool MS} l1:=(scale=2)*(center+dis); l2:=(scale=2)*center; l3:=(scale=2)*(center-dis); which I think is a little neater, it is also slightly faster to execute too.
|