Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to trigger buy signal when EMA1 cross EMA2 at current bar

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

    How to trigger buy signal when EMA1 cross EMA2 at current bar

    Dear Team,
    Now I'm using:


    if (CrossAbove(EMA1, EMA2, 1))
    {

    EnterLong(_posSize, LongPos);
    }

    But the Enterlong action always occurs after 1 or 2 bars after the cross happened.

    How can make the Enterlong action occurs in the current bar that when the cross just happen?

    Thank you so much!!!
    Last edited by williamzz; 06-25-2019, 09:40 AM.

    #2
    Hello williamzz,

    Thanks for your post.

    Historically, it will always show that when the condition is true in one bar the order is filled on the next bar. This is because your code historically is executed once per bar, at the end of the bar, so the entry condition is evaluated and if an order is to be placed the order is submitted but cannot be filled until the next bar.

    If the strategy is running on live (or replay data) and is set to "Calculate.OnBarClose", the same behavior will show on live data.

    To place intrabar orders, with live or replay data, you would need to set the calculate to Calculate.OnEachTick or Calculate.OnPriceChange. Please note that using either of these may result in the strategy placing multiple orders at once (as your entry conditions become true/false repeatedly) and you may need additional controlling logic in your strategy to only place the number of orders you specify.

    Reference: https://ninjatrader.com/support/help...?calculate.htm

    Comment


      #3
      Very helpful! Thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      87 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      132 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      65 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      118 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      67 views
      0 likes
      Last Post PaulMohn  
      Working...
      X