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

Not buying at legitimate price

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

    Not buying at legitimate price

    I have a strategy that trades both ES and MES. When running the strategy live, the strategy will buy MES at a price nearly 100 points below the price it is currently trading at (5152.25 at around 3:30 pm on Wednesday March 20th). How may I fix this?

    #2
    Hello samish18,

    Thanks for your post.

    Is this a strategy that you programmed yourself or is this a strategy from a third-party developer?

    Does the strategy submit a market order, limit order, stop limit order, or stop market order to enter a position?

    If this is a strategy you created and it is not behaving as expected, it is necessary to add debugging prints to the strategy to understand exactly how the logic of the strategy is behaving.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. One line above our Enter order methods, add prints that print out the value you are passing into the Enter method. Print out the order object in OnOrderUpdate() to see how the order is behaving.

    And, enable TradeOrders which is a useful property when debugging the behavior of your orders. With the use of this property, you can track orders placed, amended, and canceled. The traces displayed in the NinjaScript Output window

    Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    ​Below is a link to a forum post that demonstrates how to use prints to understand behavior.

    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      It is a strategy I created. It uses market orders. In the strategy tab of the control center, after "entering a position" the text of the strategy name goes yellow and the price of avg. price definitely incorrect

      Comment


        #4
        Hello samish18,

        Thanks for your notes.

        Are you referring to a historical (virtual) position that the strategy calculated upon enabling the strategy?

        When a strategy is enabled, it processes historical data to determine trades that the strategy would have made on the data that is already on the PC/chart and to determine what position the strategy is in. (Strategy positions are separate from actual Account positions.)

        When a strategy is yellow (or orange on some monitors) in the Strategies tab of the Control Center, this means that the strategy entered a historical (theoretical) position in the historical data that has been loaded.

        It also means that you have "Wait until flat" selected for the 'Start behavior' option in the strategy parameters.

        This means that once the strategy has finished processing the historical data and has transitioned to real-time, it will wait until there is a real-time order submission that will cause the strategy to become flat. This also includes changing from a long position to a short position or vice versa as the position would pass through flat.

        This also applies to secondary instruments if there are added series to the script. All positions must be flat before real-time orders will begin.

        You can observe the Strategies tab of the Control Center to see if the strategy is in a virtual position waiting to become flat. The strategy will be orange/yellow when waiting for the historical position to be closed, and will be green when allowed to trade live.

        If this is the case and you want the strategy to start from a flat position instead, you can add the following line to the top of the strategy's OnBarUpdate method to prevent it from calculating a historical position.

        if (State == State.Historical) return;

        Or, you can change the start behavior to "Immediately submit" in the parameters of the strategy. Immediately Submit automatically submits working orders from when the strategy processed historical data, and assumes the strategy position and account position are where you want it when you enable the strategy. This is typically used to have a strategy resume a position after disabling/enabling. If the strategy already had live orders running, the orders will resume with the new enablement of the strategy if they match the historically calculated orders. If the orders calculated from historical data do not match the live working orders, the live working orders will be cancelled and replaced by those calculated from historical data.

        Sync Account Positions is an additional option that has NinjaTrader submit an order to sync the account position to the position calculated by the strategy. (Not the other way around.)

        ​See the help guide documentation below for more information.

        Strategy vs. Account Position — https://ninjatrader.com/support/help..._account_p.htm
        Start Behaviors — https://ninjatrader.com/support/help..._positions.htm

        Additional information could be found in this forum thread - https://ninjatrader.com/support/foru...ion#post811541
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          I enabled the Start Behavior to submit immediately and the same issue persists. The strategy enters orders on ES and MES at the same time, however, the avg. price of ES seems to be a recent one while the MES price is one that has not occurred in several days/

          Comment


            #6
            Hello samish18,

            Thanks for your notes.

            To sync the account position to the position calculated by the strategy you could enable the strategy with the Start Behavior set to "Immediately Submit, synchronize account'.

            If you would like your strategy to always start from a Flat position, you can add the following line of code to the top of the strategy's OnBarUpdate method to prevent it from calculating a historical position.

            if (State == State.Historical) return;

            See the demonstration video on this forum thread detailing how Start Behaviors function: https://forum.ninjatrader.com/forum/...ion#post811541

            Further, to understand exactly how your strategy is processing logic and placing trades it is necessary to add debugging prints to the strategy.

            Below is a link to a forum post that demonstrates how to use prints to understand behavior.

            Brandon H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Jonafare, 12-06-2012, 03:48 PM
            5 responses
            3,986 views
            0 likes
            Last Post rene69851  
            Started by Fitspressorest, Today, 01:38 PM
            0 responses
            2 views
            0 likes
            Last Post Fitspressorest  
            Started by Jonker, Today, 01:19 PM
            0 responses
            2 views
            0 likes
            Last Post Jonker
            by Jonker
             
            Started by futtrader, Today, 01:16 PM
            0 responses
            8 views
            0 likes
            Last Post futtrader  
            Started by Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,792 views
            0 likes
            Last Post aligator  
            Working...
            X