logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Derek Worswick  
#1 Posted : Tuesday, August 10, 2010 1:13:31 PM(UTC)
Derek Worswick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

Hi, Using different time periods, I would like to calculate a Composites Sine Wave by summing up six passes of the Sine Wave Formula below. Due to the limit of the number of variables in the MetaStock formula builder I can only include two passes of the formula. Hoping you can oblige Kind regards. Derek
henry1224  
#2 Posted : Tuesday, August 10, 2010 4:37:14 PM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
Dear Derek,

there is an error in variable n
and the following variables are redundant an are of no use in your formula:

Variable m,T1,U, and V1

these variables are not used in the calculation of W1 or W2

also try to reuse the variable name and keep them on single lines so it will be easier on the eyes.

I don't want to ruin the lasik that I had done
wabbit  
#3 Posted : Wednesday, August 11, 2010 1:02:23 AM(UTC)
wabbit

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)

Derek.

Please don't post code that contains obvious errors -- it does little to foster assistance.

Next, as Henry has already pointed out, look carefully at the code to see to most of it is never used in the actual computation, so unless something is hidden from us, these can be removed to simplify the code and speed up computation and execution.

The time to use a variable is when it simplifies the reading of the code or the values are going to be reused; if you are not going to reuse the values just use the function where required to avoid lengthening the code and using up the 20 allowed variables.

Variables themselves may be reused e.g.

Code:

Period1:=Input("Cycle Period 1",5,1000,30);
Period2:=Input("Cycle Period 2",5,1000,80);
Period3:=Input("Cycle Period 3",5,1000,130);
Period4:=Input("Cycle Period 4",5,1000,180);
Period5:=Input("Cycle Period 5",5,1000,300);
Period6:=Input("Cycle Period 6",5,1000,800);

B:=LastValue(Cum(1));

Prd:=Period1;
A:=Cum(1)*360/Prd;
F:=2*Sum(C*Cos(A),B)/B;
G:=2*Sum(C*Sin(A),B)/B;
J:=LastValue(Sqrt(Power(G,2)+Power(F,2)));
K:=LastValue(Atan(G,F)*57.29577951);
W1:=LastValue(Mov(C,B,S))+J*Cos(A-K);

Prd:=Period2;
A:=Cum(1)*360/Prd;
F:=2*Sum(C*Cos(A),B)/B;
G:=2*Sum(C*Sin(A),B)/B;
J:=LastValue(Sqrt(Power(G,2)+Power(F,2)));
K:=LastValue(Atan(G,F)*57.29577951);
W2:=LastValue(Mov(C,B,S))+J*Cos(A-K);

Prd:=Period3;
A:=Cum(1)*360/Prd;
F:=2*Sum(C*Cos(A),B)/B;
G:=2*Sum(C*Sin(A),B)/B;
J:=LastValue(Sqrt(Power(G,2)+Power(F,2)));
K:=LastValue(Atan(G,F)*57.29577951);
W3:=LastValue(Mov(C,B,S))+J*Cos(A-K);

Prd:=Period4;
A:=Cum(1)*360/Prd;
F:=2*Sum(C*Cos(A),B)/B;
G:=2*Sum(C*Sin(A),B)/B;
J:=LastValue(Sqrt(Power(G,2)+Power(F,2)));
K:=LastValue(Atan(G,F)*57.29577951);
W4:=LastValue(Mov(C,B,S))+J*Cos(A-K);

Prd:=Period5;
A:=Cum(1)*360/Prd;
F:=2*Sum(C*Cos(A),B)/B;
G:=2*Sum(C*Sin(A),B)/B;
J:=LastValue(Sqrt(Power(G,2)+Power(F,2)));
K:=LastValue(Atan(G,F)*57.29577951);
W5:=LastValue(Mov(C,B,S))+J*Cos(A-K);

Prd:=Period6;
A:=Cum(1)*360/Prd;
F:=2*Sum(C*Cos(A),B)/B;
G:=2*Sum(C*Sin(A),B)/B;
J:=LastValue(Sqrt(Power(G,2)+Power(F,2)));
K:=LastValue(Atan(G,F)*57.29577951);
W6:=LastValue(Mov(C,B,S))+J*Cos(A-K);

W1+W2+W3+W4+W5+W6



wabbit [:D]


Derek Worswick  
#4 Posted : Wednesday, August 11, 2010 2:02:46 AM(UTC)
Derek Worswick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

Hi, Thank you for your help. Previously I had removed spaces to make the formula more compact I have corrected the errors in the formula
{ First Pass} Period:=Input("Cycle Period",5,1000,15); A:=360/Period; B:=LastValue(Cum(1)); D:=Sum(CLOSE*Cos(A*Cum(1)),B); E1:=Sum(CLOSE*Sin(A*Cum(1)),B); F:=2*D/B; G:=2*E1/B; J:=LastValue(Sqrt(Power(G,2)+Power(F,2))); K:=LastValue(Atan(G,F)*57.29577951); { Line Deleted } { Line Deleted } Q:=If(N>period,N-Period,N); R:=LastValue(Mov(CLOSE,B,S)); W1:=R+J*Cos(A*Cum(1)-K); ( Second Pass } Period2:=Input("Cycle Period2",5,1000,79); A:=360/Period2; B:=LastValue(Cum(1)); D:=Sum(CLOSE*Cos(A*Cum(1)),B); E1:=Sum(CLOSE*Sin(A*Cum(1)),B); F:=2*D/B;G:=2*E1/B; J:=LastValue(Sqrt(Power(G,2)+Power(F,2))); K:=LastValue(Atan(G,F)*57.29577951); { Line Deleted } { Line Deleted } Q:=If(N>period2,N-Period2,N); R:=LastValue(Mov(CLOSE,B,S)); W2:=R+J*Cos(A*Cum(1)-K); W3:=W1+W2; W3
Using different time periods, I would like to calculate a Composites Sine Wave by summing up six passes of the Sine Wave Formula below. Due to the limit of the number of variables in the MetaStock formula builder I can only include two passes of the formula. Could I use the Metastock functions below to sum up several “passes" of the Sine Wave formula Fml ("name") and FmlVar("name","variable") Hoping you can oblige Kind regards. Derek
wabbit  
#5 Posted : Wednesday, August 11, 2010 2:18:41 AM(UTC)
wabbit

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)
Code still contains errors and superfluous variables.

Did you try the code I posted above?



wabbit [:D]

Derek Worswick  
#6 Posted : Wednesday, August 11, 2010 4:15:01 AM(UTC)
Derek Worswick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

Dear Wabbit, Sorry about the errors in the formula, these occurred when I removed the spaces to make the formula more compact . May I thank you for the large amount of work you have done and the notes on coding. I have tried your code and it is great. Kind regards, Dere
henry1224  
#7 Posted : Wednesday, August 11, 2010 2:21:10 PM(UTC)
henry1224

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/29/2004(UTC)
Posts: 1,394
Location: Glastonbury, CT

Was thanked: 2 time(s) in 2 post(s)
Derek, your code still contains errors and redundancy

M:=Period*K/360;
N:=If(MQ:=If(N>period,N-Period,N);

the variable M is never used, as is the variable N

The Variable N refers to MQ? and then refers back to itself.

Both Variables can be eliminated, since they are never used in variables R ,W1,W2
Derek Worswick  
#8 Posted : Thursday, August 12, 2010 4:19:29 AM(UTC)
Derek Worswick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers, Unverified Users
Joined: 8/11/2005(UTC)
Posts: 104

Hi Henry, May I thank you for your help. I was originally working in time units for the phase. Phase = N:=If(MQ:=If(N>period,N-Period,N) ( in time units ) I should have deleted this line. Kind regards, Derek
Users browsing this topic
Guest (Hidden)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.