Forcing end of day exits

Questions about MultiCharts and user contributed studies.
rossw
Posts: 8
Joined: 03 Feb 2014
Has thanked: 3 times
Been thanked: 4 times

Forcing end of day exits

Postby rossw » 21 Apr 2014

Hi,

I'm having a few troubles sometimes with positions that do not get closed at the end of the day. I try and get out at 1500, since trading goes until 1505 I want to leave a small amount of slack just in case.

My current code is fairly simple as follows:

Code: Select all

//time based exits
If Time >= Bfr then SELL ("XLTime")ALL contracts this bar at close;
If Time >= Bfr then BUYTOCOVER ("XSTime") ALL Contracts this bar at close;
where Bfr is an input set to 1500.

The issue I have is that I am using range (point) bars and with recent quiet conditions, sometimes there is no new bar generated in the last 5mins so the strategy does not exit until the following morning.

Solutions I've tried so far without success:
I don't currently use intrabar order generation for the strategy, but tried switching it on for the end of the day only to force the position to trade out and then turning it off again

Code: Select all

inputs: aftr2(1501), bfr2(1502);
If Time > Aftr2 and Time < Bfr2 then begin
[IntrabarOrderGeneration = true];
If Time >= aftr2 then SELL ("XLTime")ALL contracts this bar at close;
If Time >= aftr2 then BUYTOCOVER ("XSTime") ALL Contracts this bar at close;
[IntrabarOrderGeneration = false];
end;
I also tried using setexitonclose and changing the market hours in the exchange settings in quote manager to end at 1455 but that did not seem to work

any suggestions?
I was considering writing a second signal running on the same chart just for end of day exits which would then use intra bar order generation, and MarketPosition_at_Broker to get out of any positions, but I would rather it all in one.

I have looked at other codes such as the one in this thread viewtopic.php?f=5&t=7834 but it has the same issue that it needs to exit next bar after the time condition is met.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Forcing end of day exits

Postby TJ » 21 Apr 2014

Hi,
::
The issue I have is that I am using range (point) bars and with recent quiet conditions, sometimes there is no new bar generated in the last 5mins so the strategy does not exit until the following morning.
::

Look up:

RecalcLastBarAfter

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Forcing end of day exits

Postby Andrew MultiCharts » 21 Apr 2014

Hello rossw,

You can find a good example here.

rossw
Posts: 8
Joined: 03 Feb 2014
Has thanked: 3 times
Been thanked: 4 times

Re: Forcing end of day exits

Postby rossw » 21 Apr 2014

Thanks for that both of you. I'll have a look into it

rossw
Posts: 8
Joined: 03 Feb 2014
Has thanked: 3 times
Been thanked: 4 times

Re: Forcing end of day exits

Postby rossw » 21 Apr 2014

Is it possible to turn IOG on and off within the same strategy? I don't think so but just checking..
Andrew, the code you link to makes sense to me, it forces the strategy to re-calculate and then closes all positions, but it requires IOG on.
The majority of my strategy does not use IOG, so I would only need it for the end of day exits. It would be nice to keep it all within the one signal, but if I have to split it out and run 2 signals on the one chart then so be it.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Forcing end of day exits

Postby TJ » 21 Apr 2014

Is it possible to turn IOG on and off within the same strategy? I don't think so but just checking..
::
The answer is no.

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Forcing end of day exits

Postby TJ » 21 Apr 2014

you can turn on IOG...

then use barstatus=2 to control your regular trading logic.

rossw
Posts: 8
Joined: 03 Feb 2014
Has thanked: 3 times
Been thanked: 4 times

Re: Forcing end of day exits

Postby rossw » 21 Apr 2014

ok that seems like a decent solution, thanks for your quick responses.
Something like the below?

Code: Select all

[intrabarordergeneration = true]
if (BarStatus(1)=2) then
begin
....do normal strategy
end;

if (currenttime_s >= TimeClosePosition) then
Begin
RecalcLastBarAfter(1);
sell ("EOD_LX") next bar market;
buytocover("EOD_SX") next bar market;
End;

I have not used IOG before so sorry for the rookie questions.
Does IOG increase load on the CPU? If I use the barstatus lines in my code, will that lessen the load?

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: Forcing end of day exits

Postby Andrew MultiCharts » 22 Apr 2014

o
Does IOG increase load on the CPU? If I use the barstatus lines in my code, will that lessen the load?
Yes, IOG utilizes more CPU resources. However if you use barstatus checking at very beginning of your code, the load would be less, since the whole script under barstatus-abased condition will not be calculated.

rossw
Posts: 8
Joined: 03 Feb 2014
Has thanked: 3 times
Been thanked: 4 times

Re: Forcing end of day exits

Postby rossw » 15 May 2014

Just coming back on this..

I was still not happy with what I could come up with so for a modest fee I got Chris from http://www.abctradinggroup.com/ to come up with a solution for me.

He wrote a signal for me specifically for end of day and I now have 2 signals running on the chart, one for my strategy and a second one for end of day exits.

The solution for range bars was to use IOG and local computer time (+ an offset to exchange time if needed) to find out exactly when the end of the day was and exit there. Simple once I read through his code, but was a bit outside my skill set to write up.

I've been running it for a week or 2 now and have happily seen my position flattened exactly when I wanted it be. :)


Return to “MultiCharts”