Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Close from specific times of prior day and present day

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

    Close from specific times of prior day and present day

    I want to code a strategy with these conditions:

    Price at 2pm yesterday is greater than price at 10am yesterday.
    Price at 6am today is greater than price at 2pm yesterday.

    Once I know how to do that I can probably figure out the rest of it.

    Thanks

    #2
    Hello RickyTicky,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    The conditions would look like the following:
    Code:
    			// set the close of 10 AM yesterday to a double
    			if(ToTime(Time[0]) == ToTime(10,0,0) && Time[0].Day == DateTime.Now.AddDays(-1).Day)
    			{
    				tenAMClose = Close[0];
    			}
    			// set the close of 2 PM yesterday to a double
    			if(ToTime(Time[0]) == ToTime(14,0,0) && Time[0].Day == DateTime.Now.AddDays(-1).Day)
    			{
    				twoPMClose = Close[0];
    			}
    			// compare the two doubles for yesterday's closes
    			if(twoPMClose > tenAMClose)
    			{
    				// do something
    			}
    			// compare today's close at 6 AM to yesterday's at 2 PM
    			if(ToTime(Time[0]) == ToTime(6,0,0) && Close[0] > twoPMClose)
    			{
    				// do something
    			}
    For information on ToTime() please visit the following link: http://www.ninjatrader.com/support/h...nt7/totime.htm
    For information on Time please visit the following link: http://www.ninjatrader.com/support/h...s/nt7/time.htm

    Please let me know if I may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    152 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    87 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    131 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    127 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    106 views
    0 likes
    Last Post CarlTrading  
    Working...
    X