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)
|
Below is an example of a Prev-based latch that references the entry signal:
[code:1:e15caf7f1f]
=======================
EntryPrice related exit
=======================
---8<------------------------------
{ EntryPrice reference, stoploss code example
for use in EntryPrice-related exit }
{ http://www.metastocktools.com }
{ User inputs }
x:=Input("EntryPrice: [1]Open, [2]High, [3]Low, [4]Close",1,4,3);
plot:=Input("[1]true EntryPrice, [2]System signals",1,2,1);
Stoploss:=1-Input("StopLoss %",0,100,4)/100;
{ Sample system Entry & Exit signals }
entry:=Cross(C,Mov(C,21,E));
exit:=Cross(Mov(C,10,E),C);
{ Reference Open/High/Low/Close choice }
prc:=If(x=1,O,If(x=2,H,If(x=3,L,C)));
{ Reference system entry price,
and apply to exit as a stoploss }
trade:=If(PREV=0,If(entry,prc,0),
If(exit OR C<PREV*Stoploss,0,PREV));
{ New entry signal }
NuEntry:=trade>0 AND Alert(trade=0,2);
{ New exit signal }
NuExit:=trade=0 AND Alert(trade>0,2);
{ True entry price }
EntryPrice:=ValueWhen(1,NuEntry,prc);
{ Plot on price chart }
If(plot=1,EntryPrice,NuEntry-NuExit)
---8<------------------------------
[/code:1:e15caf7f1f]
jose '-)
|