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

Notification

Icon
Error

2 Pages<12
Options
Go to last post Go to first unread
redrunner  
#21 Posted : Thursday, September 7, 2006 4:58:49 PM(UTC)
redrunner

Rank: Member

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

Wabbit,

I think incorrect signals are due to not stored EntryPrice ( back to initial problem ):

If an other entry signal ( C > Mov(C,20,E) ) arrives during an opened trade, all the calculations started on EntryPrice at opening the trade will be continued with next "fake" EntryPrice belongs to next valid EntLong signal ( EntryPrice:=ValueWhen(1,EntLong,C); ).

This phenomenon results incorrect StopLoss (sometimes moves it DOWN)...

What is your oppinion about it?

redrunner

wabbit  
#22 Posted : Thursday, September 7, 2006 6:38:06 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,

There is fiddling around required that I don't have time to do right now, I am just too busy. What you need to do is to define the exit levels INSIDE the binary latch. Make an attempt to do this yourself, posting your progress and I am sure someone will point you in the right direction if need more help.

wabbit [:D]
wabbit  
#23 Posted : Thursday, September 7, 2006 7:16:06 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)
Maybe now I can stop thinking about this and get on with the things I am supposed to be doing.....

Code:

x:=C>Mov(C,20,S);
EntLong:=x AND Alert(x=0,2);

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

{Binary Latch}
Tr:=
If(PREV=0,
If(EntLong,CLOSE,0),
If(C<
Max(
HighestSince(1,PREV=0,HighestSince(1,PREV=0,H)-(If(C=PREV,2,If(C<PREV+4*AvgTR,3.5,If(C<PREV+6*AvgTR,3,2.5))))*AvgTR),
HighestSince(1,PREV=0,HighestSince(1,PREV=0,C)-2.5*AvgTR)
)
,0
,PREV));

{plot}
Tr;


The code is NOT fast and it uses a bucket load of processing power.... but it achieves the results?

I will leave this for you to check, I really don't have the time!



wabbit [:D]

[Edited code : small difference in results]
redrunner  
#24 Posted : Friday, September 8, 2006 2:07:42 AM(UTC)
redrunner

Rank: Member

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

Wabbit,

I really appreciate your efforts and thanks for huge help!
There is an other -but much smaller- bug somewhere but I will try to polish this code alone.

Thanks to you AGAIN.

redrunner

wabbit  
#25 Posted : Friday, September 8, 2006 5:12: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)
There is a logic error with the trailing stop.... I am sure you will figure it out


wabbit [:D]
redrunner  
#26 Posted : Friday, September 8, 2006 9:53:07 AM(UTC)
redrunner

Rank: Member

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

Wabbit,

I hope so but without your knowledge it is much harder... It seems that 1st part of Max() doesn't work well. Problem can be with bolded referings:

Max(

HighestSince(1,PREV=0,HighestSince(1,PREV=0,H)-(
If(C=PREV,2,If(C<PREV+4*AvgTR,3.5,If(C<PREV+6*AvgTR,3,2.5))))*AvgTR),

HighestSince(1,PREV=0,HighestSince(1,PREV=0,C)-2.5*AvgTR)
)

I do not understand perfectly that your complex backward refering but feel do not equals with

if( C= EntryPrice, 2,
if( C< EntryPrice + 4*AvgTR, 3.5,
if( C< EntryPrice + 6*AvgTR, 3, 2.5)


That is actual situation :(
Any idea is welcomed if you have 1 minit (which equals with my 1week wenking)

Thank you very much

redrunner

redrunner  
#27 Posted : Friday, September 8, 2006 4:28:44 PM(UTC)
redrunner

Rank: Member

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

Master Wabbit,

Big Smile [:D]

Bug is found and code is working...
Thank you very much, again!!!!

redrunner

wabbit  
#28 Posted : Friday, September 8, 2006 8:17:06 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,

For the other Forum members who have been following the thread, can you please post the completed, error-free code.


wabbit [:D]
redrunner  
#29 Posted : Sunday, September 10, 2006 3:02:43 PM(UTC)
redrunner

Rank: Member

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

Wabbit,

I think condition C=PREV caused the problem therefore it was removed

Max(
HighestSince(1,PREV=0,HighestSince(1,PREV=0,H)-(
If(C<PREV+4*AvgTR, 3.5,
If(C<PREV+6*AvgTR, 3, 2.5))))*AvgTR),
HighestSince(1,PREV=0,HighestSince(1,PREV=0,C)-2.5*AvgTR
)

Rest of code is acccording to your original idea.
Thnx again.

redrunner

wabbit  
#30 Posted : Sunday, September 10, 2006 5:16:06 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,

You have 'fixed' the logic error, but I am not sure whether you have maintained the intention of the original code (which also contained the same logic error)?

redrunner wrote:
Code:

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))));


NOTE: The PREV here is redundant because every condition is accounted for, there is no 'fall through' so could have been better wrirtten:
Code:

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



Using an example, lets say the EntryPrice is $1.00

As we are buying at the close, the very value of Mplier is when C=EntryPrice and is set to a value of 2.

What happens if the closing price increases?

If the close price deviates at all from the EntryPrice ($1.00) BUT it happens to be less than EntryPrice plus 4 AvTR then Mplier will be set to 3.5

If the close price is higher than EntryPrice plus 4 AvTR but less than EntryPrice plus 6 AvTR then Mplier will be set to 3.

If the close price is higher than EntryPrice plus 6 AvTR then Mplier will be set to 2.5

What happens if the close is less than the EntryPrice?

If the close price deviates at all from the EntryPrice ($1.00) BUT it happens to be less than EntryPrice plus 4 AvTR then Mplier will be set to 3.5 You were setting a WIDER stop if the price has fallen below the EntryPrice?

This is where I thought the logic might have been wrong?

The conditions should be?

C <= Entry Price MPlier=2
C< EntryPrice + 4 AvTR MPlier=3.5
C< EntryPrice + 6 AvTR Mplier=3.0
otherwise (C>=EntryPrice + 6 AvTR) Mplier=2.5

Code:

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


or in the latch as:
Code:

If(C<=PREV, 2,
If(C<PREV+4*AvgTR, 3.5,
If(C<PREV+6*AvgTR, 3, 2.5))))*AvgTR),



wabbit [:D]

redrunner  
#31 Posted : Wednesday, September 13, 2006 3:02:42 AM(UTC)
redrunner

Rank: Member

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

Wabbit,

You are right but in the meantime I have found a newer bug in binary latch. Look at simplified code:

{Binary Latch}
Tr:=
If(PREV=0,
If(EntLong,C,0),
If(C<
HighestSince(1,PREV=0, HighestSince(1,PREV=0,H)-
(
If(C<PREV +4*AvgTR, 3, 1) *AvgTR)
));
,0
,PREV));

Bolded part doesn't work. It seems any other value except PREV makes conditional multiplier part working but with PREV does nothing.

Do you have any idea?

redrunner

wabbit  
#32 Posted : Wednesday, September 13, 2006 4:35:56 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)
Try placing brackets around the terms:

If(C < (PREV + 4*AvgTR), 3, 1) *AvgTR)

Mea Culpa, I should have checked the operator precedence.



wabbit [:D]



P.S. Check your inbox too for PM

wabbit  
#33 Posted : Wednesday, September 13, 2006 6:04:20 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)
For those playing along at home...

I had forgotten about this idiosyncrasy with MS and the PREV function... Roy promises to discuss some issues with the PREV function in his next installment of "MetaStock Tips and Tools", but I am sure he will not mind me getting in early to show this 'bug' and resolve this thread issue.

You should have the PREV function standalone from any other computations (in some other circumstances it will handle multipliers but its safer not to do anything to a PREV and work on the other side of the equality of comparative indicator).... If you have an expression involving a PREV and it does not work exactly like it should, the first step is to isolate the PREV on one side of the equality or comparative indicator...

e.g.

{code not working as intended}
If(C < (PREV + 4*AvgTR), 3, 1) *AvgTR)

{repaired by}
If((C - 4*AvgTR) < PREV, 3, 1) *AvgTR)

Notice the PREV is no longer part of any computation but is isolated to the right of the comparison.


Roy will be dedicating more time and effort to explain these sorts of PREV issues, but for now, I hope the immediate problems are resolved.


wabbit [:D]


P.S. Non-subscribers will have no idea what MSTT is, so check out http://www.metastocktips.co.nz/
Jose  
#34 Posted : Thursday, September 14, 2006 4:20:18 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)
wabbit wrote:
{code not working as intended}
If(C < (PREV + 4*AvgTR), 3, 1) *AvgTR)

{repaired by}
If((C - 4*AvgTR) < PREV, 3, 1) *AvgTR)

Notice the PREV is no longer part of any computation but is isolated to the right of the comparison.
Huh? I don't see any difference between the two. jose '-)
wabbit  
#35 Posted : Thursday, September 14, 2006 5:45:20 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 is an idiosyncrasy. I don't know how or why? I don't even think the problem is consistent? All I know about the problem is that I have seen it before and it was solved by isolating the PREV to one side of the equation. The problem seems to occur only if I attempt to perform addition or subtraction on the PREV, not multiplication or division?? Curious.

Anyway, pictorially the difference can be seen in these results:

The top indicator is a hand coded, single date based entry with a 'hand coded' trailing stop computation; the middle indicator is the problematic indicator which uses code If(C < (PREV + 4*AvgTR), 3, 1) *AvgTR); and the last indicator uses If((C - 4*AvgTR) < PREV, 3, 1) *AvgTR).

Logically these two code snippets are the same? But their implementation in MS is different???

If someone knows why, I would be happy to hear the answer....



wabbit [:D]


wabbit attached the following image(s):
bhp.png
Jose  
#36 Posted : Friday, September 15, 2006 12:34:30 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)
wabbit wrote:
If(C < (PREV + 4*AvgTR), 3, 1) *AvgTR); If((C - 4*AvgTR) < PREV, 3, 1) *AvgTR).
Wabbit, there are no differences whatsoever that I could find between the two formulae plots tested on over 1000 charts. For anyone else that would like to test this, here are the two corrected formulae with the extra bracket removed: If(C<(PREV+4*ATR(10)),3,1)*ATR(10); If((C-4*ATR(10))
wabbit  
#37 Posted : Friday, September 15, 2006 3:02:47 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)
As I said Jose,
wabbit wrote:
... it is an idiosyncrasy. I don't know how or why? I don't even think the problem is consistent?


Only one stock was giving me the erroneous return??? I was alerted to the difference by another Forum member. Even then, I only saw error, sometimes? There is some (minor, sporadic) inconsistency either with a) MS, b) the data, or c) both.

Unfortunately, I have overwritten the MSFL code that had / caused the error, but the graphs already posted above demonstrate that something was awry. You will have to take my word, the only difference between the second indicator and the third indicator in the graph above is the location of the PREV function in the logic. Redrunner and I were making multiple changes to the code, on the fly, so versions were not retained. I only took the screen snapshot to prove (to myself) that the error was there.

It is a very hard error to replicate. I have seen it less than five times since I have been using (abusing) MS.... Each time, a solution has been to isolate the PREV. (There may be other fixes, but this worked each time. I don't know why?)

As I said, if someone knows the answer, I would be happy to hear it. (I will guess the answer can only be accurately provided by looking at the MS source code?)


wabbit [:D]


wabbit  
#38 Posted : Friday, September 15, 2006 3:43:46 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)
... and the code was more than a one line function... with multiple PREV statements...


wabbit [:D]



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