Jump to content

Welcome to the new Traders Laboratory! Please bear with us as we finish the migration over the next few days. If you find any issues, want to leave feedback, get in touch with us, or offer suggestions please post to the Support forum here.

  • Welcome Guests

    Welcome. You are currently viewing the forum as a guest which does not give you access to all the great features at Traders Laboratory such as interacting with members, access to all forums, downloading attachments, and eligibility to win free giveaways. Registration is fast, simple and absolutely free. Create a FREE Traders Laboratory account here.

einja

Close All Orders at end of session

Recommended Posts

I was using the following code

 

[intrabarOrderGeneration = false]

SetExitOnClose ;

 

to close all orders whether long or short when session/day is ending.

 

It was not being executed and had to call the tech support of TS and they mentioned that the orders have to be specifically closed by custom code something like

 

if Time >= 1355 then

Close all orders

 

How do we write "Close all orders" in Easy Language. There could Long or Short Orders. I want all to be closed.

Edited by einja
more meaningful title

Share this post


Link to post
Share on other sites
I was using the following code

 

[intrabarOrderGeneration = false]

SetExitOnClose ;

 

to close all orders whether long or short when session/day is ending.

 

It was not being executed and had to call the tech support of TS and they mentioned that the orders have to be specifically closed by custom code something like

 

if Time >= 1355 then

Close all orders

 

How do we write "Close all orders" in Easy Language. There could Long or Short Orders. I want all to be closed.

 

While it will take 2 statements, this should do it.

 

If MarketPosition > 0 and Time >= 1355 Then sell CurrentShares this bar on close;

If MarketPosition < 0 and Time >= 1355 Then Buy to Cover CurrentShares this bar on close;

 

MarketPosition will return a +1, -1 or 0 depending on whether you are long, short or flat.

 

CurrentShares will return the number of shares/contracts in your position.

 

 

 

Cheers

 

UB

Share this post


Link to post
Share on other sites

SetExitOnClose will work fine in sim; in real trading you will need a separate exit instruction as UrmaBlume suggests.

 

I would use:

 

if t=1355 then begin
sell this bar;
buytocover this bar;
end;

 

The explanation from the EL dictionary is copied below.

 

Kind regards,

 

BlueHorseshoe

 

SetExitOnClose is a built-in stop reserved word used to place an order to exit all shares or contracts in all positions on the close of the last bar of the trading session on an intra-day chart.

 

For historical simulations, SetExitOnClose generates a market order on the bar close event of the last intra-day bar for each day in the chart. When used in an automated strategy placing real-world orders, SetExitOnClose generates a limit order into the post market trading session, (if one exists), otherwise a market order is generated for the open of the next regular session day.

 

SetExitOnClose by default uses the closing session time specified by the custom session settings of the chart.

 

SetExitOnClose can only be used in a Strategy.

 

When automating a strategy, you will not want to use SetExitOnClose as a way to make sure that all of your positions are closed prior to the regular session end time. To do this, you will need to generate a closing order prior to the last bar in the chart.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.