Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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

    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Very helpful! Thank you!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by andrewtrades, Today, 04:57 PM
      1 response
      4 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      3 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      6 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X