PDA

View Full Version : Exit coding


mary1
28th December 2007, 03:34 AM
Hi, anyone knows how to code a exit on the first close above entry price?

Jose
28th December 2007, 09:46 AM
Try adapting this indicator code to your own needs:

---8<----------------------------------------

{ Example entry signal - 1st bar of month }
NewMonth:=Month()<>Ref(Month(),-1) OR Cum(1)=2;
entry:=NewMonth;
EntryPrice:=ValueWhen(1,entry,C);

{ Exit signals }
exit:=C>EntryPrice;

{ Remove redundant signals }
init:=Cum(IsDefined(entry+exit))=1;
bin:=ValueWhen(1,entry-exit<>0 OR init,entry);
Entry:=bin*(Alert(bin=0,2)
OR entry*Cum(entry)=1);
Exit:=(bin=0)*(Alert(bin,2)
OR exit*Cum(exit)=1);

{ Plot signals in own window }
Entry-Exit

---8<----------------------------------------


jose '-)

mary1
29th December 2007, 03:06 AM
Hello Jose I wanted to implement the first close exit in system tester. The exit maybe the next bar or few bars from entry when the close successfully close above the entry price of the initial trade.

Jose
29th December 2007, 05:12 AM
Mary, don't waste any time on the System Tester - use TradeSim.


jose '-)

mary1
30th December 2007, 04:42 AM
Hello Jose, understand your point. Tradesim is far superior than the Ms tester. But wanted to optimise on some variable and trade sim does not support optimisation. How can the your exit be adapted for tester? Tried adapt the code but when exit price is inconsistent.

Jose
30th December 2007, 03:54 PM
Sorry, Mary - but the posted code is all I can help with.

jose '-)