PureBytes Links
Trading Reference Links
|
Hi Alan
> I couldn't get any further in trying to understand your latch-based
> stop.
I've deleted your previous post so will use this one to comment on the different points.
> I'm fairly certain I understand how "Trade" is being calculated (see
> my previous post below).
>
> I know that the last line (Abs(Trade)....) returns zero when Trade is
> N/A. Otherwise, it returns the close one bar after the buy price.
> However, I don't see the objective of this line.
I'll take your word for it that it holds the CLOSE one bar after the buy price. The intention is
that it holds the CLOSE of the entry bar, i.e. the actual entry price. The point of the code is to
lock in a price or indicator value that is pertinent to the trade entry, and that can be used to
monitor the course of the trade and generate an exit at any required threshold.
If my signal is off by one bar (and it might be off for you and correct for me depending on a number
of factors) then it's easily enough fixed using any appropriate technique. The detail is usually
easy once you have the big picture. The big picture is that the latch is set on entry to hold a
value which can be used to create an exit. The timing is detail, though admittedly it's not always
as aesy as we might imagine it should be. It's up to the individual to compensate for entry delays
or whatever.
> {PREV Latch Exercise}
> Set:=Cross(Mov(C,15,E), Mov(C,25,E));
> Reset:=Cross(Mov(C,25,E), Mov(C,15,E));
> Trade:=If(PREV<=0,If(Set,1,0),
> If( Reset {independent exit} OR
> C>=ValueWhen(1,PREV=0,C)*1.2 {20% profit exit} OR
> C<=ValueWhen(1,PREV=0,C)*0.9 {10% loss exit} ,-1,1));
> Abs(Trade)*ValueWhen(1,Ref(Trade=0,-1),C); {trade active/entry price}
> Q: When is Trade = -1? {a sell}
> A: Only when Trade(-1) = 1 AND (Reset = 1 OR C>20% profit OR C<10%
> stop)
> In Queen's English: a sell can only follow a buy, and only if the
> EMA signal crossed down, or 20% profit, or 10% loss.
Answer.
When a trade is active (previous value of 1) AND (Reset = 1 OR C>20% profit OR C<10%
Trade = -1 is the effect, not a cause.
Keep in mind that each If() must be processed before the next one can be considered. The logical
flow through the 'Trade' variable will depend on what conditions are true along the way.
There's another issue here but I'll tie it in with a later question (if I remember).
> Q: When is Trade = 1? {a buy}
> A: If (a) Trade(-1) = 0 or -1 AND Set = 1
> In English: When the previous trade was a sell, or neutral
> (neutral
> itself can only occur after a sell or another neutral) and EMA
> crossed up.
I'd prefer to think of "neutral" as OFF. Both +1 and -1 say "trade in progress". The difference
with -1 is that this says "trade in progress but this is the last bar of the trade". The reason for
only allowing the Trade variable to set when it was previously off or about to be set off is that
this variable is a memory device. There is no point in having a memory device if any set signal can
change the memory device. This last comment isn't critical to a "binary" latch bit it IS critical to
a "price" latch because the set will allow the stored price to change. For binary storage it's not
an issue because once it's on it's on. However to preserve the functional integrity of a price latch
the code checks for off, or will be off on the next bar, before allowing a set to be forced. For a
price latch this would be "set to a new price", not what we necessarily want.
Notice that this latch could operate in pure binary, i.e 1 or 0. Have you wondered why I switch it
to -1 for one bar? It's a matter of timing. If it resets immediately to 0 then notice that the
output from the latch tells us that the trade is reset one bar before it actally is. When the Trade
is still effectively active and in the process of being reset the plot will tell us that it's
already reset. The change to -1 is used to extend the active state (albeit as a negative value) by
one bar. This allows the reset bar to be considered as the last bar Trade is active rather than the
first bar it is inactive (off).
> Q: What is ValueWhen doing?
> A: We want the closing price of the bar for which the immediately
> previous bar was the last occurrence of Trade=0 {did you get that?}
Let's deal with the Abs() function first. It just converts the -1 to +1 giving the 1 bar extension
of the active signal. This technique makes the PREV based latch line up with the Simple latch (
BarsSince(Set or Init)<BarsSince(Reset or Init) ).
I mentioned "Price latches" which can store any value we might want. The binary latch form allow me
to remove one PREV, or even two if I'm using a negative spike for the last active bar. Removing two
PREV's is a big deal because it requires significant overheads to calculate each PREV. By using
ValueWhen() following the Trade variable I restore the ability to remember the price without having
to use the two PREV's in the code. Actually the saving is three PREV's.
"ValueWhen(1,Ref(Trade=0,-1),C)" after the Trade Variable is the same as "ValueWhen(1,PREV=0,-1),C)"
inside the Trade variable. If the latch stores a price, say, then ValueWhen is not necessary inside
the variable because just "PREV" will tell us what we want to know. However ValueWhen inside the
latch can allow us to access values prior to the latch being set. It's just a mechanism for
effecting the appropriate sample timing.
Abs(Trade)*ValueWhen()
Is just a shorter way of writing If(). Multiply a value by one or zero gives an answer of value or
zero.
Hope this helps.
I'm sending you my Word document on latches privately. You may be able to repay the favour by
pointing out gaps or errors in my document.
Regards
Roy
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/BefplB/TM
---------------------------------------------------------------------~->
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/equismetastock/
<*> To unsubscribe from this group, send an email to:
equismetastock-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|