Autotrade Close all position at end of session

Questions about MultiCharts and user contributed studies.
grt260
Posts: 6
Joined: 21 Sep 2011

Autotrade Close all position at end of session

Postby grt260 » 13 Oct 2011

Hi all,
if i am trading at a 3 min chart autotrade, and the session close time is 161500, how can i set the autotrade close all position automatically at 161430?
Thanks.

SUPER
Posts: 622
Joined: 03 Mar 2007
Has thanked: 99 times
Been thanked: 80 times

Re: Autotrade Close all position at end of session

Postby SUPER » 13 Oct 2011

grt260 wrote:Hi all,
if i am trading at a 3 min chart autotrade, and the session close time is 161500, how can i set the autotrade close all position automatically at 161430?
Thanks.


Have a look at following link:

viewtopic.php?f=1&t=8025&p=37134#p37134

viewtopic.php?f=5&t=7834
These users thanked the author SUPER for the post:
Henry MultiСharts

User avatar
Henry MultiСharts
Posts: 8394
Joined: 25 Aug 2011
Has thanked: 1201 times
Been thanked: 2682 times

Re: Autotrade Close all position at end of session

Postby Henry MultiСharts » 13 Oct 2011

You can use "setexitonclose" code word,it works properly but in real time action the conditions are not always met.
There are two conditions that should be met:
Session end and a simultaneous with session end tick.
The second condition is not always met unfortunately, this can happen if the market is slow and the position won’t close.
You can achieve your goal by using this script.
You need to apply it as a separate strategy.

Code: Select all

[intrabarordergeneration = true]
input: TimeClosePosition(0);
if (currenttime_s >= TimeClosePosition) then
Begin
    RecalcLastBarAfter(1);
    sell ("EOD_LX") next bar market;
    buytocover("EOD_SX") next bar market;
End;


As an input you need to specify the time when you need to close the position, for example 163725 – is 16:37:25.
These users thanked the author Henry MultiСharts for the post:
JoshM

User avatar
TJ
Posts: 6523
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 957 times
Been thanked: 1883 times

Re: Autotrade Close all position at end of session

Postby TJ » 13 Oct 2011

most brokers require the last order to be submitted 3 minutes before closing time.

setexitonclose can be used in backtesting,
but in real life, it will generate a market order for the opening of next session.
These users thanked the author TJ for the post (total 3):
JoshMHenry MultiСhartsSwap

grt260
Posts: 6
Joined: 21 Sep 2011

Re: Autotrade Close all position at end of session

Postby grt260 » 13 Oct 2011

Thanks All,
Luckily, the market i am trading is fast and many transcation, i think the script can help. Thanks.


Return to “MultiCharts”