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

OnBarUpdate() method not running when backtesting strategy.

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

    OnBarUpdate() method not running when backtesting strategy.

    Hi, I am new to Ninja Trader, and have been developing a new bot to run on a Virtual Machine. After developing the bot on my local PC, I moved that bot to the virtual machine by creating a new strategy and essentially pasting the code I had within the OnBarUpdate, OnStateChange, and OnOrderUpdate methods. I made sure I didn't paste over any needed defaults set when creating a new strategy.

    Ultimately what is happening when I debug the bot through the virtual machine is that it runs the OnStateChange method, but never runs the OnBarUpdate method. The weird thing is that it runs everything fine when running it on my local PC. Also I should mention if I create a new test strategy in the VM any breakpoint I set in the OnBarUpdate method doesn't get hit either. Breakpoints do get hit inside the OnStateChange method.

    I would imagine there shouldn't be any difference between running a strategy on a local machine and a VM, but if it makes a difference I am using an Azure Windows (Windows 10 Pro) VM.

    The connections I am using for local development and VM development are the same as well. I am using the 'Kinetick - END OF DAY' connection for the backtests.

    Here is the code I am running for OnStateChange and OnBarUpdate. What I have seems pretty standard, but I might as well share it.

    Code:
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"FIve minute one minute micro e mini strategy.";
    Name = "T1V1S1V1FU";
    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)
    {
    AddDataSeries("MNQ 03-22", BarsPeriodType.Minute, 1, MarketDataType.Last);
    AddDataSeries("MNQ 03-22", BarsPeriodType.Minute, 5, MarketDataType.Last);
    PortfolioAmount = Account.Get(AccountItem.CashValue, Currency.UsDollar);
    }
    }
    Code:
    protected override void OnBarUpdate()
    {
    //Don't want to share all my code within OnBarUpdate.
    }


    Maybe I'm missing something obvious here, but I am currently kind of stumped on this one.

    Any help would be greatly appreciated!

    Thanks,

    -Parker

    #2
    Hello plwieseler,

    Welcome to the NinjaTrader forums!

    You may want to export the script from the first machine, transfer the export .zip file to the new machine, and import the export file on the second machine to ensure the code is exactly the same.

    To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
    1. Click Tools -> Export -> NinjaScript...
    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

    To import a NinjaScript into NinjaTrader 8 do the following:
    1. Download the script to your desktop, keep it in the compressed .zip file.
    2. From the Control Center window select Tools -> Import -> NinjaScript...
    3. Click the Desktop icon on the left to navigate to the desktop
    4. Select the downloaded .zip file -> then click Open
    5. NinjaTrader will then confirm if the import has been successful.
    Critical *Note that on any files that say "File already exists on your PC" that start with an "@" symbol are the ones that came preloaded inside of NinjaTrader so you would say "No" so that you do not override those files.

    Below is a link to the help guide on importing.
    https://ninjatrader.com/support/help...-us/import.htm


    Regarding the script, are there errors appearing on the Log tab of the Control Center?

    Is there data appearing on the chart?
    (note, Kinetick end of Day is historical Day bars only, this does not include minute or tick historical data or real-time data)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi, thanks for the tips! I appreciate it.

      After further research I found that using the Kinetick connection doesn't work for new strategies I create using the one minute bars on both my PC and VM. However, somehow it does work only for MNQ 3-22 in back testing on my initial strategy. I believe there must be some sort of data I have downloaded or configured somewhere in that specific strategy that allows it to run (I'm still getting acquainted with using NT8, so I don't know why that would be).

      Understanding now that Kinetick is historical day bars only is probably the reason why OnBarUpdate isn't running. The solution would probably be running with a different connection.

      Thanks again,

      -Parker

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Jonker, Today, 01:19 PM
      0 responses
      1 view
      0 likes
      Last Post Jonker
      by Jonker
       
      Started by futtrader, Today, 01:16 PM
      0 responses
      5 views
      0 likes
      Last Post futtrader  
      Started by Segwin, 05-07-2018, 02:15 PM
      14 responses
      1,791 views
      0 likes
      Last Post aligator  
      Started by Jimmyk, 01-26-2018, 05:19 AM
      6 responses
      844 views
      0 likes
      Last Post emuns
      by emuns
       
      Started by jxs_xrj, 01-12-2020, 09:49 AM
      6 responses
      3,296 views
      1 like
      Last Post jgualdronc  
      Working...
      X