• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Calculate on each tick

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

    Calculate on each tick

    Just a quick question regarding automated trading strategies. Does anyone have any experience using the calculate on each tick when buying and selling using profit targets? I've included a screenshot below of a Market Replay for the ES; if i set my profit as one tick above entry, occasionally i see this result. Is there any likelihood of this happening during live trading?

    #2
    Hello Renorail,

    Thanks for your post.

    I would suggest it is probable that will happen. Your strategy running Calculate.OnEachTick means your strategy code runs on each new tick and ticks can come in quite rapidly. If your code says to place an order, it will place an order. If on the next tick it still says to place an order it will place an order, etc, etc. When you send an order to the exchange, it will take longer than the length one tick in time for the order to be transmitted over the internet, received by the broker/exchange, placed in que, filled and acknowledged back to your strategy position. The order process is run in parallel to your code meaning that they are asynchronous events (incoming ticks fire OnbarUpdate() orders sent/received/filled/acknowledged).

    You will want to control these processes with your logic now that you understand the asynchronous nature of orders to coding.

    For example, if you wanted to only place one order per bar, you could use something like:

    if (your entry conditions && CurrentBar != savedBar)
    {
    //entry order here
    savedBar = CurrentBar; // save the number of the bar being processed to prevent re-entry on the same bar
    }

    In the above, you would need to create an int variable called savedBar. CurrentBar is the system bar counter: https://ninjatrader.com/support/help...currentbar.htm

    Alternately you can work with OnExecutionUpdate(), OnPositionUpdate() and OnOrderUpdate() to get more involved with the synchronizing effort.

    https://ninjatrader.com/support/help...tionupdate.htm
    https://ninjatrader.com/support/help...tionupdate.htm
    https://ninjatrader.com/support/help...rderupdate.htm

    I would also suggesting reviewing the example strategy here if you wish to use these methods: https://ninjatrader.com/support/help...and_onexec.htm

    If you would like your strategy created for you, we can provide references to 3rd party programmers.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thank you Paul for your response. I wrote some code earlier to limit the number of trades per bar, where a counter is reset on first tick of the bar. It works pretty well. I'll take a look at your links as well.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Fastbyte, Yesterday, 11:13 PM
      1 response
      1 view
      0 likes
      Last Post NinjaTrader_ChrisSch  
      Started by StealthM93, Yesterday, 07:58 PM
      1 response
      7 views
      0 likes
      Last Post bltdavid  
      Started by Mykro, Yesterday, 11:01 AM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by bauerjj10, Yesterday, 12:24 PM
      1 response
      15 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by Newtrader101, Yesterday, 06:01 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_EricB  
      Working...
      X