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 NullPointStrategies, Today, 05:17 AM
      0 responses
      20 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      120 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      63 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      41 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      45 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X