Need Help with TS End of Day Exit Code

clbradley17

Junior member
Messages
25
Likes
0
Hey. I have a code which works fairly well in backtesting, but there are bugs in most end of day exit strategy codes at Tradestation, and have noticed recently that SetExitOnClose just works in backtesting. What do I need to do to make sure I'm out by the end of the day or just before? Here's what I have so far:

Inputs:
FastLength(10), SlowLength(20), StartTime(0930),EndTime(1600);

Vars:
FastAvg(0),SlowAvg(0);

FastAvg = xaverage(Close,FastLength);
SlowAvg = xaverage(Close,SlowLength);

If Time > StartTime and Time < EndTime then begin

If FastAvg crosses above SlowAvg then
buy 100 shares next bar at market;

If FastAvg crosses below SlowAvg then
sellshort 100 shares next bar at market;

end;


SetProfitTarget(1000);
SetStopLoss( 100);

SetExitOnClose;

Except that now I'll leave the last line out since it only works for backtesting, not in real time. Wondering if I need to put the times at the top (EST?), the time zone I'm in, or New York Time (NYT?), and if it should be changed to 1558 or 1559 end time EST or NYT to be sure and be out before 4 PM (1600 EST), and if it should be stated to sell if long or cover if short at 1558 or 1559 EST near the end of the code. Have seen that there are lots of bugs in the exit end of day codes at TS, and not sure what really works. Thanks for any help and hope you're having a great weekend.

Curtis
 
Inputs:
FastLength(10), SlowLength(20), StartTime(0930),EndTime(1557);

Vars:
FastAvg(0),SlowAvg(0);

FastAvg = xaverage(Close,FastLength);
SlowAvg = xaverage(Close,SlowLength);

If Time > StartTime and Time < EndTime then begin

If FastAvg crosses above SlowAvg then
buy 100 shares next bar at market;

If FastAvg crosses below SlowAvg then
sellshort 100 shares next bar at market;

end;


SetProfitTarget(1000);
SetStopLoss( 100);

// Assuming you are running on a 1 minute or similar time based chart
if time >= endTime then
begin
BuyToCover ("EOD SX" ) all contracts next bar market ;
Sell ( "EOD LX" ) all contracts next bar market ;
end ;

// Works only in backtesting, but go ahead and leave it in.
SetExitOnClose;
 
Yes, it will also do that. It is better to write your own code for end of day exits and you can get as fancy as you like. You can exit down to the second level if you really feel a need to. If you visit the TSW forums often you may know of me as I go by the name of _Nemo there.
 
End of Day Exit

How would you do this using tick charts? I'm running into a problems right now with the currency futures, not generating another bar 5-10 before close. Is there a macro or something that will help?

Yes, it will also do that. It is better to write your own code for end of day exits and you can get as fancy as you like. You can exit down to the second level if you really feel a need to. If you visit the TSW forums often you may know of me as I go by the name of _Nemo there.
 
Top