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: 632
Joined: 03 Mar 2007
Has thanked: 105 times
Been thanked: 81 times

Re: Autotrade Close all position at end of session

Postby SUPER » 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.
Have a look at following link:

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

viewtopic.php?f=5&t=7834

User avatar
Henry MultiСharts
Posts: 9093
Joined: 25 Aug 2011
Has thanked: 1258 times
Been thanked: 2923 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.

User avatar
TJ
Posts: 7192
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 990 times
Been thanked: 2049 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.

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”