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

Notification

Icon
Error

2 Pages12>
Options
Go to last post Go to first unread
redrunner  
#1 Posted : Wednesday, September 6, 2006 4:42:50 PM(UTC)
redrunner

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/27/2006(UTC)
Posts: 24

Dear Experts,

I would like to get a helping hand to solve following problem:


- LongEntry condition gives frequent signals (sometimes during an opened postion)

- After the 1st one, all the others must be abardoned until a LongExit signal arrives

- LongExit conditions (stop and profit target) based on EntryPrice

- EntryPrice must be stored util a LongExit signal arrives

- EntryPrice must be captured at next LongEntry signal

Problem:
========
I have tried latching without any success because I can define Reset Condition
BELOW the binary latch, only
(which is not accepted, of course)

Entry:= Fml("EntryRules");

EntryPrice:= If(PREV=0,If(Entry, C , 0),
If( Exit , 0, PREV));


{ Calculation of Exit Conditions for trailing stop and profit target}
{ ... }


Exit:= ...

Thanks in advance for any help

redrunner

Bulli  
#2 Posted : Wednesday, September 6, 2006 5:42:09 PM(UTC)
Bulli

Rank: Advanced Member

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

Hi redrunner,

Can I ask you why all this trouble while we have the Latch function of the forumdll.dll?

just call the function and that it, Or am I missing something ???

Download the forumdll.dll and its manual

http://forum.equis.com/files/default.aspx

also run a serach in the forum on Latch, the subject have been killed many times here among some experts in the forum. (they are too many to say names) thanks.

Bulli

wabbit  
#3 Posted : Wednesday, September 6, 2006 5:59:53 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)
redrunner,

As your system is a little more complicated than it can handle, the Forum.dll latch function wont be of much use to you in this particular situation, but I strongly suggest you check it out. Get it free from the downloads section. You will have to use Roy Larsen's latching code from some time ago...Code:

N:=Fml("EntryRules");
X:=Fml("ExitRules");
ProfitStop:=1.2; {percentage multiplier of the trade entry price}
StopLoss:=0.9; {percentage multiplier of the trade entry price}

Tr:=If(PREV=0,If(N,CLOSE,0),If(X OR C>=PREV*ProfitStop
OR C<=PREV*StopLoss,0,PREV));
Tr;
Hope this helps. wabbit [:D]
wabbit  
#4 Posted : Wednesday, September 6, 2006 6:07:35 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)
Bulli,

The Forum.Latch doesn't play nicely if you want to exit your trade based on the trade entry price. It can be combined with, say, Richard Dale's Trailing Stop Loss, but Richard's solution doesn't do profit targets, so we are still short some capability that needs to get trapped with PREV.

At some point, I would like to rewrite the Latch again to allow it to be self-referencing with trailing stops and profit targets. I cannot see this hapening in the near future as I am fully swamped with work, Uni, travel to India (for three months later at the end of the year) then straight back into work and Uni again next year. Does someone else want to take up this task?


wabbit [:D]
Bulli  
#5 Posted : Wednesday, September 6, 2006 6:15:28 PM(UTC)
Bulli

Rank: Advanced Member

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

Yes Wabbit,

But I overcome this problem without using PREV by using the GV.dll to store the entry price and therefore set the profit target and the loss exit.

I had no problem with them together, they are working fine.

(By the way I am one of your fans)

Bulli

Bulli  
#6 Posted : Wednesday, September 6, 2006 6:18:41 PM(UTC)
Bulli

Rank: Advanced Member

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

Here is an exemple of what I am saying:

ExtFml( "GV.SetVar","LEntry" , ValueWhen( 1, (Cross((Mov((RSI(12)-LLV(RSI(12),12)) / (HHV(RSI(12),12)- (LLV(RSI(12),12))),3,E)*100),25)), C) );
LE:= Cross((Mov((RSI(12)-LLV(RSI(12),12)) / (HHV(RSI(12),12)- (LLV(RSI(12),12))),3,E)*100),25)
AND
C>(Ref(Mov(C,25,S),-5))
OR
C> (ExtFml( "GV.GetVar","LEntry" )* 1.02);
LX:= Cross(20,(Mov((RSI(14)-LLV(RSI(14),14)) / (HHV(RSI(14),14)- (LLV(RSI(14),14))),3,E)*100))
OR
C<( ExtFml( "GV.GetVar","LEntry" )*.97);
SE:=0;
SX:=0;
B:= ExtFml("ForumDll.Latch",LE,LX,SE,SX);
B>0 AND Ref(B,-1)<=0

I Hope this coding makes sense.

Bulli

wabbit  
#7 Posted : Wednesday, September 6, 2006 6:21:25 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)
Bulli,

I hadn't thought of using the GV ! Don't know why, I just haven't! [:D]

Perhaps you might like to post a code snippet showing the combination of the Forum.dll, the GV.dll (I assume you dont need the AdvancedStop.dll?) for redrunner and the rest of us! [;)]



wabbit [:D]
redrunner  
#8 Posted : Wednesday, September 6, 2006 6:24:00 PM(UTC)
redrunner

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/27/2006(UTC)
Posts: 24

Dear Wabbit,

Thanks for quick and useful advice.
My oppinion is the same about Forum.dll... It would be useful for me if can be use on this way:

ExtFml("forum20.Latch",Set,0,0,0);
{....}
ExtFml("forum20.Latch",0,Reset,0,0);


... but works on other way:(



My problem with your suggestion:
because of non-latched EntryPrice, "ExitRules" containing ExitCond calculations will be recalculated with different Close values at preceding bars.

ExitRules contains a Chandelier Stop + Profit target Exit which is calculated from EntryPrice...

... but I do not know how

... but I am sure that You know:)

redrunner

Bulli  
#9 Posted : Wednesday, September 6, 2006 6:24:21 PM(UTC)
Bulli

Rank: Advanced Member

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

Sure Wabbit, would be gald to do that.

Bulli

redrunner  
#10 Posted : Wednesday, September 6, 2006 6:34:55 PM(UTC)
redrunner

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/27/2006(UTC)
Posts: 24

Bulli,

Thanks for your comment.

How can I get mentioned .dll and its manual? It seems to be good...

redrunner

wabbit  
#11 Posted : Wednesday, September 6, 2006 6:47:04 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)
As these posts are overlapping, I will address one at a time to avoid confusing everyone, especially ME!

Bulli,

I hate to be the bearer of bad news, but your code is moving the value of the price stored in the GV.dll whilst a trade is already open i.e. it changing the "entry price". This is the problem, you are writing the value to the variable on the last instance on the entry criteria being true. If the trade is already open and the entry is again true the new value is still written to the global variable.

Because of the points above, your code can be re-written without the GV.dll with the same effects:

Code:

N:=Cross((Mov((RSI(12)-LLV(RSI(12),12))/(HHV(RSI(12),12)-(LLV(RSI(12),12))),3,E)*100),25);

pr:=ValueWhen(1,N,C);

LE:=N
AND
C>(Ref(Mov(C,25,S),-5))
OR
C>(pr * 1.02);

LX:= Cross(20,(Mov((RSI(14)-LLV(RSI(14),14)) / (HHV(RSI(14),14)- (LLV(RSI(14),14))),3,E)*100))
OR
C<(pr * 0.97);

B:= ExtFml("Forum2.Latch",LE,LX,0,0);

{plot}
pr;
B>0 AND Ref(B,-1)<=0




See the effect I am trying to highlight in the attached image...

wabbit [:D]
wabbit attached the following image(s):
latch.png
Bulli  
#12 Posted : Wednesday, September 6, 2006 7:02:43 PM(UTC)
Bulli

Rank: Advanced Member

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

Wabbit,

There is no bad news do not worry, I am not using this for actual trading. It was just an example.

Thanks for pointing it out though.

Bulli

wabbit  
#13 Posted : Wednesday, September 6, 2006 7:03:22 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)
P.S. My code doesn't fix the problem either...
Bulli  
#14 Posted : Wednesday, September 6, 2006 7:10:00 PM(UTC)
Bulli

Rank: Advanced Member

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

redrunner wrote:

Bulli,

Thanks for your comment.

How can I get mentioned .dll and its manual? It seems to be good...

redrunner

Redrunner,

for the Forumdll.dll you get here along with the manual

http://forum.equis.com/files/default.aspx

for the GV.dll I cannot find the link anymore.

send me a PM with your e-mail I will send it to you, it is freely distributed.

Bulli

wabbit  
#15 Posted : Wednesday, September 6, 2006 7:17:53 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)
redrunner,

Does this help?

Code:

N:=Fml("EntryRules");
X:=Fml("ExitRules"); {independent exit strategy}

ProfitStop:=1.2; {percentage multiplier of the trade entry price}

Tr:=
If(PREV=0, {if no trade is open}
If(N,CLOSE,0), {if no trade is open and the entry condition is met then store the CLOSE price, otherwise indicate 0}

If(X {if a trade is open and the independent exit condition is met then exit (indicate 0)}
OR C>=PREV*ProfitStop {if a trade is open and we consider that we have made enough money then exit (indicate 0)}
OR C<HighestSince(1,PREV=0,C)-2*ATR(10) {if a trade is open and the price falls below the trailing volatility based stop then exit (indicate 0)}
,0
,PREV));


{plot}
Tr;



wabbit [:D]


redrunner  
#16 Posted : Thursday, September 7, 2006 3:18:18 AM(UTC)
redrunner

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/27/2006(UTC)
Posts: 24

Master Wabbit,

Thank you very much and sorry for causing you a headache but my problem is still exist.
If take a look at my code, you will see my challenge. Your code an my one should be integrated to get an entry rule dependent stoploss.

Thanks for any new idea

redrunner

==========================
Wabbit's code for latching
==========================

N:=Fml("EntryRules");

Tr:=
If(PREV=0, {if no trade is open}

If( N, CLOSE, 0), {if no trade is open and the entry condition is met
then store the CLOSE price, otherwise indicate 0}

If(

{ Exit Conditions }

,0 {if a trade is open and Exit condition is met then
exit (indicate 0)}
,PREV));

{plot}
Tr;

====================================================
My standalone Chandelier-YoYO Stop from a given date
====================================================

EntYR:= Input("Year",1980,2006,2006);
EntMTH:=Input("Month",1,12,2);
EntDY:= Input("Day",1,31,14);


EntLong:= Year()=EntYR AND Month()=EntMTH AND DayOfMonth()=EntDY;
Entryfulldate := (EntYR)+(EntMTH/12)+(EntDY/365);
Fulldate := Year()+Month()/12+DayOfMonth()/365;

Entry:= Entryfulldate <= Fulldate;
EntryPrice:= ValueWhen(1, EntLong, C);

AvgTR:= Mov( ATR(1),10,E );
Mplier:= If( C=EntryPrice, 2,
If( C < EntryPrice + 4*AvgTR, 3.5,
If( C < EntryPrice + 6*AvgTR, 3,
If( C >= EntryPrice + 6*AvgTR, 2.5,
PREV))));

HV:= Highest(ValueWhen( 1, Entry, H ));
HCV:=Highest(ValueWhen( 1, Entry, C ));

{Chandelier Exit}
DifferenceH:= Ref(HV - Mplier*AvgTR,0);
StopLossH:= Highest(ValueWhen(1, Entry, DifferenceH));

{YOYO exit}
DifferenceC:= Ref(HCV - 2.5*AvgTR,0);
StopLossC:= Highest(ValueWhen(1, Entry, DifferenceC));

{Selecting the stronger stop}
StopLoss:= Max( StoplossH, StoplossC );

{Binary Latch}
StopActivated:= (C < StopLoss);
State:= If( StopActivated, 1, PREV);

DrawnStopLoss:=If( State=0, Stoploss, PREV);
DrawnStopLoss;

wabbit  
#17 Posted : Thursday, September 7, 2006 5:23: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)
redrunner,

To start, have a look at your code and see what is redundant and what isn't. You can greatly simplify the code, making it easier to read, faster to function and better to manage.

The only step you had to do was to add my latch code to your system code.... You were soooo nearly there, but cest la vie....

I have taken the liberty to clean iut the code and add the latch. If it doesn't work exactly like you have planned then please point out where any errors occur and I will see if I can fix things.

Code:

EntYR:=Input("Year",1980,2006,2006);
EntMTH:=Input("Month",1,12,2);
EntDY:=Input("Day",1,31,14);

x:=Year()>EntYR OR (Year()=EntYR AND (Month()>EntMTH OR Month()=EntMTH AND DayOfMonth()>=EntDY));
EntLong:=x AND Alert(x=0,2);
EntryPrice:=ValueWhen(1,EntLong,C);

AvgTR:=Mov(ATR(1),10,E);

Mplier:=If(EntLong,2,
If(C<EntryPrice+4*AvgTR,3.5,
If(C<EntryPrice+6*AvgTR,3,
If(C>=EntryPrice+6*AvgTR,2.5,
PREV))));

HV:=HighestSince(1,EntLong,H)-Mplier*AvgTR;
HCV:=HighestSince(1,EntLong,C)-2.5*AvgTR;

{Chandelier Exit}
StopLoss:=Max(HV, HCV);

{Binary Latch}
Tr:=
If(PREV=0,
If(EntLong,CLOSE,0),
If(C<StopLoss
,0
,PREV));

{plot}
Tr;



Hope this helps.


wabbit [:D]

P.S. I am assuming the code you posted is the entire system? I thought you had some sort of profit stop too?
redrunner  
#18 Posted : Thursday, September 7, 2006 6:43:53 AM(UTC)
redrunner

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/27/2006(UTC)
Posts: 24

Wabbit,

You made an excellent work on my code!!! Much clearer and easier to understand. Thanks again...
That is the difference between a professional and a newbie coder.

But there are 2 problems:
1, Something is mistyped is your code because gives later signal than mine
e.g.: entry: 14.12.2005 XJO my exit: 18.01.2006 yours: 10.02.2006

2, My initial problem is still unsolved: how can be integrated this stand alone code with an entry signal generator (to avoid typing entry dates manually)

You were right about missing ProfitTarget exit. I can not integrate into the code because of same reason: I can not latch EntryPrice correctly. It works similar way to ChandExit (manual entry date input) at this moment.

I want all of those items to be integrated in one common code. That is my headache...
... and unfortunately yours :)


Thanks again
redrunner


wabbit  
#19 Posted : Thursday, September 7, 2006 7:09:18 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)
Whoops:

For Problem 1:
Make this change:

Code:

{Chandelier Exit}
StopLoss:=Max(HighestSince(1,EntLong,HV),HighestSince(1,EntLong,HCV));



For Problem 2:

You can create any criteria you like for the long entry....

e.g.

Code:

EntLong:=C>Mov(C,20,E);



For Problem 3: (the Profit Stop)

You have removed the profit stop criteria from an earlier post...

Code:

Tr:=
If(PREV=0,
If(EntLong,CLOSE,0),
If(C<StopLoss OR C>(ProfitMargin*EntryPrice)
,0
,PREV));



Hope this helps.

wabbit [:D]


redrunner  
#20 Posted : Thursday, September 7, 2006 7:54:30 AM(UTC)
redrunner

Rank: Member

Groups: Registered, Registered Users, Subscribers
Joined: 7/27/2006(UTC)
Posts: 24

Wabbit,

Now I can see what is in front of my eyes. Great and unbelivable quick work!!!

I have made tests and something seems not OK compared to my mechanical input version:

Chart: XJO
Entry rule: C>Mov(C,20,E)

Entry Exit
===== ====
02.12.2005 18.01.2006 - Correct
19.01.2006 08.02.2006 - Correct
09.02.2006 01.03.2006 - Incorrect
04.05.2006 - Correct

Has my mechanical one a bug?

redrunner

Users browsing this topic
Guest (Hidden)
2 Pages12>
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.