• 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

Close Trade depending on Time

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

    Close Trade depending on Time

    Hi,

    In my strategy, I want to close all trades after 3 pm. The code works fine in 99% of all cases.
    I added a time series = 1 min in the Initialize() method and I use a time comparison OnBarUpdate() method.

    protected override void OnBarUpdate()
    {
    [code]
    if(BarsInProgress == 8)
    {
    Print(Time[0].ToString("dd-MMM HH:mm:ss"));
    if(ToTime(Time[0]) >= IniHour*10000+IniMin*100)
    {
    [code to close trades]
    }
    }
    }

    However, when there is no data (I guess that's the reason), the time is not printed in the output window and the trade is not closed.
    I am attaching two images:
    - one showing the gap in the price
    - the other is the output windows where there is a gap also in the time being printed (e.g. 29 nov 12:15 to 01 dec 17:01)

    Is there a workaround that does not depend on the OnBarUpdate() method to close all trades after an specific time?

    Thanks,





    #2
    Hello Capablanca,

    Thanks for your post.

    Your screenshot does not show the chart time nor what instrument is being shown.

    There was an early close (12:15 PM) for the CME on Friday November 29th, 2019 (Day after Thanksgiving). This would seem to match up with your printed time statements that ended at 12:15 and then began again on Sunday evening session). In that case no there would be no market data to trigger OnBarUpdate() or closing trades.

    There would be no workaround other than to change your strategies to check to see what the close of the session is daily and adjusting that way or simply enabling "Exit On session close" when you apply the strategy (and setting the exit on close seconds to match up with how soon before the close to exit).


    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by EnveousColnago, Today, 02:10 PM
    0 responses
    1 view
    0 likes
    Last Post EnveousColnago  
    Started by AMATX, Today, 01:56 PM
    0 responses
    9 views
    0 likes
    Last Post AMATX
    by AMATX
     
    Started by Mykro, Today, 01:00 PM
    3 responses
    8 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by ptertich, Today, 01:37 PM
    2 responses
    5 views
    0 likes
    Last Post NinjaTrader_Tyler  
    Started by jcbnoles, Today, 12:18 PM
    1 response
    3 views
    0 likes
    Last Post NinjaTrader_Melissa  
    Working...
    X