Jump to content
Medved Trader Forums

How to reference a candle with timestamp


BlueCollarDayTrading

Recommended Posts

It can be done pretty easily - but not directly. The thing is, the paintbar/scan always runs through ALL the candles it has before it starts chugging on incoming data with the last candle only. So look at this. Note that I am doing the PrevTimestamp thing just to make sure it records the first candle at after 10 minutes after session start - in case there is no candle exactly at 10 min after session start. Modify it to change the time you're checking.

Double At10MinAfterSessionStart=0;  // Close of first candle 10 minutes after session start or after
DateTime PrevTimeStamp;

public void MainCalculation()
{
    var Cutoff = TradingDay.SessionStart.AddMinutes(10);
    if (Timestamp >= Cutoff && PrevTimeStamp<Cutoff)
    {
        At10MinAfterSessionStart = Close;
    }
    PrevTimeStamp = Timestamp;
}

Link to comment
Share on other sites

"How can I check if a candle close is greater than a candle open at 9am EST"  - the "candle close" in that statement - is that at 9am or is it current?

If current - then this code: (make sure you run it with extended hours turned on)

Double At30MinBeforeSessionStart=0;  // Open of first candle that shows up at 30 minutes or less before session start
DateTime PrevTimeStamp;

public void MainCalculation()
{
    var Cutoff = TradingDay.SessionStart.AddMinutes(-30);
    if (Timestamp >= Cutoff && PrevTimeStamp<Cutoff)
    {
        At30MinBeforeSessionStart= Open;
    }
    PrevTimeStamp = Timestamp;

  

   // this checks if current Close is greater than the Open at 9am

   if (Timestamp >= TradingDay.SessionStart && Close > At30MinBeforeSessionStart)  // checks if in regular session AND close > open-at-9am
   {

      ... do something here...

   }


}

Link to comment
Share on other sites

What I am trying to do is check the Open and Close of the 9am candle only and then do something.

for example after 45 mins into the market open (1015am EST) I still want to check if the 9am candle close was above or below the 9am candle open. Then I will run some calculations depending on if the 9am candle is a green or red bar.

I want to run a scan/paintbar that checks the 9am candle for red or green close and then does some calculations on the current bar. I have the calculations for the current bar I just can't figure out how to do a specific bar in the past data. Been trying to use time.

Link to comment
Share on other sites

Ah ok. I misunderstood.

Boolean Green9AMCandle;
DateTime PrevTimeStamp;

public void MainCalculation()
{
    var Cutoff = TradingDay.SessionStart.AddMinutes(-30);
    if (Timestamp >= Cutoff && PrevTimeStamp<=Cutoff)
    {
        Green9AMCandle = Open>Close;
    }
    PrevTimeStamp = Timestamp;

  

   if (Green9AMCandle)

   {

      ... do something here...

   }


}


 

Link to comment
Share on other sites

Been working this since yesterday. I am not able to get it to work for the simplest thing. 

I am trying to simply get it to work for Green if true and Red if false. Then I tried to get it to simply do Green if true and nothing if false.

All I get is a green. I set a paintbar to do a green band at top if true and nothing if false. It give me a green band at top on all charts no matter.

Can you show me how I can get a Green if True, A Red if False, and White if Close==Open

Programing is not my thing but I am trying to figure this out




			
		
Link to comment
Share on other sites

On 6/10/2021 at 1:30 PM, Mike Medved said:

Ah ok. I misunderstood.

Boolean Green9AMCandle;
DateTime PrevTimeStamp;

public void MainCalculation()
{
    var Cutoff = TradingDay.SessionStart.AddMinutes(-30);
    if (Timestamp >= Cutoff && PrevTimeStamp<=Cutoff)
    {
        Green9AMCandle = Open>Close;
    }
    PrevTimeStamp = Timestamp;

  

   if (Green9AMCandle)

   {

      ... do something here...

   }


}


 

Been working this since yesterday. I am not able to get it to work for the simplest thing. 

I am trying to simply get it to work for Green if true and Red if false. Then I tried to get it to simply do Green if true and nothing if false.

All I get is a green. I set a paintbar to do a green band at top if true and nothing if false. It give me a green band at top on all charts no matter.

Can you show me how I can get a Green if True, A Red if False, and White if Close==Open

Programing is not my thing but I am trying to figure this out

Link to comment
Share on other sites

On 6/11/2021 at 9:33 PM, BlueCollarDayTrading said:

Been working this since yesterday. I am not able to get it to work for the simplest thing. 

I am trying to simply get it to work for Green if true and Red if false. Then I tried to get it to simply do Green if true and nothing if false.

All I get is a green. I set a paintbar to do a green band at top if true and nothing if false. It give me a green band at top on all charts no matter.

Can you show me how I can get a Green if True, A Red if False, and White if Close==Open

Programing is not my thing but I am trying to figure this out

Well, was the 9am candle Green? Because if it was, then it would show green band.

Export your paintbar and send it to us support@medvedtrader.com

Link to comment
Share on other sites

  • 1 month later...

Been trying to use this but it does not work in real time. It only works correctly in backfills, so good for back testing. I have been trying to figure out what makes it work consistently and what makes it fail. I believe it has to do with the first tick of the candle being an uptick to be green and a down tick to be red. It may have something to do with using a Boolean.

 

On 6/13/2021 at 7:54 PM, Mike Medved said:

Well, was the 9am candle Green? Because if it was, then it would show green band.

Export your paintbar and send it to us support@medvedtrader.com

Been trying to use this but it does not work in real time. It only works correctly in backfills, so good for back testing. I have been trying to figure out what makes it work consistently and what makes it fail. I believe it has to do with the first tick of the candle being an uptick to be green and a down tick to be red. It may have something to do with using a Boolean.

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