Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

problem running strategy CalculateonBarClose = false

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

    problem running strategy CalculateonBarClose = false

    Hello,
    I have a strategy I have been running live that has been coded to work using CalculateonBar =True and things work fine. I recently began modifying a version that would run on each incoming tick to judge the difference between the performance between the two strategies.

    The problem I am having with CalculateOnBar = false is when my strategy hits the condition to enter a trade, it submits the order but before the order can even be filled (and i'm using market orders) the next TICK is coming through and triggering the order condition again because the first order has not yet been filled. So my strategy is duplicating each order because it does not have the time to finish processing its instructions before the next OnUpdate() method gets triggered.

    Is there anyway to pause / delay the strategy just a few seconds to complete instructions before the next tick comes in? I suppose I could try and immediately set a variable that says PROCESSING = TRUE and just check that flag before doing anything onBarUpdate but let me know if there is anything more robust for this issue.

    (editing this as I don't think the processing flag would even work due to no straightforward way to break out of it)

    Thanks!
    Last edited by slocumtrader; 02-04-2014, 12:52 PM.

    #2
    Hello slocumtrader,

    You can control this by using a bool variable in your strategy.

    When a market order is submitted change the value of the bool. Once the order has filled changed the bool back.

    I would recommend using a different variable for each set of orders. I also recommend changing the bool back in the OnExecution method so that this will be set as quickly as possible.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi ChelseaB,

      Could you help point me in the right direction to determine when the order has been filled? I am using the unmanaged approach submitting orders. My code looks something like this:

      entryOrder = SubmitOrder(currentIndex, OrderAction.Sell, OrderType.Market, quantity, 0, 0, "", orderName);


      I assume I can use the orderName variable and check against that to determine when an order gets filled when I get into the onbarupdate method? Any examples you can point me to would be great!

      thanks!

      Comment


        #4
        Hey slocumtrader,

        There is a reference sample that demonstrates this I am linking below.
        http://www.ninjatrader.com/support/f...ead.php?t=7499

        In this sample, take a look at the OnExecution() method. In here the order we are detecting a fill on has an IOrder handle just like you have created. The script compares the execution object to the entryOrder IOrder handle. They are the same so you can use the execution object to check the fill state.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi ChelseaB,

          Thanks for that link, I implemented similar logic to the example and it seems to work fine now, yay! But this leads me to another question

          When running my strategy on CalculateOnBarClose = false I have some logic i DO only want done every 1 minute, and not every tick. What is the most efficient way to determine when I am at a new 1 minute bar? I imagine i can introduce a dateTime object and check seconds but I am not sure if that's the best way. Any suggestions would be appreciated.

          Thanks!

          Comment


            #6
            Hello slocumtrader,

            When using Calculate on bar close as false you can detect the first tick of a bar using FirstTickOfBar.

            For example
            if (FirstTickOfBar)
            {
            // execute code
            }

            Below is a link to the help guide on FirstTickOfBar.
            http://www.ninjatrader.com/support/h...ttickofbar.htm
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            633 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            364 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            105 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            567 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            568 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X