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

Trade Executio IMMEDIATELT after evet

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

    Trade Executio IMMEDIATELT after evet

    1. I'm Working with the Strategy Builder. Using a simple example, I I have a MA crossover strategy that triggers on the cross, How can I have the order execute on the very next bar:
    Code:
    if (CrossAbove(hmaFast, smaSlow, 1))
                    EnterLong();
    ?

    2. In looking at the results in the Strategy Analyzer, When I look at the trades executed by the strategy, The Chart shows Trades that start on 4/9/2018 Buy xx @ 262, BUT the Analyzed does not show this trade and Starts showing trades starting on 4/12/2018. Why is the Analyzer missing the trade on 4/8/2018? I haven't looked to see if there are other discrepancies.

    Thanks
    Last edited by dmking; 09-04-2019, 12:03 AM.

    #2
    Hello dmking,

    Thanks for your post.

    For your first question, historically, the strategy would run once at the end of each bar and if the crossover condition is determined, then your market order would be placed/filled on the next bar. You can confirm this by adding a draw object to your code that places (for example) a dot on the bar where the condition is true and then you would see the entry execution on the next bar.

    If testing on live data (or market replay) and you are using Calculate.OneachTick or Calculate.OnPriceChange then for the live trades these would likely occur intrabar on the same bar where the cross is detected. In the NT8 strategy builder, you could create an int variable and a bool variable, and when the cross occurs save the Misc>CurrentBar into the variable and change the state of the bool to true. In another set you would check for the bool to be true and check that the current bar is not equal to the variable you previously saved the current bar into, thus ensuring that the set is only true 1 bar after the cross occurs to then place your order (and also reset the bool).

    For your second question, please post screenshot shot of the strategy analyzer settings being used, a screenshot of the strategy analyzer chart that shows the missing trades, and finally the strategy analyzer "Trades" tab that shows these are missing, thank in advance..
    Last edited by NinjaTrader_PaulH; 09-04-2019, 08:54 AM. Reason: Changed to NT8 only reply.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Sorry Paul, I was Tired as you can tell by the spelling.

      This is for NT8. I'll do as you asked.


      D

      Comment


        #4
        Paul,

        I'm going to move this over to the NT8 Strategy Builder Forum.

        Comment


          #5
          Thanks Paul,
          For your first question, historically, the strategy would run once at the end of each bar and if the crossover condition is determined, then your market order would be placed/filled on the next bar. You can confirm this by adding a draw object to your code that places (for example) a dot on the bar where the condition is true and then you would see the entry execution on the next bar.
          I understand what you're saying above.

          My question is, "Can I have the Order executed IMMEDIATELY, on the bar right after the Crossing event, instead of waiting for the following bar? See the attached picture.
          Attached Files

          Comment


            #6
            Hello dmking,

            Thanks for your reply.

            To have the order placed immediately, as soon as the cross is detected, you would have to run your NT8 strategy in Calculate.OnEachTick or Calculate.OnPriceChange. IOn either of thses modes your OnBarUpdate code is run on each tick or on each price change instead of once at the end of the bar.

            The downside of this is that with intrabar performance, as price changes the indicators may cross then not cross then cross again then not cross and you will place orders for each cross and ultimately it may be when the bar finally closes that there was not actually cross, so this is something that can actually happen. You can work around the cross/recross issues by saving the current bar into an int type variable when the cross occurs and you have placed your first order. In the entry conditions you would add a check to see that the current bar is not the same as the saved bar and this prevent additional orders at least until the next bar. If when the bar closes and there is no cross condition shown, then this can be confusing because when you look at the chart the condition would not place an order yet your strategy did, so be prepared for that.
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Oddly Enough, the suggestion as to when the Calculation is made didn't change the Order Execution from the Following Bar to the Current Bar. Just like you, I expected to see the time of the Order Execution to change to the Current Bar. The only reason that I'm going on about this is that I'm building an AutoTrader. If I'm using hourly bars and I get a signal, I don't want to wait an hour before the order is executed. It seems like if I get a signal (Cross) then, boom, the order is executed immediately in this example.

              When I coded this up in ThinkorSwim, I had the Order go off right away.

              Can you think of anything else that I might try.

              Thanks,

              D

              Comment


                #8
                Hello dmking,

                Thanks for your reply.

                Sorry, my answer was directed with Live data in mind and I forgot that you had referenced the strategy analyzer. The strategy analyzer works only with historical data which only consists of the OHLC of the bar and does not contain the ticks that made up the bar thus regardless of calculate mode it can only run as if it were set to Calculate.OnBarClose.

                To get intrabar performance historically, in the strategy analyzer, you actually would need to modify your strategy for backtesting by adding a faster time frame data series such as a 1 tick series AND running your strategy with TickReplay enabled. This would limit your back tests to only those days for which you have tick data for. The tick replay would get your indicators calculating (updating) on each tick and the added data series would provide a means for filling your orders intrabar. You data provider would need to provide historical tick data.

                Alternatively, you can use the Playback connection with Market Replay data which closely simulates live data conditions (because it is tick by tick recording) and you would not need to modify your strategy. Market replay is a slower analysis means but more real world.

                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  Good Paul. This is a valuable discussion.

                  Let's leave th Analyzer out for now and just talk about running a strategy on a chart with RT data.

                  I want to figure out a way to have an order go off immediately after and event (Crossing). By changing the Calculate parameter to Tick or Price Change we thought that that would bring about the desired result. It didn't. The question is, Can I do anything to force the strategy ti immediately execute upon detection of and event?

                  Thanks for your help and patience.

                  Comment


                    #10
                    Hello dmking,

                    Thanks for your reply.

                    If you are using Calculate.OnEachTick or Calculate.OnPriceChange set as the mode then if the cross condition occurs and if you are placing a market order (EnterLong()) it will fill immediately. If it does not then there would be some condition that is preventing the order from being applied. You would need to check the "Log" tab of the control center for any error messages related to the strategy.

                    You would also need to check the "strategy" tab to ensure your strategy color is Green. If it is not green or yellow then that indicates that you have not enabled the strategy or there is a run time error and the log tab should show this error.

                    If the strategy is yellow, that indicates it is waiting to complete its last historical trade according to the logic created, once completed the strategy will turn green and being placing live trades.

                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Paul,

                      I think we chewed all the flavor out of this for today. I do as you suggest. If I still have problems I'll let you know.

                      D

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by geddyisodin, Yesterday, 05:20 AM
                      8 responses
                      51 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by cmtjoancolmenero, Yesterday, 03:58 PM
                      10 responses
                      36 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Started by DayTradingDEMON, Today, 09:28 AM
                      4 responses
                      24 views
                      0 likes
                      Last Post DayTradingDEMON  
                      Started by George21, Today, 10:07 AM
                      1 response
                      17 views
                      0 likes
                      Last Post NinjaTrader_ChristopherJ  
                      Started by Stanfillirenfro, Today, 07:23 AM
                      9 responses
                      25 views
                      0 likes
                      Last Post NinjaTrader_ChelseaB  
                      Working...
                      X