Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EMA cross

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

    #16
    Hello,

    To look inside the bar for sure request custom coding. You would follow this sample to do this:

    You can submit orders to different Bars objects. This allows you the flexibility of submitting orders to different timeframes. Like in live trading, taking entry conditions from a 5min chart means executing your order as soon as possible instead of waiting until the next 5min bar starts building. You can achieve this by


    let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #17
      Originally posted by mateo321 View Post
      Strategy takes signals based on EMA crosses on 5 min chart. With offset set to zero the price I'm getting (in the backtest) is the close of the bar on which the cross has occured. With offset set to lets say to -3 pips I'll still be getting the close of that bar (or opening of the next one because it's the same thing) because alghoritm can give you only one of those four prices (open,high, low, close) and you're getting whichever is closer to the price where your signal fired off.
      That's why you need to look inside the bar
      Not if you are using Limit orders. The order will be submitted at the Limit price, and the backtest/optimize engine will only fill the order if the price bar on which the order is placed actually intersects the limit price. That is how I optimize my entry offsets.

      Comment


        #18
        so the backtest engine will give you a fill when the price at which you're trying to sell goes bid, is that right ??

        Comment


          #19
          Hello,

          It doesn't take into effect bid or ask, only if a trade or last place occurred there will it fill it.

          Let me know if I can be of further assistance.
          BrettNinjaTrader Product Management

          Comment


            #20
            For some reason backtest of my strategy looks differently after apllying limit orders. Net profit is for times smaller. I put my limit orders at close with zero offset. So I don't know where's the difference coming from ?

            Comment


              #21
              Here's the code after applying limit orders. The backtest results I get with this shouldn't be any different from the previous version with market orders or maybe I'm wrong ?

              if (CrossAbove(EMA(8), EMA(21), 1))
              {
              ExitLongLimit(Close[
              0] + Of_S * TickSize, "", "");
              EnterShortLimit(DefaultQuantity, Close[
              0] + Of_S * TickSize, "");
              }
              // Condition set 2
              if (CrossBelow(EMA(8), EMA(21), 1))
              {
              ExitShortLimit(Close[
              0] + Of_L * TickSize, "", "");
              EnterLongLimit(DefaultQuantity, Close[
              0] + Of_L * TickSize, "");
              }

              Comment


                #22
                Mateo, if you use limit orders, the orders will fill only at the limit price. When backtesting with market orders, the orders will fill at the open of the next bar, which could be significantly different than the limit price.
                AustinNinjaTrader Customer Service

                Comment


                  #23
                  Here's what I don't understand. Next bar open equals previous bar close (assuming continues session) and my limit orders are placed at the closing price of the bar on which EMA cross occured (offset is set to 0). So to me that should be the same thing.

                  Comment


                    #24
                    mateo, depending on what you're trading, the open could be vastly different from the close, especially if the bars are 5 minutes or longer. Say a tick comes in for July crude at 11:59:58 at 100.00 on a 5 minute bar. The next tick occurs at 12:03:56 at 100.83. This tick will generate the close of the previous bar, which would then also generate your order at 100.00. The open of the next bar, however, would be at 100.83 and that is where a market order would be filled.

                    If you need your orders executed at specific prices, you must use limit orders.
                    AustinNinjaTrader Customer Service

                    Comment


                      #25
                      I don't understand how a trade at 12.03 can generate a prevoius 5 min bar close. Shouldn't it be the last trade before 11.59.59 ? What I'm trying to do here is to play around with entries/exits around prices I'm getting filled at with market orders. If close of the previous bar and open of the next one can differ can I just set my limit order at opening price of the next bar +/- offset ? This price is not known untill the first trade on the new bar so I'm not sure if it can be done

                      Comment


                        #26
                        NinjaTrader is not time but event based, so for example in an illiquid or slow market you could definitely wait a bit for the tick to come in that would close the old bar and open the new one. You could run in realtime / Market Replay with CalculateOnBarClose to false and then submit your order in FirstTickOfBar context, then you would have the open price value and could work an order at this exact limit price.

                        Comment


                          #27
                          well that sounds complicated to say the least. So a tick that comes at 12.08 might be considered a closing price for the last 5 min bar on the chart. Nice, I think that makes my task undoable here.

                          Comment


                            #28
                            Yes this is the reality of bar data in NinjaTrader. NinjaTrader only knows the OHLC of each bar. Whether that bar started at 11:59:00 or 12:03 doesn't matter. What matters is when the pricing data came through in the market and your logic should be unaffected by this. Since it will still get the low price of the bar correct and therefor the limit order will still be submitted correctly based on market action and would be true to market conditions. The only time you'll get a delayed date like that is if there is little volume. Which would only occur either overnight or illiquid markets Is this you’re seeing or are you seeing this all the time on popular futures contracts like the ES? If that's the case I may want to look into your data to make sure it matches my own data and is correct.

                            There only a few cases where this would cause issue, and in those cases you would simply need to test the strategy live on realtime data for this not to happen as then you have access to tick by tick live feed data and not just the bar data. You can test on Market replay or simulated live to the sim101 account. Which is what Bert mentioned.

                            Let me know if I can be of further assistance.
                            BrettNinjaTrader Product Management

                            Comment


                              #29
                              Please test this code on AUD/CAD (last 2 years, 5 min chart). Then try the same thing just with market orders

                              if (CrossAbove(EMA(8), EMA(21), 1))
                              {
                              ExitLongLimit(Close[
                              0] + Of_S * TickSize, "", ""
                              );
                              EnterShortLimit(DefaultQuantity, Close[
                              0] + Of_S * TickSize, ""
                              );
                              }
                              // Condition set 2
                              if (CrossBelow(EMA(8), EMA(21), 1
                              ))
                              {
                              ExitShortLimit(Close[
                              0] + Of_L * TickSize, "", ""
                              );
                              EnterLongLimit(DefaultQuantity, Close[
                              0] + Of_L * TickSize, ""
                              );

                              Comment


                                #30
                                You would almost necessarily have different results with different entry orders. For one thing. market orders will always be filled, albeit at an, ab initio, indeterminate price, whereas limit orders may not get filled, even if touched, and certainly not if the market runs away.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                666 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                377 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                110 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                575 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                580 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X