Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How can I make sure trades happen only one per bar?

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

    How can I make sure trades happen only one per bar?

    HI i havea a strategy oneachTick. How can I make sure orders are only open one per bar.
    I have
    (Position.MarketPosition == MarketPosition.Flat) &&
    (BarsSinceExitExecution("MyStopLong") > 1 || BarsSinceExitExecution("MyStopLong") == -1)

    Click image for larger version  Name:	image.png Views:	0 Size:	376.8 KB ID:	1249898

    Last edited by tkaboris; 05-04-2023, 03:55 AM.

    #2
    You need to save this in a variable. A potential problem with OnEachTick is that it takes a bit to get an execution so BarsSinceExecution isn't updated and in the meantime you are sending order after order after order. But, another approach would be if these are managed orders and you are not scaling in, set EntriesPerDirection to 1. If you are scaling in, set EntryHandling to EntryHandling.UniqueEntries and set EntriesPerDirection to 1 and give each "scale-in" part a different entry name. See also: https://ninjatrader.com/support/help...ryhandling.htm
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Hello tkaboris,

      Thank you for your post.

      I see within BarsSinceExitExecution you are using the signal name "MyStopLong" - does this match one of the signal names used in your strategy? Based on your screenshot, I see "SL" and "2EL" though I am not seeing a signal name of "MyStopLong" so this could potentially be the issue.

      Otherwise, since you want only one entry per bar, you could try using a bool that gets set to false when an entry has been submitted for that bar, then it gets set back to true on the first tick of the next bar. For example:

      Code:
      if (IsFirstTickOfBar && allowEntry == false)
      allowEntry = true;
      
      if (Position.MarketPosition == MarketPosition.Flat && allowEntry = true)
      {
      // entry order here
      allowEntry = false;
      }
      Please let me know if I may be of further assistance.

      Comment


        #4
        HI
        I have wrote this for Longs since. Would this be correct then?

        && (BarsSinceExitExecution("SLL") > 1 || BarsSinceExitExecution("SLL") == -1)
        && (BarsSinceExitExecution("PTL") > 1 || BarsSinceExitExecution("PTL") == -1)

        ExitLongStopMarket(0, true, Position.Quantity, StopLossTicks, "SLL", "2EL");

        ExitLongLimit(0, true, Position.Quantity, Position.AveragePrice + (TickSize * ProfitTargetTicks), "PTL", "2EL");​

        Comment


          #5
          Hello tkaboris,

          Thank you for your reply.

          Just based on your snippet out of context, I am not sure if this will result in your desired behavior. You will ultimately need to test your strategy to observe and understand its behavior. What I can see is you are using the signal names from your exit orders ("SLL" and "PTL") in your condition that checks BarsSinceExitExecution which does appear to be correct. As mentioned in the help guide page for BarsSinceExitExecution(), the signalName should be the signal name of an exit order specified in an order exit method:


          Please let me know if I may be of further assistance.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          71 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          143 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          76 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          47 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          51 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X