• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


The first trade of the strategy is not accounted for in the account

  • Filter
  • Time
  • Show
Clear All
new posts


    There are multiple ways to go about this as it will be highly dependent on the rest of your logic. I do not immediately see any errors when looking at either of your samples.

    I am looking forward to reviewing your database. You can send it to me by going to the Control Center-> Help-> Mail to Platform Support.

    Ensure to check 'Database file' under 'Other files'. Please reference the following ticket number in the body of the email: 2116810

    JoshNinjaTrader Customer Service



      Good Morning, I have already sent you the information you requested through the platform. Has it arrived correctly? Secondly, to simplify and test the sessionIterator, I have designed a simple strategy, what it does is go into the first bar of the session and I only ask you to close positions 3 hours before the end of the session. Below I send you the strategy, so that you can correct it, since it does not work. What the strategy does is close positions in each bar, always, regardless of the schedule. I hope you can review it and find the flaw to help me please.
      #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;

      //This namespace holds Strategies in this folder and is required. Do not change it.
      namespace NinjaTrader.NinjaScript.Strategies
      public class PruebaITERATOR : Strategy

      private SessionIterator sessionIterator;

      protected override void OnStateChange()
      if (State == State.SetDefaults)
      Description = @"Escriba la descripción de su nuevo cliente Estrategia aquí.";
      Name = "PruebaITERATOR";
      Calculate = Calculate.OnEachTick;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.AllEntries;
      IsExitOnSessionCloseStrategy = false;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.High;
      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)

      if (State == State.DataLoaded)
      //stores the sessions once bars are ready, but before OnBarUpdate is called
      sessionIterator = new SessionIterator(Bars);


      protected override void OnBarUpdate()


      if (BarsInProgress != 0)

      if (CurrentBars[0] < 1)

      // Establecer 1
      if (Bars.IsFirstBarOfSession == true)
      EnterLong(Convert.ToInt32(DefaultQuantity), "");

      if (DateTime.Now >= sessionIterator.GetTradingDayEndLocal(sessionItera tor.ActualTradingDayExchange).AddHours(-3))

      ExitLong("Cierredeldia", "");
      ExitShort("Cierredeldia", "");
      Draw.VerticalLine(this, CurrentBars[0].ToString() + @" Línea vertical_1", 0, Brushes.White, DashStyleHelper.Solid, 1);




        I have not yet received your database through email.

        The issue with your snippet is going to be your own custom logic. You will need to debug and test your strategy on your end for it to work as you expect.

        I suggest adding Print() statements with time stamps so that you can see when your order methods are being reached. This will help you to tweak your conditons until they produce what you want. Please see the following link for more information on debugging your NinjaScript: https://ninjatrader.com/support/help...script_cod.htm

        One thing that could be causing you an issue is how you have your time filter set up. It does not looks like it is actually filtering anything. Please see the following reference sample for how to create a time filter: https://ninjatrader.com/support/help...to_limit_t.htm
        JoshNinjaTrader Customer Service


          Good Morning,

          regarding the sessionInterator, in this particular example that happened to him, it is clear that the problem is not about my strategy, nor is it due to any problem in any time filter. Actually, this is the operation of the SessionInterator indicator, which does not work as it should.
          It's a super simple strategy, which I think you should control.
          Just enter long in the first bar of the session and only ask you to close a certain time before the end of the session.

          I followed the steps of the help guide.

          I only ask you to tell me how to program it or correct the error in the programming that I have asked you to close positions 3 hours before the end of the session. The indicator itself should do it.

          Would it be possible to revise it or make an example that works well, please?
          I think it's not asking too much.
          I appreciate your cooperation.
          Greetings and thank you.



            It sounds like you have not followed my previous advice of adding Print() statements to see why this behavior is occurring. The SessionIterator is working as expected from what I am seeing on my end. Ultimately, debugging steps will need to be taken by you to observe the strategy logic as it is executing.

            I assure you that if you are not getting the results you desire it is because of the custom logic that you have written for this strategy.

            As I mentioned, I recommend adding debugging prints to your strategy. By adding prints for the values used to evaluate your conditions outside of those conditions, you can observe what logic is becoming true and allowing your order methods(and vertical line) to fire.

            Perhaps consider using ToTime(Time[0]) to simplify your time filter conditions similar to how they have done in the 'Time filter' sample I provided from the help guide. Something like the following snippet:

            if (ToTime(Time[0]) >= ToTime(sessionIterator.GetTradingDayEndLocal(sessionIterator.ActualTradingDayExchange).AddHours(-3)))
            JoshNinjaTrader Customer Service


            Latest Posts


            Topics Statistics Last Post
            Started by digibob, Today, 02:47 AM
            0 responses
            1 view
            Last Post digibob
            by digibob
            Started by NinjaCustomer, Today, 12:57 AM
            1 response
            Last Post NinjaCustomer  
            Started by lancasterstephen, Today, 12:09 AM
            1 response
            Last Post lancasterstephen  
            Started by liltr3d, Yesterday, 10:52 PM
            0 responses
            Last Post liltr3d
            by liltr3d
            Started by Longhornmark, Yesterday, 08:25 AM
            3 responses
            Last Post bltdavid