PDA

View Full Version : Errors in trade log


helene
16th February 2004, 03:39 AM
Hi all,

Was wondering if anyone could help me with a coding issue I have.

When running my exploration in Metastock, I have some rejected stocks with the following error messages for the exit price:

Error found in LONG trade [XFJ] on 11-Feb-2002 caused by Invalid Exit Price Data.
Details: [Exit Price(4281.841309)] < [Exit Price Low(4302.500000)]

Error found in LONG trade [XFJ] on 12-Feb-2004 caused by Invalid Exit Price Data.
Details: [Exit Price(4044.815674)] < [Exit Price Low(4091.000000)]

Error found in LONG trade [XHJ] on 31-Dec-2002 caused by Invalid Exit Price Data.
Details: [Exit Price(3442.092529)] < [Exit Price Low(3462.800049)]


I think that there must be an error in my code somewhere but I cannot find it and am having trouble working out why the system is exiting on these days and where it is getting the exit price data from. The code for my system below - the first part is the code is for the formula used in the system:


Fml("Guppy MMA (Short Term)")>Fml("Guppy MMA (Long Term)") AND Mov(C,3,E)>Mov(C,15,E) AND Mov(C,15,E)>Mov(C,30,E)+0.4*ATR(30) AND C>Mov(C,15,E) AND Ref(H,+1)>H


LongEntryTrigger := Fml("Entry Conditions Index");
LongEntryPrice := Ref(H,-1);
LongEntryPrice := If( OPEN > Ref(H,-1), OPEN, Ref(H,-1));
LongExitTrigger := ExtFml("TradeSim.TrailingStop",
TRIGGER,
LONG,
1.75*ATR(30),
L,
LOW);

LongExitPrice := HighestSince(1,Fml("Entry Conditions Index"),L) - 1.75*(ATR(30));
LongExitPrice:= If( OPEN < (HighestSince(1,Fml("Entry Conditions Index"), L) - 1.75*(ATR(30))), OPEN, (HighestSince(1,Fml("Entry Conditions Index"), L) - 1.75*(ATR(30))));

LongInitialStop:= Ref(H,-1)-1*ATR(30);

ExtFml("TradeSim.Initialize");
ExtFml("TradeSim.EnableDelayOfEntryByOneBar");
ExtFml("TradeSim.EnableProtectiveStop",0);
ExtFml("TradeSim.SetExitPriceToInitialStop");
ExtFml("TradeSim.SetStopGapPriceToOpen");
ExtFml("TradeSim.RecordTrades","INDEX SYSTEM",
LONG,
LongEntryTrigger,
LongEntryPrice,
LongInitialStop,
LongExitTrigger,
LongExitPrice,
START);

Any help would be greatly appreciated.

Regards
Helene

:?: :?: :?:

David Samborsky
16th February 2004, 01:02 PM
This error occurs because either or both the entry and exit prices fall outside the daily price range. You must contain the prices so that they fall within the daily range otherwise TradeSim will reject the trades.

Jose
17th February 2004, 05:31 PM
In other words:

---8<---------------------------------------------------------
LongEntryPrice:=If(OPEN>Ref(H,-1),OPEN,Ref(H,-1));
LongEntryPrice:=If(LongEntryPrice>H,H,LongEntryPrice);
LongEntryPrice:=If(LongEntryPrice<L,L,LongEntryPrice);
---8<---------------------------------------------------------

jose '-)

Jose
17th February 2004, 05:37 PM
MS code for the exit:

---8<---------------------------------------------------------
LongExitPrice:=HighestSince(1,Fml("Entry Conditions Index"),L)-1.75*(ATR(30));
LongExitPrice:=If(OPEN<LongExitPrice,OPEN,LongExitPrice);
LongExitPrice:=If(LongExitPrice>H,H,LongExitPrice);
LongExitPrice:=If(LongExitPrice<L,L,LongExitPrice);
---8<---------------------------------------------------------

jose '-)

Jose
17th February 2004, 05:54 PM
On second thoughts, your entry/exit price is not realistic.
Trying to buy/sell at the Open after the LongEntryPrice/LongExitPrice conditions have been met, is not possible.

Introducing slippage will go some way to make this matter more realistic.

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

Slippage:=0.75; {Slippage %}

LongEntryPrice:=If(OPEN>Ref(H,-1),OPEN,Ref(H,-1));
LongEntryPrice:=LongEntryPrice*(1+Slippage/100);
LongEntryPrice:=If(LongEntryPrice>H,H,LongEntryPrice);
LongEntryPrice:=If(LongEntryPrice<L,L,LongEntryPrice);

LongExitPrice:=HighestSince(1,Fml("Entry Conditions Index"),L)-1.75*ATR(30);
LongExitPrice:=If(OPEN<LongExitPrice,OPEN,LongExitPrice);
LongExitPrice:=LongExitPrice*(1-Slippage/100);
LongExitPrice:=If(LongExitPrice>H,H,LongExitPrice);
LongExitPrice:=If(LongExitPrice<L,L,LongExitPrice);

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

jose '-)

helene
21st February 2004, 04:57 AM
Thanks for your help Jose, all works well now.

Regards
Helene :)