Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

¿how can i check which entries are active - open?

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

    ¿how can i check which entries are active - open?



    people with nt,


    i have been working on a basic strategy with two identical parallel entries. both short entries are opened at the same time, entry_a and entry_b. if entry_b has reached a profit target order and has already been closed i want to know if i can check which entries (entry_a, entry_b) are active - open when a different and general close order will be generated in order to avoid the nt platform from buying too many contracts and ending up with a long position instead of a flat position. ¿is it possible to check for the status of each entry or the status of profit target orders at the time the strategy is about to generate a close position order? if the basic set orders do not have such functionality i could also try with onorder and onexecution methods.


    very well, regards.
    Last edited by rtwave; 02-27-2023, 12:31 PM.

    #2
    Hello rtwave,

    Assign the order to a variable in OnOrderUpdate(). See the example in the help guide.


    Once assigned to a variable, you can check that variable at any time for the order.OrderState property.


    If you want to know if an entry has been exited, compare BarsSinceEntryExecution() with the signalName of the entry to be less than BarsSinceExitExecution() or that BarsSinceExitExecution is equal to -1. This would mean there has not been any exit, or that the order entry has been submitted more recently than the exit.

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3


      people with nt,


      i want to confirm that these lines about barssince entry - exit work great and deliver the intended functionality to check whether any particular entry is still active - open. this is helpful to avoid duplicate positions and erroneous reversals.

      i have found that including these lines will cause all backtest - optimization processes to take 4 times as long to complete so i think i will include this code on strategies to trade with real funds but not necessarily on the strategies that i'm developing or refining.

      Comment


        #4
        Hello rtwave,

        I did a quick test, but I am not seeing any noticeable performance impact from calling these methods.

        Below is a link to a video of the test.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5


          people with nt,



          i work with minute data from 201901 and up to date and these lines will indeed cause the processes i mentioned to take up 4 and 5 times as long to complete.


          i have shared a sample strategy multiple times with nt staff that can be used to corroborate this situation i have described.

          Comment


            #6
            Hello rtwave,

            Are you inquiring on another case you have open?

            Do you have case number?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7



              people with nt,



              this below is the strategy i have posted multiple time to help nt staff corroborate platform malfunctions i have found and reported.


              if an optimization process is ran with the settings i have shared several times that should take around 60 minutes. however, if the barssinceentry - exit lines are added to the exit commands then the same processes will take 4 to 5 times as long.



              i share the sample strategy once again:



              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 tesampletrimod : Strategy
                  {
                      private SMA SMA1;
                      private Momentum Momentum1;
                      private ADX ADX1;
              
                      protected override void OnStateChange()
                      {
                          if (State == State.SetDefaults)
                          {
                              Description                                    = @"te sample tri mod.";
                              Name                                        = "tesampletrimod";
                              Calculate                                    = Calculate.OnBarClose;
                              EntriesPerDirection                            = 1;
                              EntryHandling                                = EntryHandling.UniqueEntries;
                              IsExitOnSessionCloseStrategy                = false;
                              ExitOnSessionCloseSeconds                    = 90;
                              IsFillLimitOnTouch                            = false;
                              MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                              OrderFillResolution                            = OrderFillResolution.Standard;
                              Slippage                                    = 25;
                              StartBehavior                                = StartBehavior.WaitUntilFlat;
                              TimeInForce                                    = TimeInForce.Gtc;
                              TraceOrders                                    = true;
                              RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelCloseIgnoreRejects;
                              StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                              BarsRequiredToTrade                            = 65;
                              // Disable this property for performance gains in Strategy Analyzer optimizations
                              // See the Help Guide for additional information
                              IsInstantiatedOnEachOptimizationIteration    = true;
                              Posi                    = 1;
                              Smap                    = 20;
                              Momp                    = 20;
                              Adxp                    = 20;
                              Moml1                    = -.5;
                              Moml2                    = .5;
                              Adxl                    = 30;
                          }
                          else if (State == State.Configure)
                          {
                          }
                          else if (State == State.DataLoaded)
                          {                
                              SMA1                    = SMA(Close, Convert.ToInt32(Smap));
                              Momentum1                = Momentum(Close, Convert.ToInt32(Momp));
                              ADX1                    = ADX(Close, Convert.ToInt32(Adxp));
                          }
                      }
              
                      protected override void OnBarUpdate()
                      {
                          if (BarsInProgress != 0)
                              return;
              
                          if (CurrentBars[0] < 1)
                              return;
              
                           // Set 1
                          if ((Position.MarketPosition != MarketPosition.Short)
                               && (SMA1[0] < SMA1[1])
                               && (Momentum1[0] < Moml1)
                               && (ADX1[0] > Adxp))
                          {
                              EnterShort(Convert.ToInt32(Posi), @"sp01");
                          }
              
              
                          else
              
              
                              // Set 4
                              if ((Position.MarketPosition == MarketPosition.Long)
                              && (SMA1[0] < SMA1[1]))
                              {
                              ExitLong(Convert.ToInt32(Posi), @"elp01", @"lp01");
                              }
              
              
                           // Set 3
                          if ((Position.MarketPosition != MarketPosition.Long)
                               && (SMA1[0] > SMA1[1])
                               && (Momentum1[0] > Moml2)
                               && (ADX1[0] > Adxp))
                          {
                              EnterLong(Convert.ToInt32(Posi), @"lp01");
                          }
              
              
                          else
              
              
                              // Set 2
                              if ((Position.MarketPosition == MarketPosition.Short)
                              && (SMA1[0] > SMA1[1]))
                              {
                              ExitShort(Convert.ToInt32(Posi), @"esp01", @"sp01");
                              }
              
              
                      }
              
                      #region Properties
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Posi", Description="posi.", Order=1, GroupName="Parameters")]
                      public int Posi
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Smap", Order=2, GroupName="Parameters")]
                      public int Smap
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Momp", Order=3, GroupName="Parameters")]
                      public int Momp
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [Range(1, int.MaxValue)]
                      [Display(Name="Adxp", Order=4, GroupName="Parameters")]
                      public int Adxp
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [Range(double.MinValue, double.MaxValue)]
                      [Display(Name="Moml1", Order=5, GroupName="Parameters")]
                      public double Moml1
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [Range(double.MinValue, double.MaxValue)]
                      [Display(Name="Moml2", Order=6, GroupName="Parameters")]
                      public double Moml2
                      { get; set; }
              
                      [NinjaScriptProperty]
                      [Range(1, double.MaxValue)]
                      [Display(Name="Adxl", Order=7, GroupName="Parameters")]
                      public double Adxl
                      { get; set; }
                      #endregion
              
                  }
              }
              
              ​

              Comment


                #8
                Hello rtwave,

                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


                The code you have posted does not call BarsSinceEntryExecution() or BarsSinceExitExecution() that I can see.

                "if the barssinceentry - exit lines are added to the exit commands then the same processes will take 4 to 5 times as long."

                This change in logic would change when orders are exiting and entering which can change the amount of trades which would result in a different performance.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                48 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                126 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                66 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                42 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                46 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X