Normal
0
false
false
false
MicrosoftInternetExplorer4
classid="clsid:38481807-CA0E-42D2-BF39-B33AF135CC4D" id=ieooui>
<STyle>
st1\:*{behavior:url(#ieooui) }
<STyle>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:"Table Normal";
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
Hi Dan
Here’s a basic example of how a PREV-based
latch (the "R" variable) might operate. The latch is formed in three
stages that are defined by cascading If() functions.
The first If() function checks that the
latch was previously reset (=0) or reset on the previous bar (<0). If those
conditions are TRUE then if N is TRUE the latch sets to a value of C+2.5*ATR(21).
In the event that the latch was already
set then the second If() function takes control and monitors for a pyramid
entry signal, looking for a target of 2.5*ATR(21) above the first entry’s
CLOSE. That value is fixed by the latch at the time of entry. The new target set
is the higher of the existing and new targets.
If a pyramid entry signal is not
present then control is passed to the third If() function. It monitors for an
exit signal and produces a negative spike as the latch resets when one is seen.
If there is not an exit signal then the latch retains its PREV value.
{Dan's Trade Latch}
A:=2.5*ATR(21);
N:=C>Ref(HHV(C,20),-1); {primary
entry signal}
N:=N*Alert(N=0,2); {leading edge of N
signal}
X:=C<Ref(LLV(C,10),-1); {exit
signal}
X:=X*Alert(X=0,2); {leading edge of X
signal}
R:=If(0>=PREV, N*(C+A), {first
entry}
If(N*PREV>0,Max(PREV,N*(C+A)), {pyramid entry}
If(X,-PREV,PREV))); {exit - negative spike}
Abs(R); {entry price target}
There are many ways that this type of
latch can be tweaked to do various things. Entries are kept in sync with exits
by making all decisions within the one variable. Once you try to make decisions
across 2 or more variables you lose an element of control and run the risk of
your code contradicting your intentions.
The down side of using a PREV-based
latch is that each PREV adds significant processing overheads. Adding one extra
condition into the decision making process can add two or three PREVs and
eventually you’d end up with code that is so slow to run that for all practical
purposes it is quite useless.
This piece of code is just an example
that uses my interpretation of the information that you gave and not necessarily
the end product that I believe you should use. You should study the "R"
and how it works until you are reasonably comfortable with it and can answer
all your own questions. Then you may want to experiment and ask "what
happens if I do this or that". A useful technique that might help is to
create this as an indicator and see what various alternative outputs look like
- "R", "ABS(R)", "R>0", "(R>0)*Alert(R=0,2)"
and so on.
Hope this helps.
Roy