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 Is Working In Strategy Analyzer But Not working Real Time

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

    Strategy Is Working In Strategy Analyzer But Not working Real Time

    I am currently evaluating NinjaTrader 8 and trying to determine if I can use this as a trading tool, but can't seem to get a stable / consistent platform

    I have created a basic MACD Cross Strategy when MACD Cross Above AVG, Enter Long and When Cross Below AVG Exit Long
    What I am finding is that although the Strategy is working and showing results in Strategy Analyzer, when I try to run this during normal trading hours, it does not make any trades based on criteria.

    Are there restrictions in the DEMO that are preventing this or something else I need to check / correct. I will say that this has worked a couple of times during normal trading hours, but very infrequently and not based on the criteria condition, has been hit or miss.

    Looking for support before I throw in the towel on Ninja Trader




    #2
    Hello jstaft,

    Thank you for your post.

    There are no restrictions for running a strategy on the Sim101 account.

    If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true or the order is being ignored for other reasons.

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    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.

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

    Also, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

    Below is a link to a forum post that demonstrates using prints to understand behavior and including a link to a video recorded using the Strategy Builder.
    https://ninjatrader.com/support/foru...121#post791121

    Please let me know if I may further assist
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply.

      I have turned on Order Tracing via Strategy Builder and will see what occurs during normal trading hours tomorrow.

      I also see this in the log

      2021-01-26 20:17:52:077|3|4|Strategy 'MACDCROSS/-1': An order placed at '1/4/2021 9:32:00 AM' has been ignored since the order was submitted before the strategy property BarsRequiredToTrade had been met.

      I do find it strange that everything appears to work as expected via Strategy Analyzer when back tested...

      Is it possible to add the prints via Strategy Builder or do I need to unlock and do it in the code?

      If so can you provide some guidance (Example in the actual CODE portion below?

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 1)
      return;

      // Set 1
      if
      // MACD
      (CrossAbove(MACD1.Default, MACD1.Avg, 1))
      {
      EnterLong(Convert.ToInt32(QTY), "");
      }

      // Set 2
      if (CrossBelow(MACD1.Default, MACD1.Avg, 1))
      {
      ExitLong(Convert.ToInt32(QTY), @"", "");
      }

      }


      Thanks!

      Comment


        #4
        Hello jstaft,

        Thank you for that information.

        You should expect that a strategy running real-time (live brokerage account, live market simulation, Playback connection etc...) will produce different results than the performance results generated during a backtest. This difference may be more easily seen on certain Bars types (e.g. Point and Figure or Renko) than others due to their inherent nature in bar formation.

        When using Historical data, Strategies can ONLY be processed at the close of each bar. The fill price of an order is based on the OHLC of a bar and the price of the order itself since that is the only information that is known during a backtest.

        When using real-time market data or Playback you have a choice to run a strategy tick by tick (Calculate set to 'On Each Tick') which could produce different results. The fill price is based on incoming market data and volume, and you may receive better or worse fill prices depending on where the bid or ask price is and what volume is available at this market prices. During real-time live brokerage trading, orders are filled according to market dynamics.

        This is why you may see orders NOT fill in real-time that you may otherwise expect to see filled based on your backtesting results.

        Here is a NinjaTrader Help Guide link with information about discrepancies between realtime and historical data — https://ninjatrader.com/support/help...ime_vs_bac.htm

        Prints are able to be added via the Strategy Builder. Please see the forum post linked in my previous post which includes a link to a video recorded using the Strategy Builder to add prints.

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

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Mindset, 05-06-2023, 09:03 PM
        9 responses
        258 views
        0 likes
        Last Post ender_wiggum  
        Started by Mizzouman1, Today, 07:35 AM
        4 responses
        18 views
        0 likes
        Last Post Mizzouman1  
        Started by philmg, Today, 01:17 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by cre8able, Today, 01:01 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by manitshah915, Today, 12:59 PM
        1 response
        5 views
        0 likes
        Last Post NinjaTrader_Erick  
        Working...
        X