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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      77 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      53 views
      0 likes
      Last Post CarlTrading  
      Working...
      X