Doug Hayman Posted August 10, 2020 Report Share Posted August 10, 2020 (edited) I'm looking for the purposes of back-testing, to close an open position if the current timestamp >= the End of Session. However, I'm using Range Bars, where its timestamp completes at close of bar, and no bars are started, if not completed, prior to end of session. Hence, the logic Timestamp >= session.SessionEnd doesn't achieve the desired results. Can you offer any solutions here? Thanks in advance. Edited August 10, 2020 by Doug Hayman Quote Link to comment Share on other sites More sharing options...
Doug Hayman Posted August 10, 2020 Author Report Share Posted August 10, 2020 (edited) OK, I figured out a solution (sort of): I used the following logic: Timestamp >= session.SessionEnd.Addminutes(-C), where -C is an arbitrary negative constant prior to end of session. Edited August 10, 2020 by Doug Hayman Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 10, 2020 Report Share Posted August 10, 2020 Well yes - with range candle, the timestamp of the last session candle is arbitrarily far away from the session end time. That's the nature of the range candles. For the very last candle you can take the current UTC time - DateTime.UtcNow - and compare it to the SessionEnd. But that won't help you with past candles. What you can do with those is check if the start of the range candle is past the end of the session, then do the calculation on the previous candle, as that would be the last session candle. Quote Link to comment Share on other sites More sharing options...
Doug Hayman Posted August 11, 2020 Author Report Share Posted August 11, 2020 OK Mike, thanks. Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 11, 2020 Report Share Posted August 11, 2020 I just thought of something - what I said about checking if start of range candle is past the end of session won't work because what if the next candle is in the next session? You should check if the session.DayNumber changed. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.