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

beginner question - trying to backtest on a chart

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

    beginner question - trying to backtest on a chart

    Hello,

    I have been trying to figure out how to backtest on a chart- how to view where entries and exits would be. I thought I could load a strategy into a chart in NinjaTrader and it would display all entries and exits that would have happened previously. The strategy performance window also doesn't show any trades.

    I used strategy builder to try to create a simple reason to enter a long position: 2 consecutive bars with lower lows. Any advice would be greatly appreciated!

    Thanks.



    Code:
    #region 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;
    #endregion
    
    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class pm936 : Strategy
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                        = @"Enter the description for your new custom Strategy here.";
                    Name                            = "pm936";
                    Calculate                        = Calculate.OnBarClose;
                    EntriesPerDirection                    = 1;
                    EntryHandling                        = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy                = true;
                    ExitOnSessionCloseSeconds                = 30;
                    IsFillLimitOnTouch                    = false;
                    MaximumBarsLookBack                    = MaximumBarsLookBack.TwoHundredFiftySix;
                    OrderFillResolution                    = OrderFillResolution.Standard;
                    Slippage                        = 0;
                    StartBehavior                        = StartBehavior.WaitUntilFlat;
                    TimeInForce                        = TimeInForce.Gtc;
                    TraceOrders                        = false;
                    RealtimeErrorHandling                    = RealtimeErrorHandling.StopCancelClose;
                    StopTargetHandling                    = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade                    = 20;
                    // Disable this property for performance gains in Strategy Analyzer optimizations
                    // See the Help Guide for additional information
                    IsInstantiatedOnEachOptimizationIteration        = true;
                }
                else if (State == State.Configure)
                {
                    SetStopLoss(@"", CalculationMode.Price, (Low[1] - 2) , false);
                    SetProfitTarget("", CalculationMode.Ticks, 10);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (BarsInProgress != 0)
                    return;
    
                if (CurrentBars[0] < 2)
                    return;
    
                 // Set 1
                if ((Low[2] > Low[1])
                     && (Low[1] < Low[0]))
                {
                    Draw.ArrowUp(this, @"pm936 Arrow up_1", false, 0, 0, Brushes.Lime);
                    EnterLong(Convert.ToInt32(DefaultQuantity), @"lower lows");
                }
    
            }
        }
    }
    ​
    Attached Files

    #2
    Hello Stormin87,

    When enabling a strategy on a chart, this will show historical orders, the same as a backtest.

    Are you certain the strategy is enabled, with the Enabled checkbox checked on the Strategies tab of the Control Center?

    What color is the name of the strategy on the Strategies tab of the Control Center?

    Below is a link to a video of enabling a strategy.
    https://www.youtube.com/watch?v=VxU4...XkWe0Nf&t=3655

    If the strategy is enabled and no orders were placed, this would mean the condition to submit the order did not evaluate as true.

    It will be necessary to add prints and debug the script to understand why.

    In order to better understand how the code is working, it will be necessary to use Print to see how the conditions are evaluating and enable TraceOrders to see if orders are being submitted, ignored, rejected, or cancelled.

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

    Enable TraceOrders, print the time of the bar and all values used in the conditions that submit entry orders. Include labels for all values and comparison operators.

    Let me know if you need any assistance creating a print or enabling TraceOrders.

    Save the output from the output window to a text file and provide this with your reply.

    I'll be happy to assist with analyzing the output.​


    As a tip, to export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript Add-on...
    2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
    3. Click the 'Export' button
    4. Enter a unique name for the file in the value for 'File name:'
    5. Choose a save location -> click Save
    6. Click OK to clear the export location message
    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<export_file_name.zip>
    Below is a link to the help guide on Exporting NinjaScripts.
    http://ninjatrader.com/support/helpG...-us/export.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the reply. It appears that I just didn't have "plot executions" enabled...

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Balage0922, Today, 07:38 AM
      0 responses
      1 view
      0 likes
      Last Post Balage0922  
      Started by JoMoon2024, Today, 06:56 AM
      0 responses
      6 views
      0 likes
      Last Post JoMoon2024  
      Started by Haiasi, 04-25-2024, 06:53 PM
      2 responses
      19 views
      0 likes
      Last Post Massinisa  
      Started by Creamers, Today, 05:32 AM
      0 responses
      6 views
      0 likes
      Last Post Creamers  
      Started by Segwin, 05-07-2018, 02:15 PM
      12 responses
      1,786 views
      0 likes
      Last Post Leafcutter  
      Working...
      X