• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

calculating time past 50 percent

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

    calculating time past 50 percent

    I need to figure out ha time stamp is past 50 percent past a bar for example

    I drew a line on a 15 minute time frame and the time is 8:23.15

    what i need to know if the 8:15 bar is half way done.

    I need it for all time frames

    1 min, 2 min 5 min etc

    #2
    Hello ballboy11,

    Thanks for your inquiry.

    You could do so using CalculateOnBarClose = false;

    This way your strategy will iterate on each tick. You can still reference each bar close by using a barsAgo of 1 instead of 0 when a tick iterates FirstTickOfBar.

    As your strategy iterates each tick, you can get the time of the bar close using Time[0] and the current time with DateTime.Now. Depending on the time frame used, you can subtract half of that interval from Time[0] and see if DateTime.Now is greater than it.

    Here is some sample code demonstrating how the logic could be set up for second bars:

    Code:
    TimeSpan TimeToSubtract;
    protected override void OnBarUpdate()
    {
    	if(BarsPeriod.BasePeriodType == PeriodType.Second)
    		TimeToSubtract = new TimeSpan(0,0,0,(int)BarsPeriod.Value/2);
    	if(FirstTickOfBar)
    	{
    		Print(Close[1]); // Prints the same as Close[0] with CalculateOnBarClose = true;
    	}
    	if(ToTime(Time[0].Subtract(TimeToSubtract)) < ToTime(DateTime.Now))
    		Print("Halfway done with second type bar");	
    }
    I will include documentation links below on the items used so they may be referenced to expand the logic for minutes, etc.

    BarsPeriod - https://ninjatrader.com/support/help...barsperiod.htm

    FirstTickOfBar - https://ninjatrader.com/support/help...ttickofbar.htm

    Time - https://ninjatrader.com/support/helpGuides/nt7/time.htm

    ToTime() - https://ninjatrader.com/support/help...nt7/totime.htm

    Additional reading on general C# DateTime and TimeSpan can be found below.

    DateTime - https://msdn.microsoft.com/en-us/lib....datetime.aspx

    TimeSpan - https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Please let me know if I can be of further help.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by ballboy11, Today, 04:29 PM
    0 responses
    5 views
    0 likes
    Last Post ballboy11  
    Started by zacharydw00, Today, 02:29 PM
    2 responses
    20 views
    0 likes
    Last Post zacharydw00  
    Started by timcjpfx, Today, 06:22 AM
    4 responses
    27 views
    0 likes
    Last Post timcjpfx  
    Started by welson, Today, 08:26 AM
    2 responses
    17 views
    0 likes
    Last Post NinjaTrader_PatrickG  
    Started by brucerobinson, Today, 08:27 AM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_Kate  
    Working...
    X