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 analyzer issus

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

    strategy analyzer issus

    Hi there,

    I have a custom strategy and I try to test it in strategy analyzer, but it only exit trades when session closed, same situation for the previous entry and exit when I enable the strategy on the chart, but it works well when I run it in playback, it exit trades when hits stoploss or profit target, I attached few screenshot so you can see. Could you pls assist me to fix this issues, thanks!

    #2
    Hello Jy666,

    Thank you for your post.

    Please review the help guide page on the differences on real-time vs backtest.



    Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics. Instead these are filled based on logical rules from processing historical data.
    • When in historical data, only the Open, High, Low, and Close will be available and there will be no intra-bar data.
      • This means actions cannot happen intra-bar, fills cannot happen intra-bar. All prices and actions come from and occur when the bar closes as this is all the information that is known
      • Because of this, OnBarUpdate will only update 'On bar close' as it does not have the intra-bar information necessary for 'On price change' or 'On each tick' and the script will not have the intra-bar information to accurately fill an order at the exact price and time.
    Intra-bar granularity adds a second data series such as a 1 tick series using AddDataSeries() so that the strategy or indicator has the individual ticks in the historical data in between the High and Low of the primary series.
    In NinjaTrader 8, there have been two new enhancements so that programmers may not have to manually add this secondary series and code the script for high accuracy fills (Order Fill Resolution) or for intra-bar actions (TickReplay) depending on the needs of the script.
    Note: bar types that are IsRemoveLastBarSupported cannot be used with TickReplay and generally cause inaccurate results when backtesting in historical data.
    Note: High Order Fill Resolution allows for intra-bar order fills with historical processing, but is not compatible with Tick Replay.


    Please see this forum post for a detailed explanation:

    https://forum.ninjatrader.com/forum/...-backtest-live​​
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      Thanks Gaby,

      another question, because my indicator is base on two instruments, how to add Intra-bar granularity for both instruments for a same timeframe?

      Comment


        #4
        Hello Jw666,

        I'm not clear on what you are asking. Do you mean your strategy is based on two instruments?

        This sample script demonstrates adding intrabar granularity to your script:



        You can add a single tick data series for both instruments via AddDataSeries() and submit the orders to that series.

        Please let us know if you have any further questions.
        Gaby V.NinjaTrader Customer Service

        Comment


          #5
          Hi Gaby,

          Yes, my indicator is based on two instruments, it works well without Intra-bar granularity, it prints values correct, but once I try to get Intra-bar granularity, the indicator can’t work properly.

          Comment


            #6
            Hello Jy666,

            Why are you looking to implement intrabar granularity for an indicator?

            Typically intrabar granularity is used for strategies to have more accurate fills in backtesting.
            Gaby V.NinjaTrader Customer Service

            Comment


              #7
              The indicator is for a strategy, or I don’t have to implement Intra-bar granularity for the indicator, only implement for the strategy using this indicator will works for back testing in strategy analyzer?

              Comment


                #8
                Hello,

                No, it's not necessary for the indicator as well. You only need to implement intrabar granularity in your strategy for accurate fill times and prices.

                You can only backtest strategies in the Strategy Analyzer, not indicators.

                Please let us know if you have any further questions.
                Gaby V.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Gaby,

                  I have checked the sample Multi Instrument code:

                  else if (State == State.Configure)
                  {
                  // Add an MSFT 1 minute Bars object to the strategy
                  AddDataSeries("MSFT", Data.BarsPeriodType.Minute, 1);
                  }

                  If I wanna implement Intra-bar granularity, could you tell me how to do that?

                  Comment


                    #10
                    Hello Jy666,

                    I recommend taking a look at this sample script as it would be very helpful, it demonstrates how you can implement intrabar granularity in your strategy.



                    Please let us know if you have any further questions.
                    Gaby V.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Gaby, I think I have no issue for the implement Intra-bar granularity, but still the strategy runs good in play back, but in strategy analyzer still never exit until session closed. that is only one issue for now. my code is : AddDataSeries(Leg1, BarsPeriodType.Minute, timeframe);// Leg1 BarsInProgress 1
                      AddDataSeries(Leg2, BarsPeriodType.Minute, timeframe);// Leg2 BarsInProgress 2​

                      Comment


                        #12
                        Hello,

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

                        To understand why the script is behaving as it is, such as placing orders or not placing orders 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 date time of the bar and all values compared in every condition that places an order.

                        The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very important to include a text label for each value and for each comparison operator in the print to understand what is being compared in the condition sets.

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

                        Further, 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.

                        I am happy to assist you with analyzing the output from the output window.

                        Run or backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

                        Below is a link to a forum post that demonstrates using informative prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.


                        Please let me know if I may further assist with analyzing the output or if you need any assistance creating a print or enabling TraceOrders.​
                        Gaby V.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by NM_eFe, Today, 06:14 AM
                        0 responses
                        1 view
                        0 likes
                        Last Post NM_eFe
                        by NM_eFe
                         
                        Started by sgordet, Today, 06:04 AM
                        0 responses
                        4 views
                        0 likes
                        Last Post sgordet
                        by sgordet
                         
                        Started by bc24fl, 08-30-2019, 01:58 PM
                        4 responses
                        260 views
                        0 likes
                        Last Post PaulMohn  
                        Started by sugalt, Today, 04:02 AM
                        0 responses
                        7 views
                        0 likes
                        Last Post sugalt
                        by sugalt
                         
                        Started by tradingnasdaqprueba, 04-09-2024, 09:52 AM
                        6 responses
                        30 views
                        0 likes
                        Last Post tradingnasdaqprueba  
                        Working...
                        X