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

Strategy working in backtest, not triggering in real time.....

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

    Strategy working in backtest, not triggering in real time.....

    public class dcXTest.docx

    Hi all,

    So this is probably something stupid from my end but I am stuck on this so here goes.... So I have a very simple strategy that triggers a buy or sell when one price crosses the t-1 close of a indicator. Relatively straight forward. It should be triggering today, given the market move. When i run the backtest, i can see that indeed it has a sell trade registered in there for today, exactly as I would expect. But when I try and run the strategy in real time It doesn't trigger a sell.

    What am i missing? I have attached a cut down part of the strat which is failing.

    thanks in advance

    dan
    Last edited by Daniel008; 11-29-2021, 11:04 PM.

    #2
    I noticed that mine isnt taking trades when its not in sync so I try to force it to resync but it wont sync up.

    Comment


      #3
      mmm i tried that also... and same result....

      Comment


        #4
        Hello Daniel008,

        Thanks for your post.

        If the strategy is yellow in the Strategies tab of the Control Center, this means it is waiting until the strategy is flat so it enters from an entry instead of from an exit.

        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 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.)

        If you do not want the strategy to calculate a position from processing historical data. Simple add if (State == State.Historical) return; to the top of your strategy logic so historical processing is skipped. The strategy will then always start from a flat position because it has not calculated any orders.

        If a strategy is green in the Strategies tab of the Control Center and is not making trades, you would need to debug the strategy using prints and TraceOrders to confirm order methods are reached and the orders are not getting ignored.

        Below is a link to a forum post that demonstrates how to debug using prints and TraceOrders to understand the behavior of a script.
        https://ninjatrader.com/support/foru...121#post791121

        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

        Let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Hi Brandon,

          Thank you for your reply. The strategy is green in the Control Center, so I'll start the debug process now. But it does seem odd, since I separated that bit of the strategy and built it in the automated Strat builder so not sure what could be wrong with it....

          Anyway, debugging.....

          Comment


            #6
            It seems that trying to use Position.MarketPosition=MarketPosition.Long or Position.MarketPosition=MarketPosition.Short is doing something to confuse it. I have build two idential strats - one with that included and one without. The one without it triggers in the control panel as I would expect.

            I guess I was trying to use marketposition in the wrong manner.

            regards

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Graci117, Today, 11:40 PM
            0 responses
            3 views
            0 likes
            Last Post Graci117  
            Started by BIOK.NT, Today, 01:56 PM
            2 responses
            11 views
            0 likes
            Last Post BIOK.NT
            by BIOK.NT
             
            Started by i2ogu3, Today, 11:31 PM
            0 responses
            4 views
            0 likes
            Last Post i2ogu3
            by i2ogu3
             
            Started by RDTrader16, Today, 10:19 PM
            0 responses
            8 views
            0 likes
            Last Post RDTrader16  
            Started by gemify, 03-08-2023, 08:02 AM
            9 responses
            150 views
            0 likes
            Last Post culpepper  
            Working...
            X