nasdorq Posted August 24, 2020 Report Share Posted August 24, 2020 (edited) I'm trying to plot a paintbar for the current session only, and starting 10 minutes after the session open. I have a snippet of code for each, and I've combined them together. However it looks like there's probably some redundancy there, and I'm not sure how to simplify it. I figured since I run it on a lot of charts, it might be worth fixing. Do you have any suggestions? Edited August 24, 2020 by nasdorq Quote Link to comment Share on other sites More sharing options...
nasdorq Posted August 24, 2020 Author Report Share Posted August 24, 2020 The code wasn't appearing in the post so I had to attach a screenshot Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 24, 2020 Report Share Posted August 24, 2020 1. You're doing AddMinutes(1) and not AddMinutes(10). 2. GetTradingSessionInfo(Timestamp) gets the trading session for THAT candle. Since the paintbar is run on all candles, the candles from yesterday will get yesterday's sessions etc. If you want to get TODAY's session, you have to do GetTradingSessionInfo(DateTime.UtcNow). That way you don't have to check for plotting only current day. Quote Link to comment Share on other sites More sharing options...
nasdorq Posted August 24, 2020 Author Report Share Posted August 24, 2020 Thank you Mike. Quick follow up if you have a moment? I replaced both GetTradingSessionInfo(Timestamp); with GetTradingSessionInfo(DateTime.UtcNow) in bold below. It seems to work, only plotting current day, and starting 10min after the session open. Though do I need to have that line twice? Perhaps I do since I'm trying to do two different things? public void MainCalculation() { TradingSessionInfo session = GetTradingSessionInfo(DateTime.UtcNow); var TS = GetTradingSessionInfo(DateTime.UtcNow); if (Timestamp[0]>=TS.SessionStart.AddMinutes(10) && Timestamp[0]<=TS.SessionStart.AddHours(6.5)) //plot 10 min after session open until close if (DateTime.UtcNow<session.DayStart.AddDays(1)) // only plot current day { Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 24, 2020 Report Share Posted August 24, 2020 Don't need the second line. It actually adds a bug that will not plot the paintbar for Friday if you run it on Saturday. Quote Link to comment Share on other sites More sharing options...
nasdorq Posted August 24, 2020 Author Report Share Posted August 24, 2020 I removed the line: var TS = GetTradingSessionInfo(DateTime.UtcNow); However, then I get an error for the 3rd line: The name 'TS' does not exist in the current context. Quote Link to comment Share on other sites More sharing options...
Mike Medved Posted August 24, 2020 Report Share Posted August 24, 2020 Sorry I confused you. By second line I meant the second if.if (DateTime.UtcNow<session.DayStart.AddDays(1)) // only plot current day 1 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.