View Full Version : End of day ENTRY stopped out at OPEN of same day?
MySystem
30th August 2005, 09:38 AM
I'd appreciate your help working out a problem regarding systems using end of day entry (EntryPrice:= CLOSE).
The problem is that about 10% of the trades generated/taken using the EntryPrice:= CLOSE are closed out on the same day at the OPEN PRICE of that day.
I cannot find anything obviously wrong?
Below is the entry, initial stop and trailing stop code that is generating the same day exit errors:
LongEntryTrigger:= Cross(MACD(),Mov(MACD(),9,E));
LongEntryPrice:= CLOSE;
LongInitialStop:= OPEN-1 * Ref(ATR(30),-1);
LongTrailStopTrig:=ExtFml("TradeSim.TrailingStop",Trigger,Long, 1 *ATR(10),H,L);
LongTrailStopPrice:= Ref(ExtFml("TradeSim.TrailingStop",Band,Long, 1 * ATR(10),H,L),-1);
LongTrailStopPrice:= If(O<LongTrailStopPrice,O,LongTrailStopPrice);
StartDay := 1;
StartMonth := 5;
StartYear := 2005;
EndDay := 31;
EndMonth := 8;
EndYear := 2005;
ExtFml("TradeSim.Initialize");
ExtFml("TradeSim.SetStartRecordDate",StartDay,StartMonth,StartYear);
ExtFml("TradeSim.SetStopRecordDate",EndDay,EndMonth,EndYear);
ExtFml("TradeSim.EnableProtectiveStop",0);
ExtFml("TradeSim.SetStopGapPriceToOpen");
ExtFml("TradeSim.RecordTrades",
"System",
LONG,
LongEntryTrigger,
LongEntryPrice,
LongInitialStop,
LongTrailStopTrig,
LongTrailStopPrice,
Start);
Cheers
Dan
[/b]
Jose
31st August 2005, 11:39 PM
Dan, the problem here is that your code is using exit triggers based on the Low of the day, and yet it's trying to exit at the Open of the same day.
Try delaying your exit signals by one bar:
LongInitialStop:=O-Ref(ATR(30),-1);
LongTrailStopTrig:=
Ref(ExtFml("TradeSim.TrailingStop",Trigger,Long,ATR(10),H,L),-1);
LongTrailStopPrice:=
ExtFml("TradeSim.TrailingStop",Band,Long,ATR(10),H,L);
LongTrailStopPrice:=
If(O<LongTrailStopPrice,O,LongTrailStopPrice);
LongInitialStop:=O-Ref(ATR(30),-1);
Try and keep your signals as visual as possible - keep all system code within MetaStock wherever possible.
jose '-)
MySystem
4th September 2005, 02:43 AM
Thanks Jose,
I've tried the code you have provided and still get 'exit errors' (EXITS on entry day and ENTRY being CLOSE of day). In fact I seem to get more exit errors, about 35% of the database as opposssed to about 10%?
I've tried as you have suggested -
"Try delaying your exit signals by one bar"
by using:
ExtFml( "TradeSim.SetExitTriggerDelay", 1);
exit errors still occur.
I'm wondering if I'm asking the right questions. Perhaps what I need to ask is:
"Does TradeSim allow back testing for a system based on the following:
1. - entry at CLOSE of day
2. - ATR based InitialStops
3. - TrailingStops (based on) Intraday ATR exits
If so, what else would I need to change/add in the code below for TradeSim to record a database without EXITS occurring on the day of ENTRY (when entry is at CLOSE of day)?"
Cheers,
Dan
--------------------------------------------
LongEntryTrigger:= Cross(MACD(),Mov(MACD(),9,E)) ;
{EntryTrigger seems irrelevant, most EntryTriggers record the same "problems"}
{ 1. - entry at CLOSE of day }
LongEntryPrice:= CLOSE;
{ 2. - ATR based InitialStops }
LongInitialStop:= {Ideally} HIGH - (ATR(30)*1);
{ 3. - TrailingStops (based on) Intraday ATR exits }
LongTrailStopTrig:=
ExtFml("TradeSim.TrailingStop",Trigger,Long,
1 *ATR(10),H,L);
LongTrailStopPrice:= Ref(ExtFml("TradeSim.TrailingStop",Band,Long,
1 * ATR(10),H,L),-1);
LongTrailStopPrice:=
If(O<LongTrailStopPrice,O,LongTrailStopPrice);
StartDay := 1;
StartMonth := 5;
StartYear := 2005;
EndDay := 31;
EndMonth := 8;
EndYear := 2005;
ExtFml("TradeSim.Initialize");
ExtFml("TradeSim.SetStartRecordDate",StartDay,StartMonth,StartYear);
ExtFml("TradeSim.SetStopRecordDate",EndDay,EndMonth,EndYear);
ExtFml("TradeSim.EnableProtectiveStop",0);
ExtFml( "TradeSim.SetExitTriggerDelay", 1); {alteration made}
ExtFml("TradeSim.SetStopGapPriceToOpen");
ExtFml("TradeSim.RecordTrades",
"System",
LONG,
LongEntryTrigger,
LongEntryPrice,
LongInitialStop,
LongTrailStopTrig,
LongTrailStopPrice,
Start);
Jose
5th September 2005, 04:05 AM
Dan, TradeSim can backtest any signals generated by MetaStock code.
I suspect the problem is here:
LongInitialStop:=O-Ref(ATR(30),-1);
The trick is to keep all signal code within MetaStock itself, and plot all signals as indicators for visual debugging. Avoid stops outside MetaStock, as these signals then become invisible and cannot be easily debugged.
Try using Richard Dale's free (Initial/Trailing) Advanced Trailing Stop dll
http://www.tradernexus.com/advancedstop/advancedstop.html ,
and use it to construct your visual initial ATR stop indicator, which can then be referenced by the TradeSim/MetaStock exploration.
jose '-)
MySystem
14th September 2005, 02:33 AM
Hi Jose.
Finally sorted out!
A simple solution to the problem of TradeSim recording - EXITS
('protective or normal') on the same day of ENTRY, when using:-
LongEntryPrice:= CLOSE;
is to use the following external formula:
ExtFml("TradeSim.EnableProtectiveStop",1);
ExtFml( "TradeSim.SetExitTriggerDelay", 1);
There are perhaps other ways to achieve the same result. Would you go past this method and use some other?
Thanks for your help Jose.
Cheers,
Dan
Final Exit code:
LongEntryTrigger:= ;
LongEntryPrice:= CLOSE;
LongInitialStop:= (H - ((H-L)/2))- ATR(10);
LongTrailStopTrig:=ExtFml("TradeSim.TrailingStop",Trigger,Long,
ATR(30),(H - ((H-L)/2)),L);
LongTrailStopPrice:= Ref(ExtFml("TradeSim.TrailingStop",Band,Long,
ATR(30),(H - ((H-L)/2)),L),-1);
LongTrailStopPrice:= If(O<LongTrailStopPrice,O,LongTrailStopPrice);
StartDay := 1;
StartMonth := 8;
StartYear := 2004;
EndDay := 31;
EndMonth := 7;
EndYear := 2005;
ExtFml("TradeSim.Initialize");
ExtFml("TradeSim.SetStartRecordDate",StartDay,StartMonth,StartYear);
ExtFml("TradeSim.SetStopRecordDate",EndDay,EndMonth,EndYear);
{Following line required for CLOSE entry}
ExtFml("TradeSim.EnableProtectiveStop",1);
{Following line required for CLOSE entry}
ExtFml( "TradeSim.SetExitTriggerDelay", 1);
ExtFml("TradeSim.SetStopGapPriceToOpen");
ExtFml("TradeSim.RecordTrades",
"System",
LONG,
LongEntryTrigger,
LongEntryPrice,
LongInitialStop,
LongTrailStopTrig,
LongTrailStopPrice,
Start);
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.