Jump to content
Medved Trader Forums

Plot paintbar today only, and X minutes into session


Recommended Posts

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?


 

file.PNG

Edited by nasdorq
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

{

Link to comment
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.

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...