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 4,075 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?

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

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

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
Better Renko Gaps
The Elite Circle
Strategy stop orders partially filled
EasyLanguage Programming
What broker to use for trading palladium futures
Commodities
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
22 thanks
Funded Trader platforms
17 thanks
Trading with Intuition
14 thanks
ApexTraderFunding.com experience and review
13 thanks
GFIs1 1 DAX trade per day journal
9 thanks
  #12 (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,863


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 NexusFi Trade Journal Reply With Quote
  #13 (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,863



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 NexusFi Trade Journal 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