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

Notification

Icon
Error

Options
Go to last post Go to first unread
oem7110  
#1 Posted : Tuesday, April 13, 2010 5:26:39 AM(UTC)
oem7110

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/30/2005(UTC)
Posts: 120

I would like to trigger a buy signal if Ref(HHV(H,20),-1)<H, once this signal is triggered, then mark this H as a reference. The profit taking / stop loss level is from this reference level plus / minus 200. Once this buy signal is triggered, ignore any buy signal until stop loss level is hit. I try following codes, BS:=Ref(HHV(H,20),-1)<H; Reference:=If(BS and Ref(Status,-1)=0,H,PREV); Status:=If(BS,1,If(Reference+200=<h OR Reference-200>=L,0,PREV)); Signal:= If((Ref(Status,-1) = 0 AND Status = 1),1,0); EX:=If((Ref(Status,-1)=1 AND Status = 0),1,0); but there is a structure issue on defining "Reference", does anyone have any suggestions on how to solve this issue? Thanks in advance for any suggestions Eric
wabbit  
#2 Posted : Tuesday, April 13, 2010 7:15:10 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 to start???

Let's start with some simple logic in MS: you don't need to use :-

variable:=If(condition,1,0);

because this is already interpreted for you and can just be coded as :-

variable:=condition;

will return 1 if the condition is TRUE, 0 if FALSE.


Next, MS uses a fully evaluated scripting language which means each line of code is fully evaluated for every bar on the chart before the next line is evaluated, which means you cannot define a variable in line three of your code and call it from line two.

Roy Larsen wrote an excellent article on using latches in MS, I suggest you locate it and have a read.


wabbit [:D]

oem7110  
#3 Posted : Tuesday, April 13, 2010 7:30:58 AM(UTC)
oem7110

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/30/2005(UTC)
Posts: 120

It seems to me that this forum cannot use larger / smaller signs, because it does not display text properly with HTML language. I would like to trigger a buy signal if H is larger than Ref(HHV(H,20),-1), once this signal is triggered, then mark this H as a reference level. The profit taking / stop loss level is based on this reference level plus / minus 200. Once this buy signal is triggered, any further buy signal will be ignored until stop loss level is triggered. This rule is applied to Exit signal too. So Buy and Exit, then Buy and Exit ... in this series. I try following codes, [Buy Signal] "BS:=H is larger than Ref(HHV(H,20),-1);" [Reference Level] "Reference:=If(BS and Ref(Status,-1) = 0,H,PREV);" [Status on holding position] "Status:=If(BS,1,If(Reference+200 is equal or small than H OR Reference-200 is larger than or equal to L,0,PREV));" [Filtered Buy Signal] "Signal:= If((Ref(Status,-1) = 0 AND Status = 1),1,0);" [Filtered Exit Signal] "EX:=If((Ref(Status,-1) = 1 AND Status = 0),1,0);" but there is a structure issue on defining "Reference", does anyone have any suggestions on how to solve this issue? Thanks in advance for any suggestions Eric
oem7110  
#4 Posted : Tuesday, April 13, 2010 7:57:45 AM(UTC)
oem7110

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/30/2005(UTC)
Posts: 120

wabbit wrote:

Roy Larsen wrote an excellent article on using latches in MS, I suggest you locate it and have a read.


wabbit [:D]

Could you please tell me where to find it? If I cannot define a variable in line three of your code and call it from line two, then I have tried to code them in separated indicators, then call each other, but there is an issue on Nested formula circular reference. Do you have any trick to solve this issue? Thanks in advance for any suggestions Eric
wabbit  
#5 Posted : Tuesday, April 13, 2010 8:00:25 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)
oem7110  
#6 Posted : Tuesday, April 13, 2010 8:57:49 AM(UTC)
oem7110

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/30/2005(UTC)
Posts: 120

wabbit wrote:
http://forum.equis.com/files/3015/metastock_files/entry19675.aspx


wabbit [:D]

Could you please give me more description on how this article related to my issue? Do you have any sample related to my issue? so I look iinto it for studing this issue. Thank you very much for any suggestions Eric
wabbit  
#7 Posted : Tuesday, April 13, 2010 9:21:03 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)
See the similarity between Examples 5, 6 and 7, and this :-

Code:

BS:=H>Ref(HHV(H,20),-1);
BS:=BS AND Alert(BS=0,2);

TP:=200;
SL:=200;

tr:=
If(PREV=0,
BS*H,
If(H>PREV+TP OR L<PREV-SL,0,PREV));

{plot}
tr;


wabbit [:D]
oem7110  
#8 Posted : Tuesday, April 13, 2010 9:43:53 AM(UTC)
oem7110

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/30/2005(UTC)
Posts: 120

wabbit wrote:

BS:=BS AND Alert(BS=0,2);
Thank wabbit very much for assisting on Metastock. Could you please tell me what above code does in this position? Thank you very much for suggestions Eric
wabbit  
#9 Posted : Tuesday, April 13, 2010 6:10: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)
It's a different way of coding the Cross() function.


wabbit [:D]

oem7110  
#10 Posted : Wednesday, April 14, 2010 12:48:11 AM(UTC)
oem7110

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/30/2005(UTC)
Posts: 120

wabbit wrote:

Code:

BS:=H>Ref(HHV(H,20),-1);
BS:=BS AND Alert(BS=0,2);

TP:=200;
SL:=200;

tr:=
If(PREV=0,
BS*H,
If(H>PREV+TP OR L<prev-SL,0,PREV));

{plot}
tr;

Hi wabbit: When I exit the position, which could be taking profit or stop loss. I would like to create another signal to trigger a short position if and only if Low is lower than the reference level (Stop Loss only), but I get no idea on how to differentiate whether the exit is taking profit or stop loss. Could you please give me any suggestions on this coding? Thank you very much for any suggestions
Eric
wabbit  
#11 Posted : Wednesday, April 14, 2010 1:19:55 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)
Make the exit portion of the code return a value, maybe something like :-

Code:

BS:=H>Ref(HHV(H,20),-1);
BS:=BS AND Alert(BS=0,2);

TP:=200;
SL:=200;

tr:=
If(PREV=0,
BS*H,
If(H>PREV+TP,-1, if(L<PREV-SL,-2,PREV)));

{plot}
tr;


If the trade exited on TP the value will be -1.
If the trade exited on SL the value will be -2.



wabbit [:D]

oem7110  
#12 Posted : Wednesday, April 14, 2010 1:26:48 AM(UTC)
oem7110

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/30/2005(UTC)
Posts: 120

Thanks thanks thanks ... again Eric
oem7110  
#13 Posted : Thursday, April 15, 2010 8:17:05 AM(UTC)
oem7110

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/30/2005(UTC)
Posts: 120

Hi wabbit: Does the following function perform what you describe? Thank you very much for any sugestions Eric ExtFml(“forum.DateRange", Enter Long, Exit Long, Enter Short, Exit Short)
wabbit  
#14 Posted : Thursday, April 15, 2010 9:05: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)
No... because you have the Forum.Latch function arguments but are specifying the Forum.DateRange function call!?

In the Files section is a user manual for the Forum.dll, I suggest you read that too.


wabbit [:D]

oem7110  
#15 Posted : Thursday, April 15, 2010 9:24:06 AM(UTC)
oem7110

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/30/2005(UTC)
Posts: 120

It should be following function, instead of forum.DateRange ExtFml(“forum.Latch",LE,LX,0,0); which describes this external formula to only trigger a BUY signal if (and only if) a buy signal has not been previously set without a sell signal, or the last signal was a sell signal. Do you think whether forum.Latch will be another approach to solve my issue or not? Thank you very much for any suggestions Eric
wabbit  
#16 Posted : Thursday, April 15, 2010 9:39:09 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 Forum.Latch has no method to store the trade entry price data, so doesn't have take profit or stop loss capabilities. It was designed to assist trades keep track of their trades when they have discrete LE, LX, SE and SX signals. If you want a .dll solution then you will require the MDK and knowledge of C/C++, Pascal and/or PowerBasic. You can still achieve what I think you want by using a PREV based latch, but it will be slower to execute than the external function call.

I know there are plenty of examples on this forum of these latches, just do a search. Even if you don't find a code section that specifically addresses your precise needs, then you should be able to find enough hints, tips and ideas to complete your project.


wabbit [:D]

oem7110  
#17 Posted : Thursday, April 15, 2010 10:08:37 PM(UTC)
oem7110

Rank: Advanced Member

Groups: Registered, Registered Users, Subscribers
Joined: 12/30/2005(UTC)
Posts: 120

Thank you very much for suggestions Eric
wabbit  
#18 Posted : Thursday, April 15, 2010 11:01:39 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)
All users of the Forum.Latch should be aware the logic was written by a trader to suit his own style and that it might not suit everyone's trading style and risk. There is a truth table posted (somewhere) on the Forum to show how the latch responds to the different combination of input signals; do a search and take the time to discover if the latch meets individual requirements before using in real trades.

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.