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

Easy way to exit trade after specific amount of time using Ninzarenko bars?

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

    Easy way to exit trade after specific amount of time using Ninzarenko bars?

    I’ve seen the minimal posts on the board regarding this but I don’t find it helpful at all.

    It seems like this is so basic but not explained well anywhere on how to do it. Im looking to simply be able to close a trade if still open after 5 minutes. I cannot use bars to decide when to close as I am using Ninzarenko bars.

    Has anyone found a video tutorial or something that shows how to code this?

    This link seems to sort of explain it but unfortunately not being much of a coder it doesn’t make sense.

    https://ninjatrader.com/support/foru...fter-x-minutes

    itd be nice if there was some type of sample strategy that had it all coded then I could copy the code over to mine.

    mid you can help at all it’s much appreciated!

    #2
    Hello yeahdudeman,

    Exiting after an amount of time really depends on the setup of your script and the bars type being used. Renko bars arent time based so doing something after X time can be problematic because the bar close times won't be consistent to check if X time has passed.

    To check if a certain amount of time has passed since an event you can use C# DateTime objects to do that. The easiest way to do that would be to generate a new end time when your entry is submitted or filled and save that time to a variable. You can add 10 minutes to a C# DateTime object and then save that to a variable.

    The renko bar times won't be consistent so you wouldnt be able to use those to add 10 minutes to make a end time. This would be a situation where adding a 1 second secondary series would be the easiest way to have a constant updated timestamp and also execute logic after X time.



    Assuming you added a 1 second series your logic would end up looking like the following to generate a +10 minute timestamp from the time of an event.

    Code:
    private DateTime endTime = DateTime.MaxValue; 
    protected override void OnBarUpdate()
    {
        if(BarsInProgress == 0)
        {
             if(someEntryCondition)
             {
                EnterLong();
                endTime = Times[1][0].AddMinutes(10);  // take the secondary 1 second timestamp and save it + 10 minutes
    
             }
        }
        if(BarsInProgress == 1)
        {
            if(Time[0] >= endTime)  // check if the 1 second time is greater or equal to the target time of +10 minutes since the entry
            {
                 // exit logic here because the current time is 10 minutes past the entry time
                 endTime = DateTime.MaxValue; // set the end time to an max end date so this condition does not keep happening, once your entry logic happens again it will reset the time to 10 minutes past that entry time
            }
        }
    }



    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by athexinehowley, Today, 02:39 AM
    0 responses
    4 views
    0 likes
    Last Post athexinehowley  
    Started by dtaylor, Today, 02:24 AM
    0 responses
    4 views
    0 likes
    Last Post dtaylor
    by dtaylor
     
    Started by RosaRichardow, Today, 12:21 AM
    1 response
    5 views
    0 likes
    Last Post marcus2300  
    Started by ETFVoyageur, Today, 12:45 AM
    1 response
    8 views
    0 likes
    Last Post ETFVoyageur  
    Started by TradeSaber, Yesterday, 10:33 PM
    1 response
    12 views
    0 likes
    Last Post TradeSaber  
    Working...
    X