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

Notification

Icon
Error

Options
Go to last post Go to first unread
lilly  
#1 Posted : Monday, April 14, 2014 7:07:26 AM(UTC)
lilly

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 5/27/2005(UTC)
Posts: 17

Hello ,

I need help understanding the logic of the valuewhen section of this formula.

pds1:=Input("Short Moving Average periods: ",1,1000,9);
pds2:=pds1*1.6180339887;
pds3:=pds2*1.6180339887;
pdsL1:=LastValue(Rnd(pds1/1.6180339887));
pdsS1:=LastValue(Rnd(pds1-pdsL1));
pdsL2:=LastValue(Rnd(pds2/1.6180339887));
pdsS2:=LastValue(Rnd(pds2-pdsL2));
pdsL3:=LastValue(Rnd(pds3/1.6180339887));
pdsS3:=LastValue(Rnd(pds3-pdsL3));
MA1:=(Mov(C,pdsL1,S)+ValueWhen(1,pdsL1+1,Mov(C,pdsS1,S)))/2;
MA2:=(Mov(C,pdsL2,S)+ValueWhen(1,pdsL2+1,Mov(C,pdsS2,S)))/2;
MA3:=(Mov(C,pdsL3,S)+ValueWhen(1,pdsL3+1,Mov(C,pdsS3,S)))/2;

MA1;
MA2;
MA3;

Under MA1, MA2 or MA3 why would you use Valuewhen function when just using as below gives the same result ?

MA1:=(Mov(C,pdsL1,S)+Mov(C,pdsS1,S))/2;
MA2:=(Mov(C,pdsL2,S)+Mov(C,pdsS2,S))/2;
MA3:=(Mov(C,pdsL3,S)+Mov(C,pdsS3,S))/2;

I mean what is pdsL1+1 been compared to?

Thanks for any explanation
wabbit  
#2 Posted : Monday, April 14, 2014 7:47:53 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)
Where did this come from?

Look closely at the relationship between the pds parameters and the values they become in the pdsL variables, especially pdsL2 which always equals pds1, so why unnecessarily make code to obfuscate its value?

It's shocking code -- ignore it in its entirety! Or, use it as a lesson in what crap some people try to sell as "science".

It's over complicated by the use of phi, which is then multiplied and rounded out of any significance. Terrible!

Enter a value of 1 for the pds1 parameter and see what happens. Poor!

The ValueWhen() expressions will always evaluate to true, so they're redundant. Obvious!



wabbit  
#3 Posted : Monday, April 14, 2014 7:51:14 PM(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)
For readability:
Code:
pds1:=Input("Short Moving Average periods: ",1,1000,9);
pds2:=pds1*1.6180339887;
pds3:=pds2*1.6180339887;
pdsL1:=LastValue(Rnd(pds1/1.6180339887));
pdsS1:=LastValue(Rnd(pds1-pdsL1));
pdsL2:=LastValue(Rnd(pds2/1.6180339887));
pdsS2:=LastValue(Rnd(pds2-pdsL2));
pdsL3:=LastValue(Rnd(pds3/1.6180339887));
pdsS3:=LastValue(Rnd(pds3-pdsL3));
MA1:=(Mov(C,pdsL1,S)+ValueWhen(1,pdsL1+1,Mov(C,pdsS1,S)))/2;
MA2:=(Mov(C,pdsL2,S)+ValueWhen(1,pdsL2+1,Mov(C,pdsS2,S)))/2;
MA3:=(Mov(C,pdsL3,S)+ValueWhen(1,pdsL3+1,Mov(C,pdsS3,S)))/2;

MA1;
MA2;
MA3;


versus

Code:
phi:= 1.6180339887;
phi1:= 0.6180339887;

pds1:=Input("Short Moving Average periods: ",2,1000,9);

pdsL1:= pds1 / phi;
pdsL2:= pds1;
pdsL3:= pds1 * phi;

pdsS1:= phi1 * pdsL1;
pdsS2:= phi1 * pdsL2;
pdsS3:= phi1 * pdsL3;

{convert lengths to static integers}
pdsL1:=LastValue(Rnd(pdsL1));
pdsL2:=LastValue(Rnd(pdsL2));
pdsL3:=LastValue(Rnd(pdsL3));

pdsS1:=LastValue(Rnd(pdsS1));
pdsS2:=LastValue(Rnd(pdsS2));
pdsS3:=LastValue(Rnd(pdsS3));

{plot}
(Mov(C,pdsL1,S)+Mov(C,pdsS1,S))/2;
(Mov(C,pdsL2,S)+Mov(C,pdsS2,S))/2;
(Mov(C,pdsL3,S)+Mov(C,pdsS3,S))/2;


Laisze  
#4 Posted : Tuesday, April 22, 2014 9:15:57 AM(UTC)
Laisze

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 11/18/2007(UTC)
Posts: 96
Location: HK

Lilly, it's disappointing to see you wasting your time and (going by previous posts) your obvious talent, with this useless crap. Concentrate on market relevant stuff, girl...
Users browsing this topic
Guest (Hidden)
Similar Topics
ValueWhen() opposite function, such as ValueUntil()? (Formula Assistance)
by Drew 9/19/2015 2:49:48 PM(UTC)
ValueWhen (Formula Assistance)
by Derek Worswick 9/2/2014 2:16:28 AM(UTC)
Returning price bar H or L based on HHV in some other parameter - ValueWhen()? (Formula Assistance)
by perth RAT 12/16/2012 10:33:36 PM(UTC)
valuewhen function (Formula Assistance)
by roomyd 9/12/2012 4:36:45 AM(UTC)
Super slow ValueWhen/Prev (Basic Coding Techniques)
by Data 9/25/2009 7:37:11 AM(UTC)
BarsSince, ValueWhen and Custom Formula call in an Expert. (Advanced Coding Techniques)
by marketwatch 2/14/2009 3:04:34 PM(UTC)
Problem with barssince() and valuewhen() (Advanced Coding Techniques)
by FoxerFX 2/13/2009 2:46:39 AM(UTC)
ValueWhen with Hour as Data Array parameter (Formula Assistance)
by andwilson 6/23/2008 7:07:21 PM(UTC)
ValueWhen variable help (Formula Assistance)
by gojuice 2/8/2008 3:23:51 PM(UTC)
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.