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!
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
NinjaTrader
date comparison
Collapse
X
-
Hello pman777,
You can utilize the DateTime methods that are a part of C# from NinjaScript to get the Current day. Once you have todays date you can compare it to the bars date using an if statement in combination with ToDay(Time[0]) for the bars date.
Here is an example.
Code:int barDay = ToDay(Time[0]); int currentDay = ToDay(System.DateTime.Now); if(barDay == currentDay) { //do something here }
Also here is a link to the MSDN documentation on DateTime
Please let me know if I may be of additional assistanceJesseNinjaTrader Customer Service
-
I have a similar question.
I want to write an indicator that tracks open trades on the daily timeframe. I'd like to have an Input Parameter for the date the trade was entered, and then draw on the chart based on the entry date.
Is there a way to convert a date variable into the day of the corresponding bar as it relates to CurrentBar?
For example, if EntryDate = 07/08/2014 and today is 07/09/2014 a function that converts EntryDate to 1. Of course weekends or holidays would have to be accounted for.
Thanks in advance.
Comment
-
Hello Grasul,
Thank you for the question I will be happy to help.
Can you please clarify for me what you are trying to accomplish.
From what you have said I take it that you are trying to get the amount of days between the two dates am I correct?
For example, if EntryDate = 07/08/2014 and today is 07/09/2014 a function that converts EntryDate to 1. Of course weekends or holidays would have to be accounted for.
Please let me know and I will be happy to help.JesseNinjaTrader Customer Service
Comment
-
Sure.
What I'd like to do is create an indicator that took as an input parameter the Entry Date of the trade.
So, I open a blank chart, choose the security, add this indicator to it and add as an input parameter the Entry Date. Then, presuming I keep the window open, as the days go by the indicator is calculating and plotting, targets, stops, all the stuff you pay attention to with an open trade.
All I really want to be able to do is to relate a date to a particular Bar on the daily timeframe. So if EntryDate is today, we'd know that Close[0] was the closing price of EntryDate. If EntryDate was 5 trading days ago, Close[5] would have been the closing price that day. Once I can make that relationship, then I can write what I want the indicator to do from there.
Comment
-
Hello Grasul,
Thank you for the reply I think I can see what you are trying to do. Let me provide the description of how I read your last post so that you can verify I am reading it right.
So if EntryDate is today, we'd know that Close[0] was the closing price of EntryDate. If EntryDate was 5 trading days ago, Close[5] would have been the closing price that day.
So you need to convert a Date that is inputted into an int value of the amount of days from today to get the bars ago?
If this is not correct can you provide a different example, I am just trying to determine what exactly the outcome you are looking for is.
So far I know that you are trying to create a input that you can select a date.
Once you have the date input I am looking to find out what exactly you need to do with this date.
I look forward to being of further assistance.JesseNinjaTrader Customer Service
Comment
-
Sure, sorry I'm not trying to be deliberately vague.
I want to input a date. Then I want to be able to relate that date to a specific bar on a daily chart. I only want to enter the date once, but I want it to always be referenced to the same bar as days go by.
Once I can do this I will do things like this:
Draw on the chart noting which day(bar) the trade was entered.
Calculate a target price for the trade and post it on the chart with a line beginning at the entry date bar and extending into the future.
Calculate a stop price and plot it on the chart beginning at the entry date.
I could do all of this simply by having my Input Parameter be an integer that equaled the number of days ago the trade was entered. Then the bars ago value could be incremented by one every OnBarUpdate. Using the date would just be a little more elegant; if its a hassle I'll just use a bars ago integer.
Comment
-
Hello Grasul,
Thank you for giving more details on this.
I would additionally like to ask what timeframe you are trying to use this on.
If this is a day type chart then this would be an easy comparison as you could compare the current bars date to your input date, if the current bars date is equal to the input date then you would know what bar to use.
This would look something like the following:
Code:if (ToDay(Time[0]) == ToDay(inputDate)) { int barNeeded = CurrentBar; }
If this is on a less than daily type chart then you would have multiple bars with the same date value.
in this situation the comparison of dates would still work you would just need to ensure that you do your calculations after this is complete and the final close value is acquired.
Code:if (ToDay(Time[0]) == ToDay(inputDate)) { int barNeeded = CurrentBar; } if(ToDay(Time[0]) > ToDay(inputDate)) { //run code }
Please let me know if I may be of additional assistance.JesseNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by strategist007, Today, 07:51 PM
|
0 responses
2 views
0 likes
|
Last Post Today, 07:51 PM | ||
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,968 views
3 likes
|
Last Post
by jhudas88
Today, 06:59 PM
|
||
Started by rbeckmann05, Today, 06:48 PM
|
0 responses
4 views
0 likes
|
Last Post
by rbeckmann05
Today, 06:48 PM
|
||
Started by rhyminkevin, Today, 04:58 PM
|
4 responses
58 views
0 likes
|
Last Post
by dp8282
Today, 06:13 PM
|
||
Started by iceman2018, Today, 05:07 PM
|
0 responses
6 views
0 likes
|
Last Post
by iceman2018
Today, 05:07 PM
|
Comment