Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 rocketman7, Today, 02:12 AM
    5 responses
    23 views
    0 likes
    Last Post rocketman7  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    7 responses
    28 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by samish18, 04-17-2024, 08:57 AM
    17 responses
    66 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by briansaul, Today, 05:31 AM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Started by PaulMohn, Today, 03:49 AM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Working...
    X