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

Notification

Icon
Error

Options
Go to last post Go to first unread
arnevanveen  
#1 Posted : Tuesday, November 1, 2005 11:54:36 AM(UTC)
arnevanveen

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 10/15/2005(UTC)
Posts: 31
Location: The Netherlands

In an article written by Dennis P. Peterson i found a trading system which combines the StochRSI with Bollinger Bands. It sounds very interesing and i tried the code in metastock. Unfortunately i does not work :( . I will paste the code below and hopefully somebody can tell me what i'm doing wrong. I pasted the entry part in the bullish trends part of the expert advisor, and the exit part in the bearish part. The error that metastock displayes is that a certain variable or expression must contain only constant data, i have marked this spot below. {ENTRY} standarddev:= 60; periods:= 14; StochRSI:=(RSI(periods)-LLV(RSI(periods),periods))/ (HHV(RSI(periods),periods)-LLV(RSI(periods),periods)); rdp1:=Round(Stdev(stochrsi,standarddev)/.053); rdp2:=Round(Stdev(stochrsi,standarddev)/.035); rdv1:=Round(Stdev(Mov(V,periods,S)/ 1000000,standarddev)); adjust1:= rdv1-rdp1+11; adjust1:=if(adjust1<8,8,adjust1); adjust1:=if(adjust1>12,12,adjust1); adjust2:=rdv1-rdp2+14; adjust2:=if(adjust1<12,12,adjust2); adjust2:=if(adjust1>20,20,adjust2); periods:=adjust1; BBpds:=adjust2; howclosetoBBbot:=0.9; longthresholdentry:=0.3; wprice:=(2*C+H+L)/4; deviations:=.0625*BBpds+0.75; StochRSI:=(RSI(periods)-LLV(RSI(periods),periods))/ (HHV(RSI(periods),periods)-LLV(RSI(periods),periods)); [color=red:cdf13f94a1]{Metastock is here displaying an error that this variable or expression must contain only constant data!??}[/color] botpercentage:=Abs((wprice- BBandBot(wprice,BBpds,S,deviations))/ (BBandTop(wprice,BBpds,S,deviations)- BBandBot(wprice,BBpds,S,deviations))); {entry conditions} entry1:=botpercentage-howclosetoBBbot<0.3; entry2:=C*1.05>BBandBot(wprice,BBpds,S,deviations) and StochRSI>longthresholdentry; volbb:=If(C>Ref(C,-1),V,0); entry3:=Volbb>Ref(volbb,-1); entry4:=(C-O)/(H-L)>.2; entry1 and entry2 and entry3 and entry4 {EXIT} standarddev:= 60; periods:= 14; StochRSI:=(RSI(periods)-LLV(RSI(periods),periods))/ (HHV(RSI(periods),periods)-LLV(RSI(periods),periods)); rdp1:=Round(Stdev(stochrsi,standarddev)/.053); rdp2:=Round(Stdev(stochrsi,standarddev)/.035); StochRSIvol:=(V-LLV(V,periods))/(HHV(V,periods)- LLV(V,periods)); rdv1:=Round(Stdev(Mov(V,periods,S)/ 1000000,standarddev)); adjust1:=rdv1-rdp2+14; adjust1:=if(adjust1<8,8,adjust1); adjust1:=if(adjust1>12,12,adjust1); adjust2:=rdv1-rdp2+14; adjust2:=if(adjust1<12,12,adjust2); adjust2:=if(adjust1>20,20,adjust2); periods:=adjust1; BBpds:=adjust2; longthresholdexit:=0.7; howclosetoBBtop:=0.8; wprice:=(2*C+H+L)/4; deviations:=.0625*BBpds+0.75; StochRSI:=(RSI(periods)-LLV(RSI(periods),periods))/ (HHV(RSI(periods),periods)- LLV(RSI(periods),periods)); [color=red:cdf13f94a1]{Metastock also displays here an error that this variable or expression must contain only constant data!}[/color] toppercentage:=Abs((wprice- BBandTop(wprice,BBpds,S,deviations))/ (BBandTop(wprice,BBpds,S,deviations)- BBandBot(wprice,BBpds,S,deviations))); {exit conditions} exit1:=stochrsi<longthresholdexit; exit2:=toppercentage<howclosetoBBtop; exit3:=C>0.95*BBandTop(wprice,BBpds,S,deviations); exit4:=C<BBandBot(wprice,BBpds,S,deviations); (exit1 and exit2 and exit3) or exit4
Bulli  
#2 Posted : Tuesday, November 1, 2005 1:03:47 PM(UTC)
Bulli

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 9/26/2005(UTC)
Posts: 185
Location: Brazil

Just remove the word "periods" and replcae it with 14 in the formula, this is what he is doing but indirectly. for example change: StochRSI:=(RSI(periods)-LLV(RSI(periods),periods))/ (HHV(RSI(periods),periods)-LLV(RSI(periods),periods)); to StochRSI:=(RSI(14)-LLV(RSI(14),14))/ (HHV(RSI(14),14)-LLV(RSI(14),14)); This should work just fine. Good luck. Bulli ;)
wabbit  
#3 Posted : Tuesday, November 1, 2005 1:10:23 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)
You need to use the Forum.dll external functions for variable time perod indicators for HHV and LLV (another way of saying, you need to use adaptive functions!) The value for the periods variable is changing during the execution of the script. When using HHV(data array, periods) MS requires that periods remain static; also true for LLV() and RSI(). In your script, lets see how periods is changing... --8<------------------------------------- [color=blue:860897aa9c]periods:= 14;[/color] StochRSI:=(RSI(periods)-LLV(RSI(periods),periods))/ (HHV(RSI(periods),periods)-LLV(RSI(periods),periods)); rdp1:=Round(Stdev(stochrsi,standarddev)/.053); rdp2:=Round(Stdev(stochrsi,standarddev)/.035); rdv1:=Round(Stdev(Mov(V,periods,S)/ 1000000,standarddev)); adjust1:= rdv1-rdp1+11; adjust1:=if(adjust1<8,8,adjust1); [color=blue:860897aa9c]adjust1:=if(adjust1>12,12,adjust1);[/color] adjust2:=rdv1-rdp2+14; adjust2:=if(adjust1<12,12,adjust2); adjust2:=if(adjust1>20,20,adjust2); [color=blue:860897aa9c]periods:=adjust1;[/color] BBpds:=adjust2; howclosetoBBbot:=0.9; longthresholdentry:=0.3; wprice:=(2*C+H+L)/4; deviations:=.0625*BBpds+0.75; [color=blue:860897aa9c]StochRSI:=(RSI(periods)-LLV(RSI(periods),periods))/ (HHV(RSI(periods),periods)-LLV(RSI(periods),periods));[/color] {Metastock is here displaying an error that this variable or expression must contain only constant data!??} etc.... --8<------------------------------------- Now there are several ways to circumvent this restriction, but the simplest is to download and install the Forum.dll file available for free from the Downloads section in this forum. It comes with a Users Manula, which I highly recommend you add to your reading list. From the Forum.dll users manual:
ForumDll.VarHHV", Data Array, Periods) For LLV : ExtFml("ForumDll.VarLLV", Data Array, Periods)[/quote wrote:
Hope this helps. wabbit :D
arnevanveen  
#4 Posted : Tuesday, November 1, 2005 2:06:38 PM(UTC)
arnevanveen

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 10/15/2005(UTC)
Posts: 31
Location: The Netherlands

Thanks for the replies. In the beginning i also tried to replace the error-variables with constants, but this is not the meaning and the power of this indicator. I just tried to install the forum.dll . I downloaded the file and executed the .exe file, but my metastock does not recognize it. It looks like the file implements everything oke, but Metastock does not show forum.dll in the indicator builder. Does anyone know what i'm doing wrong? Arne
Bulli  
#5 Posted : Tuesday, November 1, 2005 2:07:33 PM(UTC)
Bulli

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 9/26/2005(UTC)
Posts: 185
Location: Brazil

you are right, I did not see that "adjust1", I only saw periods:=14 Bulli
wabbit  
#6 Posted : Tuesday, November 1, 2005 2:13:52 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)
.... and looking even deeper at your code you have a DOUBLE adaptive function in the Bollinger Bands! You need a variable PERIODS and a variable DEVIATIONS. This is yet to be implemented in the Forum.dll. Note: I said yet! Its sort of late where I am right now, so I am off to bed but I will have a look at building a variable BB function in vanilla MS and for the .dll tomorrow. Until then.... wabbit :D
wabbit  
#7 Posted : Tuesday, November 1, 2005 2:18:28 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)
when you do get the Forum.dll file installed correctly, try this code for the StochRSI entry part of your formula. FOR THE REST OF YOU Whilst I slumber can you please continue here and see if you can get the Adaptive BB part to work?? wabbit :D ---8<------------------------------------------------- standarddev:=60; periods:=14; myRSI:=RSI(periods); StochRSI:=(myRSI-LLV(myRSI,periods))/(Max(HHV(myRSI,periods)-LLV(myRSI,periods),0.00001)); rdp1:=Round(Stdev(Stochrsi,standarddev)/.053); rdp2:=Round(Stdev(Stochrsi,standarddev)/.035); rdv1:=Round(Stdev(Mov(V,periods,S)/1000000,standarddev)); {variable RSI, HHV and LLV functions} periods:=Min(Max(rdv1-rdp1+11,8 ) ,12); myRSI:=ExtFml("ForumDll.VarRSI", C, periods); myHHV:=ExtFml("ForumDll.VarHHV", myRSI, periods); myLLV:=ExtFml("ForumDll.VarLLV", myRSI, periods); StochRSI:=(myRSI-myLLV)/(Max(myHHV-myLLV,0.00001)); longthresholdentry:=0.3; {we dont have a variable BB function, yet} {my first attempt at variable Bollinger Bands functions} howclosetoBBbot:=0.9; wprice:=(2*C+H+L)/4; BBpds:=If(periods<12,12,If(periods>20,20,Max(rdv1-rdp2+14,1))); myBBandBot:=BBandBot(wprice,lastvalue(BBpds-PREV+PREV),S,LastValue((.0625*BBpds+0.75)+PREV-PREV)); myBBandTop:=BBandTop(wprice,lastvalue(BBpds-PREV+PREV),S,LastValue((.0625*BBpds+0.75)+PREV-PREV)); botpercentage:=Abs((wprice-myBBandBot)/(Max(myBBandTop-myBBandBot,0.00001))); {entry conditions} volbb:=If(C>Ref(C,-1),V,0); entry:= botpercentage-howclosetoBBbot<0.3 AND C*1.05>myBBandBot AND StochRSI>longthresholdentry AND ROC(Volbb,1,$)>0 AND (C-O)/(H-L)>.2; entry ---8<----------------------------------------------- P.S. Arne I have taken the liberty to butcher your code, as I was qyuickly running short of variables and I think better when I see the code written like this!
arnevanveen  
#8 Posted : Tuesday, November 1, 2005 2:22:46 PM(UTC)
arnevanveen

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 10/15/2005(UTC)
Posts: 31
Location: The Netherlands

Okay sleep well and when you read this: good morning! I have send an email to the support (patrick) with the question about why metastock doesn't recognize the forum.dll . And am i correct that the code have to be adjusted with forum.dll codes? And that some codes are doublicated?
Bulli  
#9 Posted : Tuesday, November 1, 2005 2:59:45 PM(UTC)
Bulli

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 9/26/2005(UTC)
Posts: 185
Location: Brazil

I had the same problem with Forumdll.dll You can do this: download this version for Metastock 8 http://forum.equis.com/d...?mode=drm_cat_view&cat=7 it works fine with 8 & 9 Bulli
arnevanveen  
#10 Posted : Tuesday, November 1, 2005 3:08:48 PM(UTC)
arnevanveen

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 10/15/2005(UTC)
Posts: 31
Location: The Netherlands

The dll works fine and the adjusted StochRSI of Wabbit also!! Thanks alot Wabbit and Bulli :D !! Right now i'm studying the code in order to add a BB-code myself, but i don't think i will succeed. So any help on finishing the code of Wabbit is welcome!
Jose  
#11 Posted : Wednesday, November 2, 2005 1:19:36 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)
Bulli wrote:
You can do this: download this version for Metastock 8 http://forum.equis.com/d...?mode=drm_cat_view&cat=7 it works fine with 8 & 9
Patrick, if there is no difference, let's dump the Forum.dll for MS v9, and just use the one for MS v8 to avoid any possible confusion - how about it? :?: jose '-
Patrick  
#12 Posted : Wednesday, November 2, 2005 2:15:52 AM(UTC)
Patrick

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 9/8/2004(UTC)
Posts: 2,266

Was thanked: 1 time(s) in 1 post(s)
Well I don't know for sure that it works with both 8 and 9 ... If I get more feedback that it does work for both 8.0 and 9.0 then I will remove all the confusion ;) Hell I want this one dll to work for 8.0 and 9.0 more than anybody else :lol: Patrick :mrgreen:
arnevanveen  
#13 Posted : Wednesday, November 2, 2005 7:08:23 AM(UTC)
arnevanveen

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 10/15/2005(UTC)
Posts: 31
Location: The Netherlands

I won't get this part of the formula working, i simply don't know enough (YET!!) about the Metastock formula language. Can anyone help me out? howclosetoBBbot:=0.9; wprice:=(2*C+H+L)/4; BBpds:=If(periods<12,12,If(periods>20,20,Max(rdv1-rdp2+14,1))); myBBandBot:=BBandBot(wprice,lastvalue(BBpds-PREV+PREV),S,LastValue((.0625*BBpds+0.75)+PREV-PREV)); myBBandTop:=BBandTop(wprice,lastvalue(BBpds-PREV+PREV),S,LastValue((.0625*BBpds+0.75)+PREV-PREV)); botpercentage:=Abs((wprice-myBBandBot)/(Max(myBBandTop-myBBandBot,0.00001))); {entry conditions} volbb:=If(C>Ref(C,-1),V,0); entry:= botpercentage-howclosetoBBbot<0.3 AND C*1.05>myBBandBot AND StochRSI>longthresholdentry AND ROC(Volbb,1,$)>0 AND (C-O)/(H-L)>.2;
mydancher2  
#14 Posted : Monday, July 30, 2007 7:31:18 PM(UTC)
mydancher2

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 7/14/2007(UTC)
Posts: 7

Hi hi, can someone help direct me to the download link for forum.dll (for MS version 8)? Many thanks.

wabbit  
#15 Posted : Monday, July 30, 2007 7:47:08 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)
The Forum.dll is available for download from the Files Section (button near top of forum page), Programming (Browse Folders menu item), Forum_200.dll (is the latest version)


Hope this helps.

wabbit [:D]


mydancher2  
#16 Posted : Tuesday, July 31, 2007 7:55:16 AM(UTC)
mydancher2

Rank: Newbie

Groups: Registered, Registered Users, Subscribers
Joined: 7/14/2007(UTC)
Posts: 7

Many thanks, wabbit!
pumrysh  
#17 Posted : Tuesday, July 31, 2007 10:25:08 AM(UTC)
pumrysh

Rank: Advanced Member

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

All,

Found the link to the original article . From what I read it appears there are more problems to the code than the variable lookbacks. Entry 3 is going to require some work as well.

Preston

wabbit  
#18 Posted : Tuesday, July 31, 2007 8:16:45 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)
Quote:
I can’t get MetaStock to do the right thing with this next statement. Volbb is the volume for an up day today’s close>yesterday’s close). What I want for an entry condition is: if today is an up day and the volume for today is greater than the last up day, set entry3 to be true.

entry3:=Volbb>Ref(volbb,-1);


Code:
up:=c>ref(c,-1);
entry3:=up and valuewhen(1,up,v)>valuewhen(2,up,v);

Maybe?


wabbit [:D]


wabbit  
#19 Posted : Tuesday, July 31, 2007 10:28:40 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)
... and of course the logic can be simplified here a little!

The first valuewhen() happens when the up condition occurs, so is redundant, making the same function:

Code:
up:=c>ref(c,-1);
entry3:=up and v>valuewhen(2,up,v);



wabbit [:D]


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.