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

Exit after single bar / ignore entry bar

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

    Exit after single bar / ignore entry bar

    Hi all,

    Q1: I am trying to exit a strategy after one bar from my entry. But if I set the "Bars Since Entry" to number value 1, the strategy waits two bars. How can I avoid this? This strategy calculates after bar change

    Q2: In another strategy I am seeking to exit a strategy (from a long position) after a red bar. It is working fine, except for when my entry bar is a red bar, then my strategy just enters and immediately exits as it detects the previous bar (entry bar) was red. How can I exit in this case but ignore the entry bar. When I set the "Bars Since Entry" to number value 1, my strategy waits two bars again, at least, and will only exit two bars after entry (at a minimum). Looking for it to exit on a red bar, if the first red bar AFTER entry is red. This strategy calculates after bar change

    #2
    Hello Austiner87,

    Thank you for your note.

    It would be expected that when running a strategy On Bar Close that orders triggered by your logic will be submitted at the open of the bar following the one that actually triggers the order. So, if you're checking that at least 1 bar has elapsed since the strategy entered, it would look like this:

    Entry bar > entire next bar goes by and triggers an exit order since bars since entry now equals 1 > exit order is submitted on the open of next bar.

    You would need to run the logic OnPriceChange or OnEachTick for the exit to be triggered on the next bar after the entry.

    For the second thing, where you want to ignore it if the entry bar was red, again, you'd need to be running On Price Change or On Each Tick for it to exit on the next bar after the entry if that bar is a red bar. The issue then becomes that you don't know while the bar is forming if it will be a red or green bar once it closes, you can only tell if the current price is less than the open of the bar at a given point, so really what you'd have to do is as long as you're at least 1 bar from the entry, check whether the prior bar was a red bar and then submit the entry if it was, which would essentially give you the same behavior as you'd get running OnBarClose and checking that at least 1 bar has passed - the exit would be seen on the next bar after a red bar.

    Please let us know if we may be of further assistance to you.

    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hello, I am still having trouble getting this to work, I'd like to ask an alternate question:

      is there a way to exit after a specified lapse of time. for instance, I can accomplish my goal to exit using after a single bar if I use 1 minute bars and have my strategy exit 60 seconds after entry. I see the bar timer indicator is not available in the strategy builder, but can I use it in a ninjascript? and when Bar Timer = 00:01 (or something) I exit the trade? thank you.

      Or perhaps I could fill a variable with the time of entry minus 60 seconds, and then once current time equals that variable, I exit?

      can you confirm this is possible before I attempt, thank you!


      Comment


        #4
        Hello Austiner87,

        Thank you for your reply.

        The bar timer is not available in the Strategy Builder as it does not expose information about its countdown and is a visual tool.

        There wouldn't be a good way to do this in the Strategy Builder, unfortunately. You could try using a timer that is triggered when an order is filled to send another order 60 seconds later, but that will require some advanced manual programming skill. If you want to try going this route, you'd need to monitor for a fill in OnExecutionUpdate and start the timer, then when the timer reaches 60 seconds send an order to exit.

        This example from our help guide illustrates using a timer:



        And this example shows how to monitor in OnExecutionUpdate for order fills:



        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        6 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        158 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        7 views
        0 likes
        Last Post Belfortbucks  
        Started by zstheorist, Yesterday, 07:52 PM
        0 responses
        7 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        151 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Working...
        X