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

Notification

Icon
Error

Options
Go to last post Go to first unread
Jose  
#1 Posted : Thursday, July 19, 2007 3:16:57 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
Whilst recently looking around for poorly written MetaStock code to use as an example for demonstrating the KISS principle (an acronym for "Keep It Simple, Stupid"), I came across this gem:
{Restricted Display} {Written by Preston Umrysh} {Displays an indicator for a specified period of time} pds:=Input("MA Lookback Periods ",2,100,10); A:=Mov(C,pds,S);{Your Indicator Here} len:=Input("TotalDisplayPeriods ",8,100,10); Barbk:=Input("Right Setback",0,100,0); len:=len+Barbk;{resets display to setback} Signal:=Ref(A,-len); Signal2:=Ref(A,-Barbk); LastBar:=Cum(1)=LastValue(Cum(1)-(len)); bacdis1:=ValueWhen(1,LastBar,LastValue(Signal)); 1stRefPnt:=Ref(Ref(bacdis1,-Barbk),Barbk);{end} bacdis2:=ValueWhen(1,LastBar,LastValue(Signal2)); 2ndRefPnt:=Ref(Ref(bacdis2,-Barbk),Barbk);{end} {Line Plot } D1:=LastValue(Cum(1))-LastValue(LEN); {D1 is first high of line} D2:=LastValue(Cum(1))-LastValue(BARBK); {D2 is last high of line} P1:=1stRefPnt; {start-of-line data array} P2:=2ndRefPnt; {end-of-line data array} V1:=ValueWhen(1,D1,P1); V2:=ValueWhen(1,D2,P2); B1:=LastValue(Cum(1))-D1; B2:=LastValue(Cum(1))-D2; LINE:=V1-(BarsSince(Cum(1)=D1)*( (V1-V2)/(B1-B2))); If(LINE,A,line) {end}
Apart from the fact that the "author" doesn't seem to understand the MetaStock code he has plagiarized, the (mostly redundant) 18 lines of plot-restriction code above can be condensed into 3 simpler lines:
{ Bar-based plot display restriction v1.0 http://www.metastocktools.com } { User inputs } pds:=Input("Indicator periods ",1,1000,10); totPds:=Input("Total display periods",1,1000,10); backPds:=Input("Right setback periods",0,1000,0); { Indicator example } x:=Mov(C,pds,S); { Plot restriction } start:=Cum(1)=LastValue(Cum(1))-totPds-backPds; rightClip:=Ref(Ref(x,-backPds),backPds); restricted:=rightClip*ValueWhen(1,start,1); { Output } restricted
Not only is this formula much shorter, but its logic makes some sense. KISS - the easiest way to become proficient at writing reasonable MetaStock code. jose '-)
pumrysh  
#2 Posted : Saturday, July 21, 2007 10:47:36 PM(UTC)
pumrysh

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/28/2004(UTC)
Posts: 110

So from the very first word you are pretentious and archaic (http://en.wikipedia.org/wiki/Whilst) .

If you are going to apply the KISS principle then you should do so correctly. Your code could have been simplified even further to just 2 lines of code. Like this:

{ User inputs }

pds:=Input("Indicator periods ",1,1000,10);

totPds:=Input("Total display periods",1,1000,10);

backPds:=Input("Right setback periods",0,1000,0);

{ Indicator example }

x:=Mov(C,pds,S);

{ Plot restriction }

start:=Cum(1)=LastValue(Cum(1))-totPds-backPds;

restricted:=Ref(Ref(x,-backPds),backPds)*ValueWhen(1,start,1);

{ Output }

restricted

Now isn’t 2 simpler than 3?

Quite frankly though I find this very suprising as it is quite out of the norm for you. From what I remember, anytime someone asked for assistance from you all they ever got was 50 lines of “accurate” calendar date generating code.

Is my code complex and redundant? Sure is! I’m the first to admit that it is. Was it overkill? Yep, there is no doubt that it was. Has it been plagiarized? Only if you consider that it is code that I wrote for another task and used in this application to answer a question put forth to a friendly user group. It was not someone else's written work. Not to worry though as I did indeed consult with myself about the use of the code and I decided that it would be okay for me to use it.

http://finance.groups.yahoo.com/group/equismetastock/message/8910

http://finance.groups.yahoo.com/group/equismetastock/message/8918

Do I understand the code? I obviously understand more about the code than you do. You see this code allows for more than just a restricted indicator display. Indeed it will also display a specified period trendline.

I do appreciate though the fact that you still enjoy monitoring the post of the EquisMetastock usergroup. I’m sure we’re going to be able to provide you with even more pearls in the future. Sorry I can’t invite you to join us though. Besides that would be conterproductive to your already too busy schedule what with all your private paying customers and board administration tasks. :-)

Preston

Jose  
#3 Posted : Sunday, July 22, 2007 12:34:01 AM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
pumrysh wrote:
Your code could have been simplified even further to just 2 lines of code.
Heck, why not just make it one line of code then? { Plot restriction } restricted:=Ref(Ref(x,-backPds),backPds)*ValueWhen(1,Cum(1)=LastValue(Cum(1))-totPds-backPds,1); There is a reason why I've used 3 lines of code, and it involves helping MetaStock users understand the basic logic behind a function without complicating code unnecessarily as you have done. Obviously this way of thinking is beyond you, and unfortunately (for you), this cheap shot earns you no brownie points.
pumrysh wrote:
Do I understand the code?
No, you do not. If you had, then you would have written the plot restriction code correctly in a way that would help MetaStock users. As entertaining as your attempts are at writing above basic entry-level MetaStock code, you are definitely not cut out as a MetaStock educator by any stretch of the imagination. I strongly suggest you read the MetaStock Formula Primer and Help manual to help you understand some programming basics. As for the "original" code being "yours", if you are going to plagiarize someone else's work the least you could do would be to change the original variable names.
pumrysh wrote:
Sorry I can’t invite you to join us though.
No need for any fake sorrow on your part - you just don't get it do you? Posting in your dying private mailing list is nowadays akin to posting graffiti on a toilet wall, as you have recently demonstrated by encouraging software piracy. The only useful content in your posts would be as an example of how to avoid writing poorly thought-out MetaStock code. You are definitely out of your depth in the field of MetaStock expertise, and perhaps you should just concentrate on helping MetaStock newcomers with more basic help (such as changing plot colours), and leave the more serious programming to those with some programming ability. jose '-)
pumrysh  
#4 Posted : Sunday, July 22, 2007 1:32:41 PM(UTC)
pumrysh

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 10/28/2004(UTC)
Posts: 110

Once again Jose you surprise me.

You claim to understand the code yet you continue to write code that is in error.

I tried to warn you but you were so hellbent on your personal attack agenda that

you continue to offer the metastock community code that is flawed.

Compare the code below to yours and I think the error will be apparent.

So when is 10 equal to 11?

{Restricted Display v2.0}
{Written by
Preston
Umrysh}
{Correctly Displays an indicator for a specified period of time}

Pds:=Input("Indicator periods ",1,1111,10);

DisPds:=Input("Select Display Periods",1,1111,10);

BackPds:=Input("Select Setback Periods",0,1111,0);

{ Indicator }

Ind:=Mov(C,pds,S);

{ Restricted Display }

ResPds:= Alert(BarsSince(Cum(1)=LastValue(Cum(1)-(DisPds+BackPds))=1),1);

Plot:=ValueWhen(1,ResPds,Ref(Ref(Ind,-BackPds),BackPds));

Plot; {end}

Preston

Jose  
#5 Posted : Sunday, July 22, 2007 10:56:00 PM(UTC)
Jose

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 1/19/2005(UTC)
Posts: 1,065
Location: Koh Pha-Ngan, Earth

Was thanked: 2 time(s) in 2 post(s)
My KISS code plots exactly as "your" original, and I have no time nor desire to go through fixing your subsequent amateurish attempts at MetaStock programming. Give it up, Preston - you are well out of your depth here. You have absolutely no idea as to what you are doing, even though you continue to adapt my code and re-badge it as your own. jose '-)
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.