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

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 Jonafare, 12-06-2012, 03:48 PM
    5 responses
    3,984 views
    0 likes
    Last Post rene69851  
    Started by Fitspressorest, Today, 01:38 PM
    0 responses
    2 views
    0 likes
    Last Post Fitspressorest  
    Started by Jonker, Today, 01:19 PM
    0 responses
    2 views
    0 likes
    Last Post Jonker
    by Jonker
     
    Started by futtrader, Today, 01:16 PM
    0 responses
    7 views
    0 likes
    Last Post futtrader  
    Started by Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,791 views
    0 likes
    Last Post aligator  
    Working...
    X