NexusFi: Find Your Edge


Home Menu

 





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


Discussion in MultiCharts

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




 
Search this Thread

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

  #1 (permalink)
 JHall65 
Denver Colorado
 
Experience: Intermediate
Platform: Multicharts
Trading: Forex
Posts: 23 since Apr 2013
Thanks Given: 3
Thanks Received: 2

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 NexusFi?
Request for MACD with option to use different MAs for fa …
NinjaTrader
ZombieSqueeze
Platforms and Indicators
NexusFi Journal Challenge - April 2024
Feedback and Announcements
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Retail Trading As An Industry
58 thanks
Battlestations: Show us your trading desks!
55 thanks
NexusFi site changelog and issues/problem reporting
48 thanks
What percentage per day is possible? [Poll]
31 thanks
GFIs1 1 DAX trade per day journal
29 thanks

  #2 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
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
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,862

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 NexusFi Trade Journal Reply With Quote
  #3 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
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
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,862



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 NexusFi Trade Journal Reply With Quote
  #4 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709

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

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

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
The following user says Thank You to shodson for this post:
  #5 (permalink)
 JHall65 
Denver Colorado
 
Experience: Intermediate
Platform: Multicharts
Trading: Forex
Posts: 23 since Apr 2013
Thanks Given: 3
Thanks Received: 2


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
  #6 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
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
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,862


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 NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


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 NexusFi Trade Journal Reply With Quote
The following 2 users say Thank You to shodson for this post:
  #8 (permalink)
 JHall65 
Denver Colorado
 
Experience: Intermediate
Platform: Multicharts
Trading: Forex
Posts: 23 since Apr 2013
Thanks Given: 3
Thanks Received: 2

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
  #9 (permalink)
 
rleplae's Avatar
 rleplae 
Gits (Hooglede) Belgium
Legendary Market Wizard
 
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
Posts: 3,003 since Sep 2013
Thanks Given: 2,442
Thanks Received: 5,862


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 NexusFi Trade Journal Reply With Quote
  #10 (permalink)
 JHall65 
Denver Colorado
 
Experience: Intermediate
Platform: Multicharts
Trading: Forex
Posts: 23 since Apr 2013
Thanks Given: 3
Thanks Received: 2


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

Started this thread Reply With Quote





Last Updated on August 28, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts