Time based exit


Category:
0
0

do yo have a script that exits a trade long or short at the end of the day?  I would like to add it to a strategy on think or swim

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on October 29, 2019 9:53 am
70 views
0
Private answer

I updated your question title to fully describe the context of your question. There is no way to write the code to exit "at end of the day". We can only write code that specifies a time of day to exit.

input exitTime = 1555;
def exitBar = SecondsTillTime(exitTime) == 0;
AddOrder(OrderType.SELL_TO_CLOSE, exitBar[-1], close[-1]);
AddOrder(OrderType.BUY_TO_CLOSE, exitBar[-1], close[-1]);

You will need to update the input parameter "exitTime" to match the time stamp on the last bar of your chart. The selected time frame will impact this and you will need to select the correct time accordingly.

Screenshot below shows this on a 5 min chart using the built-in strategy named: "MovAvgTwoLinesStrat".

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on October 29, 2019 10:53 am