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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    571 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    330 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    549 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    549 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X