In C# how do I compare the current bar's time with a hardcoded 14:30:00? - futures io
futures io futures trading



In C# how do I compare the current bar's time with a hardcoded 14:30:00?


Discussion in MultiCharts

Updated
    1. trending_up 2,745 views
    2. thumb_up 3 thanks given
    3. group 4 followers
    1. forum 12 posts
    2. attach_file 0 attachments




Welcome to futures io: the largest futures trading community on the planet, with well over 125,000 members
  • Genuine reviews from real traders, not fake reviews from stealth vendors
  • Quality education from leading professional traders
  • We are a friendly, helpful, and positive community
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts
  • We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

(If you already have an account, login at the top of the page)

 
Search this Thread
 

In C# how do I compare the current bar's time with a hardcoded 14:30:00?

(login for full post details)
  #1 (permalink)
Denver Colorado
 
Experience: Intermediate
Platform: Multicharts
Trading: Forex
 
Posts: 23 since Apr 2013
Thanks: 3 given, 2 received

In C# how do I compare the current bar's time with a hardcoded 14:30:00?

Started this thread Reply With Quote

Can you help answer these questions
from other members on futures io?
Volume Profile Indicator for Ninja Script in NT8
NinjaTrader
Improve current ZigZag indicator in NT8
NinjaTrader
Automatic pattern research with NT
Elite Algorithmic NinjaTrader Trading
What blockvolume is visible? - order processing
NinjaTrader
Help Needed: TOS Options Chain IV & IMPL MOVE Calcul …
ThinkOrSwim
 
Best Threads (Most Thanked)
in the last 7 days on futures io
Battlestations: Show us your trading desks!
118 thanks
Big Mike in Ecuador
66 thanks
If you needed one-on-one help with any trading issue, ho …
31 thanks
Want your NinjaTrader indicator created, free?
27 thanks
Building a Crypto Mining Rig
21 thanks
 
(login for full post details)
  #2 (permalink)
Gits (Hooglede) Belgium
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,991 since Sep 2013
Thanks: 2,437 given, 5,801 received

as an example :

if ((String.Compare(Time[0].ToString("yyyyddMM"),"20140309") < 0) ||
(String.Compare(Time[0].ToString("yyyyddMM"), "20140330") >0))
{
// do what you want to do...
}



Is this what you need ?

regards,
Ron

Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #3 (permalink)
Gits (Hooglede) Belgium
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,991 since Sep 2013
Thanks: 2,437 given, 5,801 received



JHall65 View Post
In C# how do I compare the current bar's time with a hardcoded 14:30:00?

as an example :

if ((String.Compare(Time[0].ToString("HHmmss"),"143000") < 0) ||
(String.Compare(Time[0].ToString("HHmmss"), "144500") >0))
{
// do what you want to do...
// do nothing between 14:30:00 and 14:45:00
}



Is this what you need ?

regards,
Ron

Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #4 (permalink)
OC, California, USA
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
 
shodson's Avatar
 
Posts: 1,958 since Jun 2009
Thanks: 528 given, 3,648 received

Or, more simply, using the ToTime() method...

 
Code
if (ToTime(Time[0]) == 143000)
   // do something

Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
The following user says Thank You to shodson for this post:
 
(login for full post details)
  #5 (permalink)
Denver Colorado
 
Experience: Intermediate
Platform: Multicharts
Trading: Forex
 
Posts: 23 since Apr 2013
Thanks: 3 given, 2 received


rleplae View Post
as an example :

if ((String.Compare(Time[0].ToString("yyyyddMM"),"20140309") < 0) ||
(String.Compare(Time[0].ToString("yyyyddMM"), "20140330") >0))
{
// do what you want to do...
}



Is this what you need ?

regards,
Ron


Ron, thanks for your help! I am trying to record a settlement price. So it would be nice to know the format to use for 14:30.

Thanks again,

Jason

Started this thread Reply With Quote
 
(login for full post details)
  #6 (permalink)
Gits (Hooglede) Belgium
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,991 since Sep 2013
Thanks: 2,437 given, 5,801 received


JHall65 View Post
Ron, thanks for your help! I am trying to record a settlement price. So it would be nice to know the format to use for 14:30.

Thanks again,

Jason

@shodson gave a shorter, more simple solution

but i'm also creating class libraries/trading strategies that run outside of NT
and then a more standard c# approach is better
but if you stay withing NT and don't run the code outside NT,
then the solution of @shodson is cleaner... and preferable

Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #7 (permalink)
OC, California, USA
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
 
shodson's Avatar
 
Posts: 1,958 since Jun 2009
Thanks: 528 given, 3,648 received


rleplae View Post
but i'm also creating class libraries/trading strategies that run outside of NT and then a more standard c# approach is better

Without using anything Ninjatrader-specific...

 
Code
if (Time[0]. Hour == 14 && Time[0]. Minute == 30)
    // do stuff

However, Time[0] is a Ninjatrader-specific DataSeries so you'll have to de-Ninja that if you want to be pure...

Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
The following 2 users say Thank You to shodson for this post:
 
(login for full post details)
  #8 (permalink)
Denver Colorado
 
Experience: Intermediate
Platform: Multicharts
Trading: Forex
 
Posts: 23 since Apr 2013
Thanks: 3 given, 2 received

Thanks for the responses! The Multicharts.Net version I came up with is this:
 
Code
if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute == 30 && Bars.TimeValue.Second == 00 ) {
m_settlementPrice.Value = Bars.Close.Value;
}
However, now I have another question: How do I get that code to run only once if I am using tick data? The other problem is that by using seconds, I sometimes get no result for that day, because no ticks happened right at the 0th second. Any suggestions?

Started this thread Reply With Quote
 
(login for full post details)
  #9 (permalink)
Gits (Hooglede) Belgium
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,991 since Sep 2013
Thanks: 2,437 given, 5,801 received


JHall65 View Post
Thanks for the responses! The Multicharts.Net version I came up with is this:
 
Code
if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute == 30 && Bars.TimeValue.Second == 00 ) {
m_settlementPrice.Value = Bars.Close.Value;
}
However, now I have another question: How do I get that code to run only once if I am using tick data? The other problem is that by using seconds, I sometimes get no result for that day, because no ticks happened right at the 0th second. Any suggestions?

i was just going to say.... with that if, it will only trigger if exactly on that time there is a bar,
if there is 5 second silence, then your code would not be triggered

therefore you would more likely do something like this :

if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute >= 30 && myBarFlag==0 )
{
m_settlementPrice.Value = Bars.Close.Value;
myBarFlag = 1;
}

if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute < 30 && Bars.TimeValue.Minute >= 20 )
{
myBarFlag = 0;
}


this would trigger the update with the first tick after 14:30:XX
and reset the flag a few minutes before that time


how does that sound ?

Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #10 (permalink)
Denver Colorado
 
Experience: Intermediate
Platform: Multicharts
Trading: Forex
 
Posts: 23 since Apr 2013
Thanks: 3 given, 2 received


Perfect! That's exactly what I was looking for. Thanks for your help!

Started this thread Reply With Quote
 
(login for full post details)
  #11 (permalink)
Denver Colorado
 
Experience: Intermediate
Platform: Multicharts
Trading: Forex
 
Posts: 23 since Apr 2013
Thanks: 3 given, 2 received

Now I'm getting some odd results. Maybe you can easily see what's going on here:

 
Code
	
// This Block of code records the first closing price after 14:30. 
if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute >= 30 && m_MyBarFlag == 0) 
{
Output.WriteLine("Hour: {0} Minute: {1} Data1 Close: {2}  Data2 Close: {3} Settlement Price: {4} Bar Flag {5}",
Bars.TimeValue.Hour, Bars.TimeValue.Minute, Bars.CloseValue, BarsOfData(2).CloseValue, Bars.Close.Value, m_MyBarFlag);

m_settlementPrice.Value = (Bars.CloseValue - BarsOfData(2).CloseValue);

m_MyBarFlag = 1;	// This marks that a value was recorded already.
			}

if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute < 20) m_MyBarFlag = 0;	// This resets the flag for the next day.
The Output of that code on 30 days worth of tick data:
Hour: 14 Minute: 30 Data1 Close: 93.96 Data2 Close: 93.39 Settlement Price: 93.96 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.61 Data2 Close: 93.15 Settlement Price: 93.61 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.35 Data2 Close: 92.88 Settlement Price: 93.35 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.84 Data2 Close: 93.35 Settlement Price: 93.84 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.88 Data2 Close: 93.35 Settlement Price: 93.88 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 94.51 Data2 Close: 93.79 Settlement Price: 94.51 Bar Flag: 0


Why would there not be 30 lines written to output, and why is the settlement price not being calculated?

Started this thread Reply With Quote
 
(login for full post details)
  #12 (permalink)
Gits (Hooglede) Belgium
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,991 since Sep 2013
Thanks: 2,437 given, 5,801 received


JHall65 View Post
Now I'm getting some odd results. Maybe you can easily see what's going on here:

 
Code
	
// This Block of code records the first closing price after 14:30. 
if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute >= 30 && m_MyBarFlag == 0) 
{
Output.WriteLine("Hour: {0} Minute: {1} Data1 Close: {2}  Data2 Close: {3} Settlement Price: {4} Bar Flag {5}",
Bars.TimeValue.Hour, Bars.TimeValue.Minute, Bars.CloseValue, BarsOfData(2).CloseValue, Bars.Close.Value, m_MyBarFlag);

m_settlementPrice.Value = (Bars.CloseValue - BarsOfData(2).CloseValue);

m_MyBarFlag = 1;	// This marks that a value was recorded already.
			}

if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute < 20) m_MyBarFlag = 0;	// This resets the flag for the next day.
The Output of that code on 30 days worth of tick data:
Hour: 14 Minute: 30 Data1 Close: 93.96 Data2 Close: 93.39 Settlement Price: 93.96 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.61 Data2 Close: 93.15 Settlement Price: 93.61 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.35 Data2 Close: 92.88 Settlement Price: 93.35 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.84 Data2 Close: 93.35 Settlement Price: 93.84 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.88 Data2 Close: 93.35 Settlement Price: 93.88 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 94.51 Data2 Close: 93.79 Settlement Price: 94.51 Bar Flag: 0


Why would there not be 30 lines written to output, and why is the settlement price not being calculated?


i think it has to do, where that code is
i don't see any errors right away

Follow me on Twitter Visit my futures io Trade Journal Reply With Quote
 
(login for full post details)
  #13 (permalink)
Gits (Hooglede) Belgium
 
Experience: Master
Platform: NinjaTrader, Proprietary,
Broker: Ninjabrokerage/IQfeed + Synthetic datafeed
Trading: 6A, 6B, 6C, 6E, 6J, 6S, ES, NQ, YM, AEX, CL, NG, ZB, ZN, ZC, ZS, GC
 
rleplae's Avatar
 
Posts: 2,991 since Sep 2013
Thanks: 2,437 given, 5,801 received


JHall65 View Post
Now I'm getting some odd results. Maybe you can easily see what's going on here:

 
Code
	
// This Block of code records the first closing price after 14:30. 
if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute >= 30 && m_MyBarFlag == 0) 
{
Output.WriteLine("Hour: {0} Minute: {1} Data1 Close: {2}  Data2 Close: {3} Settlement Price: {4} Bar Flag {5}",
Bars.TimeValue.Hour, Bars.TimeValue.Minute, Bars.CloseValue, BarsOfData(2).CloseValue, Bars.Close.Value, m_MyBarFlag);

m_settlementPrice.Value = (Bars.CloseValue - BarsOfData(2).CloseValue);

m_MyBarFlag = 1;	// This marks that a value was recorded already.
			}

if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute < 20) m_MyBarFlag = 0;	// This resets the flag for the next day.
The Output of that code on 30 days worth of tick data:
Hour: 14 Minute: 30 Data1 Close: 93.96 Data2 Close: 93.39 Settlement Price: 93.96 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.61 Data2 Close: 93.15 Settlement Price: 93.61 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.35 Data2 Close: 92.88 Settlement Price: 93.35 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.84 Data2 Close: 93.35 Settlement Price: 93.84 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 93.88 Data2 Close: 93.35 Settlement Price: 93.88 Bar Flag: 0
Hour: 14 Minute: 30 Data1 Close: 94.51 Data2 Close: 93.79 Settlement Price: 94.51 Bar Flag: 0


Why would there not be 30 lines written to output, and why is the settlement price not being calculated?

The reason for this behavior is due to the fact that on certain days there is no bar between , 14:00 and 14:20 that resets the flag. I have modified the code to reset the flag once we are passed midnight, that way the first bar after 14:30 will be captured and trigger the logic.

// This Block of code records the first closing price after 14:30.
if (Bars.TimeValue.Hour == 14 && Bars.TimeValue.Minute >= 30 && m_MyBarFlag == 0)
{
Output.WriteLine("Hour: {0} Minute: {1} Data1 Close: {2} Data2 Close: {3} Settlement Price: {4} Bar Flag {5}",
Bars.TimeValue.Hour, Bars.TimeValue.Minute, Bars.CloseValue, BarsOfData(2).CloseValue, Bars.Close.Value, m_MyBarFlag);

m_settlementPrice.Value = (Bars.CloseValue - BarsOfData(2).CloseValue);

m_MyBarFlag = 1; // This marks that a value was recorded already.
}

if (Bars.TimeValue.Hour < 14 ) m_MyBarFlag = 0; // This resets the flag for the next day.

Follow me on Twitter Visit my futures io Trade Journal Reply With Quote


futures io Trading Community Platforms and Indicators MultiCharts > In C# how do I compare the current bar's time with a hardcoded 14:30:00?


Last Updated on August 28, 2014


Upcoming Webinars and Events
 

NinjaTrader Indicator Challenge!

Ongoing
 

Battlestations! Show us your trading desk - $1,500 in prizes!

March
 

Importance of Finding Your Own Way w/Adam Grimes

Elite only
 

Journal Challenge w/Jigsaw

April
     



Copyright © 2021 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts