Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

bactesting vs historical (strategy performance)

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

    #16
    Hi thank you for the quick response,

    During backtesting: I enabled Tick Replay and the script contain OnEachTick as you can see from the attached screen, is ok? or I have to switch in OnPriceChange?

    About SetStopLoss and SetProfit I will change into Exit orders since they allow 1-tick intra-bar granularity

    Thank you I will try with this and then I will get back to you
    Attached Files

    Comment


      #17
      Hello luketrades,

      If you change a property set in State.Defaults you would need to remove the strategy from the chart Configured list, or the strategies tab of the control center, and add a new instance from the Available list.

      On the Strategy Analyzer, this is not necessary and will update after a compile for the next backtest.

      OnEachTick would be fine to use if you need the logic to update on each tick. Typically if volume is not being used, the OnPriceChange setting is less CPU demanding.

      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Hi, I just need to check the backtesting right now. However, when using false as a parameter, it doesn’t show me any trades.

        Since this is an order flow strategy, I have to use OnEachTick.

        I used ExitOrder (and for those methods, I understand I need to use true as a parameter because SL and TP orders must remain active until they are filled). My question is: could the reason why backtesting doesn’t show any trades be related to the true parameter on SL or TP orders? Specifically, does it cause the SL to remain active even if the profit is hit, or the opposite?

        How should I handle these situations?
        Attached Files

        Comment


          #19
          Hello luketrades,

          Is TraceOrders showing the orders are being submitted?
          Is TraceOrders showing the orders are being automatically cancelled?

          Have your printed the order.ToString() in OnOrderUpdate() as directed and are you seeing the entry order fill?

          "could the reason why backtesting doesn’t show any trades be related to the true parameter on SL or TP orders?"

          If there are 0 trades, likely no entry order was filled.

          "Specifically, does it cause the SL to remain active even if the profit is hit, or the opposite?"

          When using the managed approach, exit orders submitted with the From entry signal of the Signal name of a specific entry will automatically cancel if the position is closed by another order.
          Note, this is not OCO, but instead the managed approach managing the position.

          Below is a link to examples of using exit orders or using the unmanaged approach with OCO for exit orders.

          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            I didn't put into the code TraceOrder function, do I have to? for debugging?

            then..

            "Have your printed the order.ToString() in OnOrderUpdate() as directed and are you seeing the entry order fill?​"

            No

            Anyway by checking log in the backtesting there are not any trades​

            Comment


              #21
              Hello luketrades,

              Please see post # 8 and follow the directions.

              TraceOrders shows when orders are being submitted, ignored, rejected, or automatically cancelled.

              Printing the order.ToString() shows when orders are being submitted, accepted, working, filled, rejected, or cancelled.

              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 or rejected.

              You will need to debug to understand what is occurring and why.

              You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                I will try with TraceOrder and the other things you suggested to me, but to be sure send me the list please, and how I can contact them

                Comment


                  #23
                  Hello luketrades,

                  You can search our extensive library of NinjaScript consultants through the link below. Simply enter a consultant name or search by using our filter categories. Once you have identified your consultants of choice, please visit each consultant's site for more information or contact them directly to learn more!
                  Programming Services - https://ninjatraderecosystem.com/sea...mming-services
                  Educators - https://ninjatraderecosystem.com/sea...ures=education

                  You can locate the contact information for the consultants on their direct websites for any additional questions you may have. Since these consultants are third party services for NinjaTrader all pricing and support information will need to be obtained through the consultant.

                  This NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The companies and services listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.

                  You will need to travel to each vendors website to find how they want to be contacted.

                  Please let me know if you have any questions, or if I can provide any further assistance.​
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Hi Chelsea B.

                    Before I spend a lot of money I want to try to solve the problem myself.

                    I have studied many posts on this topic, I found your video-explanation with EMA sample code for intra-bar granularity.

                    I took this sample code: sampleintrabarbacktestNT8

                    I just removed the EMAs and added some components of my strategy that I oversimplified to test.

                    This is the script:​

                    Code:
                    [HASHTAG="t3322"]region[/HASHTAG] Using declarations
                    using System;
                    using System.Collections.Generic;
                    using System.ComponentModel;
                    using System.ComponentModel.DataAnnotations;
                    using System.Linq;
                    using System.Text;
                    using System.Threading.Tasks;
                    using System.Windows;
                    using System.Windows.Input;
                    using System.Windows.Media;
                    using System.Xml.Serialization;
                    using NinjaTrader.Cbi;
                    using NinjaTrader.Gui;
                    using NinjaTrader.Gui.Chart;
                    using NinjaTrader.Gui.SuperDom;
                    using NinjaTrader.Gui.Tools;
                    using NinjaTrader.Data;
                    using NinjaTrader.NinjaScript;
                    using NinjaTrader.Core.FloatingPoint;
                    using NinjaTrader.NinjaScript.Indicators;
                    using NinjaTrader.NinjaScript.DrawingTools;
                    using NinjaTrader.NinjaScript.BarsTypes;
                    #endregion
                    
                    // This namespace holds all strategies and is required. Do not change it.
                    namespace NinjaTrader.NinjaScript.Strategies
                    {
                    public class InitiativeAuction : Strategy
                    {
                    private VolumetricBarsType volumetricBarsType;
                    private double prevPOC = 0;
                    
                    [NinjaScriptProperty]
                    [Display(Name = "Delta Threshold", GroupName = "Auction Candle Parametes", Order =1)]
                    public double deltaThreshold { get; set; } = 6.0;
                    
                    
                    [NinjaScriptProperty]
                    [Display(Name = "Risk Reward Ratio", GroupName = "Risk Management", Order =1)]
                    public double riskRewardRatio { get; set; } = 0.5;
                    
                    [NinjaScriptProperty]
                    [Display(Name = "Initial balance", GroupName = "Risk Management", Order =1)]
                    public double initialBalance { get; set; } = 50000.0;
                    
                    
                    
                    protected override void OnStateChange()
                    {
                    if(State == State.SetDefaults)
                    {
                    
                    Calculate = Calculate.OnEachTick;
                    Name = "Initiative Auction";
                    IsOverlay = true;
                    }
                    
                    else if(State == State.Configure)
                    {
                    AddDataSeries(Data.BarsPeriodType.Tick, 1);
                    }
                    else if (State == State.Configure)
                    {
                    volumetricBarsType = Bars.BarsSeries.BarsType as VolumetricBarsType;
                    }
                    
                    }
                    
                    protected override void OnBarUpdate()
                    {
                    
                    if (BarsInProgress == 0)
                    {
                    var closedVolbar = volumetricBarsType.Volumes[CurrentBar - 1]; //@ Call the last bar
                    double deltaPercent = closedVolbar.GetDeltaPercent(); //@ Get Delta Percent of the last bar
                    
                    double pocPrice;
                    closedVolbar.GetMaximumVolume(null, out pocPrice);
                    
                    bool isBullishCandle = Close[1] > Open[1];
                    bool isBearishCandle = Close[1] < Open[1];
                    
                    
                    
                    // When the fast EMA crosses above the slow EMA, enter long on the secondary (1min) bar series
                    if (Math.Abs(deltaPercent) >= deltaThreshold && isBullishCandle)
                    {
                    EnterLong(1, "Long Entry");
                    }
                    
                    else if (Math.Abs(deltaPercent) >= deltaThreshold && isBearishCandle)
                    {
                    EnterShort(1, "Entry Short");
                    }
                    
                    }
                    }
                    }
                    }
                    ​
                    The problem is that even though I simplified the code with ultra basic conditions, the backtesting does not show me any trades.

                    TraceOrders and Print for debugging in this case are not needed because the basic problem is that backtesting shows nothing anyway.

                    I simplified the code, starting with the example code I found on this forum hoping it would work but nothing.

                    Since the code is more simplified could I know what is wrong? It is the same as what I also found in the documentation you sent me a few posts ago, why backtesting continue to not show me trades?

                    I used TickReplay, used Volumetric Bars, i don't really know what to do.. this should not be complex..

                    ​​
                    Attached Files

                    Comment


                      #25
                      I tested without order flow and seems to work the backtesting.. so the problem is in my Order Flow conditions.. I removed from the basic example code everything about order flow and now the backtesting work properly.. so what I have to do now?

                      Comment


                        #26
                        Hello luketrades,

                        Are you referring to the SampleIntrabarBacktest_NT8 found here?:
                        Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


                        This reference sample strategy does not use any order flow bar types or indicators and only calls the EMA indicator.

                        I've tested this original script and I am finding it places orders without any issue testing on the ES 03-25 1 Minute.

                        If you have found a script that uses order flow, this would not be the original SampleIntrabarBacktest_NT8 script available from the documentation.


                        Regarding order flow, is your user enabled for order flow in the Account Portal?

                        Can you put the Order Flow Volumetric bars on a chart and see making changes?

                        Are there errors appearing on the Log tab of the Control Center?

                        Below is a link to the documentation on how to use Volumetric bars in a script.
                        Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.


                        Attached is a simple example that implements the sample code in the documentation.
                        Attached Files
                        Chelsea B.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by NullPointStrategies, Yesterday, 05:17 AM
                        0 responses
                        54 views
                        0 likes
                        Last Post NullPointStrategies  
                        Started by argusthome, 03-08-2026, 10:06 AM
                        0 responses
                        130 views
                        0 likes
                        Last Post argusthome  
                        Started by NabilKhattabi, 03-06-2026, 11:18 AM
                        0 responses
                        72 views
                        0 likes
                        Last Post NabilKhattabi  
                        Started by Deep42, 03-06-2026, 12:28 AM
                        0 responses
                        44 views
                        0 likes
                        Last Post Deep42
                        by Deep42
                         
                        Started by TheRealMorford, 03-05-2026, 06:15 PM
                        0 responses
                        49 views
                        0 likes
                        Last Post TheRealMorford  
                        Working...
                        X