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

Notification

Icon
Error

Options
Go to last post Go to first unread
gorachand  
#1 Posted : Sunday, August 27, 2017 5:19:35 PM(UTC)
gorachand

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 2/19/2012(UTC)
Posts: 101

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)

In his book De Mark writes about the requirements for a Buy signal for his REI oscillator

1. A mild oversold condition.(<=6) 2. A closing price that is greater than the previous trading day's closing price. 3. The opening price on the trading day immediately following the up close day is less than or equal to the previous trading day's high (the up close day's high). 4. The high that same trading day must exceed upside the previous trading day's true high (a true high is the trading day's high or the previous day's close, whichever is greater).

After creating an indicator for TD REI and another for True High---I coded it thus:-

A:=BarsSince(Cross(Fml( "TD REI") ,-40)-BarsSince(Cross(-40, Fml( "TD REI")))); Z:=BarsSince(Cross( Fml( "TD REI"),-40)=0);
B:=Ref(C,-1)>Ref(C,-2) AND (O<=Ref(H,-1)) AND (H>(Ref( Fml( "True High"),-1)) AND A<=6)AND Z; {Plot} B;
But the binary indicator does not plot.
Can someone tell me where i am going wrong?

 

Regards,
Dr.Chatterjee

wabbit  
#2 Posted : Monday, August 28, 2017 2:58:03 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 EVERY condition specified in your BarsSince() functions to have occurred at least once for "B" to have a value.
gorachand  
#3 Posted : Monday, August 28, 2017 4:13:21 PM(UTC)
gorachand

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 2/19/2012(UTC)
Posts: 101

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Hello Wabbit, Thank you for your reply. What is the solution then for "generalised" cases? Regards, Dr.Chatterjee
wabbit  
#4 Posted : Tuesday, August 29, 2017 12:57:27 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)
BarsSince(event)=0 is a long winded way of saying event Your comparative calculation in "A" can be better made using the Alert() function.
gorachand  
#5 Posted : Friday, September 1, 2017 8:01:09 AM(UTC)
gorachand

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 2/19/2012(UTC)
Posts: 101

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)

Hello Wabbit,

               According to your advice---the only condition which has to occur once and has least probability of occuring is

Z:=BarsSince(Cross( Fml( "TD REI"),-40)=0);

Accordingly using the Alert function I tried

Z:=Alert(BarsSince(Cross(-40,Fml( "TD REI"))),5);
A:=BarsSince(Cross(Fml( "TD REI") ,-40)-Z);
B:=Ref(C,-1)>Ref(C,-2) AND (O<=Ref(H,-1)) AND (H>(Ref( Fml( "True High"),-1)) AND A<=6)AND Z; {Plot} B;
But it still does not plot---any suggestions?
Regards,
Dr.Chatterjee

wabbit  
#6 Posted : Saturday, September 2, 2017 5:52:21 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)

I'm assuming you've coded the "true high" and "TD REI" correctly, then I'd be thinking something along these lines (excluding BarsSince() )

Code:

{1. A mild oversold condition.(<=6)} Cross(Fml("TD REI"),-40) AND Alert(Cross(-40,Fml("TD REI")),6) AND

{2. A closing price that is greater than the previous trading day's closing price.} Ref(C,-1)<Ref(C,-2) AND

{3. The opening price on the trading day immediately following the up close day is less than or equal to the previous trading day's high (the up close day's high).} O<=Ref(H,-1) AND

{4. The high that same trading day must exceed upside the previous trading day's true high (a true high is the trading day's high or the previous day's close, whichever is greater).} H>Ref(Fml("True High"),-1)

gorachand  
#7 Posted : Wednesday, September 6, 2017 5:58:24 PM(UTC)
gorachand

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 2/19/2012(UTC)
Posts: 101

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)

Hello Wabbit,

                     Thank you for your reply. I tried your code out but found that it never plots a 1 on any security. Also run as an exploration it never returns a single security.

The REI code I used has been corroborated with the REI indicator found in the commercial Tradestation De Mark indicators package.

The True High indicator has been coded as

Max(H,Ref(C,-1))

You have coded  Alert(Cross(-40,Fml("TD REI")),6)   ---but the difference in bars between Cross(Fml("TD REI"),-40)

and   Alert(Cross(-40,Fml("TD REI")),6) --- you have not fixed at 6.. The Alert function prolongs the signal for 6 more bars  but at any point during the prolongation  the difference in bars may be anything.

I find that a bit strange. Could you clarify my doubts?

Regards,

Dr.Chatterjee

wabbit  
#8 Posted : Thursday, September 7, 2017 1:31:58 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)

Post ALL of your TD REI code

Edited by user Thursday, September 7, 2017 1:35:25 AM(UTC)  | Reason: Not specified

gorachand  
#9 Posted : Friday, September 8, 2017 5:01:42 AM(UTC)
gorachand

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 2/19/2012(UTC)
Posts: 101

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)

Hello Wabbit,

                Thank you for your reply. Here is the TD Rei code. As I wrote before this has been tested against TD Rei indicator found in the DeMark suite of indicators marketed by Tradestation. The readings are authentic.

TD1:= H-Ref(H,-2); TD2:= L-Ref(L,-2); TD3:= If((H>=Ref(L,-5) OR H>=Ref(L,-6)) AND (L<=Ref(H,-5) OR L<=Ref(H,-6)),1,0); TD4:= If((Ref(H,-2)>=Ref(C,-7) OR Ref(H,-2)>=Ref(C,-8)) AND (Ref(L,-2)<=Ref(C,-7) OR Ref(L,-2)<=Ref(C,-8)),1,0); TD6:= (TD1) + (TD2); TD5:= If((TD3) + (TD4)>=1, (TD6), 0); TD7:= Abs(TD1) + Abs(TD2); TDREI:=((TD5) + Ref(TD5,-1) + Ref(TD5,-2) + Ref(TD5,-3) + Ref(TD5,-4))/ (TD7 + Ref(TD7,-1) + Ref(TD7,-2) + Ref(TD7,-3) + Ref(TD7,-4))*100; TDREI; 45;-45;

Regards,

Dr.Chatterjee

wabbit  
#10 Posted : Friday, September 8, 2017 5:09: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)

The reason your code fails (and later, my code) is because when you call the value of another MS function using Fml(); MS looks at the LAST returned value in that function.  In every case, calling Fml("TD REI") will ALWAYS return a value of -45 because that is the last value in your function, and -45 will NEVER cross -40!

So, either reorder the values in your TD REI function, or, Use FmlVar() instead of Fml()

gorachand  
#11 Posted : Saturday, September 9, 2017 4:06:29 PM(UTC)
gorachand

Rank: Advanced Member

Groups: Registered, Registered Users
Joined: 2/19/2012(UTC)
Posts: 101

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)

Hello Wabbit,

                Thank you for your reply.According to your instructions I used Fmlvar for both your code and mine---The indicator plots but gives division by zero---maths error

{1. A mild oversold condition.(<=6)} Cross( FmlVar("TD REI","TDREI"), -40) AND Alert(Cross(-40, FmlVar("TD REI","TDREI") ),6) AND {2. A closing price that is greater than the previous trading day's closing price.} Ref(C,-1)<Ref(C,-2) AND {3. The opening price on the trading day immediately following the up close day is less than or equal to the previous trading day's high (the up close day's high).} O<=Ref(H,-1) AND {4. The high that same trading day must exceed upside the previous trading day's true high (a true high is the trading day's high or the previous day's close, whichever is greater).} H>Ref(Fml("True High"),-1)

AND

A:=BarsSince(Cross( FmlVar("TD REI","TDREI")  ,-40)-BarsSince(Cross(-40,  FmlVar("TD REI","TDREI")))); Z:=BarsSince(Cross(  FmlVar("TD REI","TDREI"),-40)=0); B:=Ref(C,-1)>Ref(C,-2) AND (O<=Ref(H,-1)) AND (H>(Ref( Fml( "True High"),-1)) AND A<=6)AND Z; {Plot} B;

Can you help?

Regards,

Dr.Chatterjee

Edited by user Saturday, September 9, 2017 4:07:26 PM(UTC)  | Reason: Not specified

wabbit  
#12 Posted : Sunday, September 10, 2017 3:49:27 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)

Thinking logically -- your code produces a DBZ error and my code produces the same DBZ error; but neither code has any division in it, so where is the error??

Of course, the error is in your TD REI code!  Calling this function is common to both your function and mine, and it has a division operation.  Fix this.

http://forum.metastock.com/posts/m178824-Miscellaneous--How-to-handle-a--divide-by-zero--error#post178824

And, if you continue to use BarsSince() unnecessarily, you're going to run into more troubles than is worth it.

Users browsing this topic
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.