Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATM functionality for backtesting and questions

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

    ATM functionality for backtesting and questions

    I'm an experienced programmer, I have made some complex indicators for NinjaScript (some of which I have submitted to the 6.5 sharing area), but until now I have not tried my hand at creating strategies. I've looked through the documentation, the reference samples, some posts on this forum, and some of the user-posted strategies in the file area.

    I still have a few questions, for anyone knowledgeable, not just support staff:
    1. Everything I've seen appears to be a self-contained strategy with entries and exits. Coming from TradeStation, where I could program separate complex logic for entry orders and exit orders and then add them to a strategy, I'm wondering if I can do that here. Can I have a strategy containing only exit orders and add it to a chart along with another strategy that contains only entry orders? Or do they all need to be mashed into the same module?
    2. I've been relying on ATM for real-time trading. I know ATM isn't available for backtesting. But surely someone has figured out a way to duplicate this functionality within NinjaScript? Example ATM operations I would need are: enter 3 contracts, 20 tick initial stop, exit 1 contract at a time at 10, 20, 30 tick targets, auto-breakeven+2 ticks stop when reaching 10 tick target. Has anyone done something like that?
    3. If I have to write it myself, would it be feasible to do it with the managed order coding, or would I need to go with Unmanaged (I dread the bookkeeping code I'd have to write in that case)?
    4. If I have a SetStopLoss() active for a order for 3 contracts, and I exit one contract, does the active SetStopLoss() change its quantity accordingly without any intervention from me?
    5. I know orders die at the end of each bar unless I set them to live until cancelled. If I place the same order several times within the same bar as new tick data comes in, does it get replaced or do I need to cancel it myself first?
    6. I read in the documentation that when an order like EnterLongLimit() is working but unfilled, an opposing order like EnterShortLimit() will be ignored. If my strategy decides to place an order in the opposite direction, would the strategy have to cancel the original order first, even if both orders are generated on different ticks in the same bar?

    I'm just trying to get an idea of what's involved with order management while backtesting on NinjaTrader.
    -Alex
    Last edited by anachronist; 07-14-2011, 07:08 PM.

    #2
    Hi Alex,

    1. Correct, strategies are self contained scripts, they would not cross communicate.
    2. I'm not aware of a complete sample posted for emulating ATM's in backtesting, but a basic start would be showcased here - http://www.ninjatrader.com/support/f...ead.php?t=3222
    3. It will depend on the level of flexibility you seek, if you're frequently running into the order management rules of the managed approach for example using the unmanaged one would be advantageous.
    4. Yes, if you scale in to scale out later - then the Set() order 'protecting' the partial position would be cancelled if needed (if the corresponding position or partial position here is closed).
    5. If you resubmit using the same signal name it would update the order.
    6. That's correct, the internal order handling rules would trigger here, so if you cancel the other order first, wait for a confirmed order state change to cancelled and then submit your new order in the opposite direction, you should be good - you could also use market orders in those cases - they are not affected by the managed approach order handling rules.

    Comment


      #3
      Thank you, Bertrand.
      Originally posted by NinjaTrader_Bertrand View Post
      1. Correct, strategies are self contained scripts, they would not cross communicate.
      Ah. OK. It seems to me that there is a bit of "cross communication" via the Position property, which is visible to all the strategy scripts regardless of which strategy created the position. Or is Position different for each script?

      The reason I asked is that I have a number of different exit strategies, and I may want to use one that's common to several different entry strategies. Your answer would mean a lot of code duplication.

      Thanks for the example link.

      In the case of EnterShortStopLimit() being ignored if EnterLongStopLimit() is working, would that also be true if the signal name in each one is different? I note that I can place opposing orders like this in if I use different ATM strategy names, so I wondered if that string parameter in the order entry methods would were analogous to ATM strategy names.

      -Alex

      Comment


        #4
        Alex, there is no cross communication unless you explicitly code it. Every strategy has its own Positions property, so one strategy won't be able to see the position of another.

        As for your second questions, internal order handling rules (http://www.ninjatrader.com/support/h...d_approach.htm) prevent two opposing orders from being placed at the same time. To get around this, you'll need to move to an unmanaged strategy - http://www.ninjatrader.com/support/h...d_approach.htm.
        AustinNinjaTrader Customer Service

        Comment


          #5
          OK, thanks. It wasn't clear to me whether Position was global to your instrument or local to each strategy.

          I see now the order handling rules say they apply per unique signal name. So if I have two opposing orders with different signal names, they would both be accepted.

          Another variation of my question: Suppose I have one strategy for long trades and a different one for short trades. Two separate scripts. If they happen to place opposing orders that bracket the price (and the two orders happen to have the same signal names), would one of them still be ignored, or does each strategy run independently without interference from existing orders in another?

          -Alex
          Last edited by anachronist; 07-15-2011, 02:40 PM.

          Comment


            #6
            Alex, everything about different instances of strategies is separate. Thus, if your long strategy was long 1 and then your short strategy decided to go short 1 (even with the same order names), your actual account position would be zero, but the long strategy would still think it was long 1 and your short strategy would still think it was short one. Does that answer your question?
            AustinNinjaTrader Customer Service

            Comment


              #7
              Yes, thank you.
              -Alex

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              671 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              379 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              111 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              575 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              582 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X