{"id":53,"date":"2006-10-26T05:19:08","date_gmt":"2006-10-26T10:19:08","guid":{"rendered":"http:\/\/www.amibroker.com\/kb\/2006\/10\/26\/how-to-close-open-positions-at-the-end-of-the-day-for-daytraders\/"},"modified":"2014-12-04T08:23:10","modified_gmt":"2014-12-04T13:23:10","slug":"how-to-close-open-positions-at-the-end-of-the-day-for-daytraders","status":"publish","type":"post","link":"https:\/\/www.amibroker.com\/wordpress\/kb\/2006\/10\/26\/how-to-close-open-positions-at-the-end-of-the-day-for-daytraders\/","title":{"rendered":"How to close open positions at the end of the day (for daytraders)"},"content":{"rendered":"
If we are backtesting the intraday<\/strong> strategy and we do not want to keep open positions overnight – then it’s necessary to force closing all the open positions before the session end. In order to code it in AFL – the easiest is to use TimeNum() function for that purpose. <\/p> The below example shows how to close all open positions after 15:50, just before the end of the trading session (when testing on intraday quotes).<\/p> If we are backtesting the intraday strategy and we do not want to keep open positions overnight – then it’s necessary to force closing all the open positions before the session end. In order to code it in AFL – the easiest is to use TimeNum() function for that purpose.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[7],"tags":[53,14,15],"_links":{"self":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/53"}],"collection":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/comments?post=53"}],"version-history":[{"count":1,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/53\/revisions"}],"predecessor-version":[{"id":803,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/posts\/53\/revisions\/803"}],"wp:attachment":[{"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/media?parent=53"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/categories?post=53"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.amibroker.com\/wordpress\/kb\/wp-json\/wp\/v2\/tags?post=53"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}Buy <\/span>= ...<\/span>your regular conditions<\/span>....
<\/span>Sell <\/span>= ....<\/span>your regular conditions<\/span>.... OR <\/span>TimeNum<\/span>() > <\/span>155000<\/span><\/code>For example – in case of MACD crossover – the code will look like:<\/p>Buy <\/span>= <\/span>Cross<\/span>( <\/span>MACD<\/span>(), <\/span>Signal<\/span>() );
<\/span>Sell <\/span>= <\/span>Cross<\/span>( <\/span>Signal<\/span>(), <\/span>MACD<\/span>() ) OR <\/span>TimeNum<\/span>() > <\/span>155000<\/span><\/code>","protected":false},"excerpt":{"rendered":"