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;