Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Finding a timeStamp

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Finding a timeStamp

    Hi there,

    I have created a L2 Book that holds a historical record of Size at a Price and a timestamp of when the Update occurred

    When I get an Order update to indicate the order is working I want to .search my L2 book for the time stamp that is closest too but less then the time stamp of the order.orderState Working. I am having trouble finding a good method to do this so does anyone know of a good way to compare a DateTime var against a collection of DateTime and return the closest value that is less then the DateTime var?

    Thanks in advance.

    #2
    Hello GKonheiser,

    Thank you for your post.

    Loop through the collection and compare against the desired DateTime value. Each time a value is less than the DateTime value assign it to specific value. Then repeat the process, if the new value is greater than the previous and we know it is less than the DateTime value we assign it to the new variable.

    Below is a basic example of looping through a list of DateTime objects and comparing them in the manner you wish:
    Code:
            #region Variables		
    		private List<DateTime> myDtList = new List<DateTime>();
    		
    		private DateTime dtHolder;
            #endregion
    		
    		protected override void Initialize()
    		{
    			
    		}
    
            protected override void OnBarUpdate()
            {
    			myDtList.Add(Time[0]);
    			
    			for (int i = 0; i < CurrentBar; i++)
    			{
    				if (myDtList[i] < Time[0])
    				{
    					if (myDtList[i] > dtHolder)
    						dtHolder = myDtList[i];
    				}
    			}
    			
    			Print("Current Time: " + Time[0] + " value below: " + dtHolder);
            }

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    37 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    23 views
    0 likes
    Last Post PaulMohn  
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    162 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    98 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    152 views
    2 likes
    Last Post CaptainJack  
    Working...
    X