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

Multi Time Frame - Daily chart Exit on Close problem

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

    Multi Time Frame - Daily chart Exit on Close problem

    Hello,

    I just can't seem to make sense out of it. On Multi Time Frames the strategies work fine when using 5 min as primary and 1 min as secondary. I can buy and sell through the 5 and 1 min BIP without a problem.

    However, when I switch to the daily chart, 'Exit on Close' occurs a day before the Long Entry.

    I tested the SampleMultiTimeFrame strategy and it has the same behavior on the daily NQ 09-20 chart. I am trying and researching but can't find what is the reason for this behavior. Screen shot is enclosed.

    Thank you.

    #2
    Hello remorim,

    Thanks for the post.

    I just wanted to let you know I am taking a look into this and will provide an update here once I have tested this further.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      What are the timestamps for the trade entry & trade exit in the Strategy Performance?
      Last edited by bltdavid; 07-29-2020, 12:58 PM.

      Comment


        #4
        Hello,

        Details from Strategy Performance:
        Code:
        1    NQ 09-20    Sim101    SampleMultiTimeFrameDebug    Short    1000    7714.25    7818.75    6/19/2019 5:00:00 PM    6/20/2019 5:00:00 PM    Exit on close    SMA    -0.0135463590109213    -0.0135463590109214    0    0.0135463590109213    0    0    2
        Details from OnExecution():
        Code:
        **NT** Disabling NinjaScript strategy 'SampleMultiTimeFrameDebug/9a9215109c9f48f78df277cad53d3896'
        **NT** Enabling NinjaScript strategy 'SampleMultiTimeFrameDebug/9a9215109c9f48f78df277cad53d3896' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes
        Order Name: SMA
        1000
        Execution='NT-00000' Instrument='NQ 09-20' Account='Sim101' Name='SMA' Exchange=Default Price=7818.75 Quantity=1,000 Market position=Long Commission=0 Order='NT-00000' Time='6/20/2019 5:00:00 PM'
        ------------------------------------------------------------------------------
        Order Name: Exit on close
        1000
        Execution='NT-00001' Instrument='NQ 09-20' Account='Sim101' Name='Exit on close' Exchange=Default Price=7714.25 Quantity=1,000 Market position=Short Commission=0 Order='NT-00001' Time='6/19/2019 5:00:00 PM'
        ------------------------------------------------------------------------------
        Again same behavior, Exit on Close appears 1 day before Entry on the daily chart.

        This is the standard @SampleMultiTimeFrame below. I've only added OnExecution() and made no other changes.
        You can run it on NQ 09-20 Daily chart and set 'Days to load' to 500 to capture at least 1 trade.
        Code:
        // 
        // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
        // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
        //
        
        #region Using declarations
        using System;
        using System.ComponentModel;
        using System.Diagnostics;
        using System.Drawing;
        using System.Drawing.Drawing2D;
        using System.Xml.Serialization;
        using NinjaTrader.Cbi;
        using NinjaTrader.Data;
        using NinjaTrader.Indicator;
        using NinjaTrader.Strategy;
        #endregion
        
        
        // This namespace holds all strategies and is required. Do not change it.
        namespace NinjaTrader.Strategy
        {
            /// <summary>
            /// This is a sample multi-time frame strategy.
            /// </summary>
            [Description("This is a sample multi-time frame strategy.")]
            public class SampleMultiTimeFrameDebug : Strategy
            {
                #region Variables
                // Wizard generated variables
                // User defined variables (add any user defined variables below)
                #endregion
        
                /// <summary>
                /// This method is used to configure the strategy and is called once before any strategy method is called.
                /// </summary>
                protected override void Initialize()
                {
                    // Add a 5 minute Bars object to the strategy
                    Add(PeriodType.Minute, 5);
        
                    // Add a 15 minute Bars object to the strategy
                    Add(PeriodType.Minute, 15);
        
                    // Note: Bars are added to the BarsArray and can be accessed via an index value
                    // E.G. BarsArray[1] ---> Accesses the 5 minute Bars object added above
        
                    // Add simple moving averages to the chart for display
                    // This only displays the SMA's for the primary Bars object on the chart
                    Add(SMA(5));
                    Add(SMA(50));
        
                    CalculateOnBarClose = true;
                }
        
                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
                    // OnBarUpdate() will be called on incoming tick events on all Bars objects added to the strategy
                    // We only want to process events on our primary Bars object (index = 0) which is set when adding
                    // the strategy to a chart
                    if (BarsInProgress != 0)
                        return;
        
                    // Checks  if the 5 period SMA is above the 50 period SMA on both the 5 and 15 minute time frames
                    if (SMA(BarsArray[1], 5)[0] > SMA(BarsArray[1], 50)[0] && SMA(BarsArray[2], 5)[0] > SMA(BarsArray[2], 50)[0])
                    {
                        // Checks for a cross above condition of the 5 and 50 period SMA on the primary Bars object and enters long
                        if (CrossAbove(SMA(5), SMA(50), 1))
                            EnterLong(1000, "SMA");
                    }
        
                    // Checks for a cross below condition of the 5 and 15 period SMA on the 15 minute time frame and exits long
                    if (CrossBelow(SMA(BarsArray[2], 5), SMA(BarsArray[2], 50), 1))
                        ExitLong(1000);
                }
        
                protected override void OnExecution(IExecution execution)
                {
        
                    Print("Order Name: " +execution.Name);
                    Print(execution.Quantity.ToString());
                    Print(execution.ToString());        
        
                    Print("------------------------------------------------------------------------------");
                }                
        
                #region Properties
                #endregion
            }
        }

        Comment


          #5
          Hello remorim,

          I just wanted to provide a quick update here. Our QA team is currently reviewing this situation however I don't have any other details that I can provide at this point. This was assigned a tracking ID of 14588, if I have anything else provided to me I will update this thread.

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            The update is appreciated, thank you.

            Comment


              #7
              I am getting same problem.
              below is my code:
              Code:
              public class Entry01TradeThePullback : Strategy
              {
              SessionIterator sessionIterator;
              Order sessionOrder;
              protected override void OnStateChange()
              {
              if (State == State.SetDefaults)
              {
              Description = @"Entry #1 – Trade The Pullback";
              Name = "Entry01TradeThePullback";
              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(Data.BarsPeriodType.Minute, 5);
              }
              else if (State == State.DataLoaded)
              {
              sessionIterator = new SessionIterator(Bars);
              }
              }
              
              protected override void OnBarUpdate()
              {
              if (CurrentBar < BarsRequiredToTrade)
              return;
              if (BarsInProgress == 0) //Daily bars, check on open previous value
              {
              if (High[0] < High[1] && High[1] > High[2])
              sessionOrder=EnterShort();
              
              if (Low[0] > Low[1] && Low[1] < Low[2])
              sessionOrder= EnterLong();
              }
              if (Bars.IsLastBarOfSession)
              {
              if ((sessionOrder != null) && (sessionOrder.OrderState == OrderState.Filled))
              {
              if (sessionOrder.OrderAction == OrderAction.Buy)
              ExitLong("eXit", sessionOrder.Name);
              if ((sessionOrder.OrderAction == OrderAction.Sell) || (sessionOrder.OrderAction == OrderAction.SellShort))
              ExitShort("eXit", sessionOrder.Name);
              }
              else if (sessionOrder != null)
              CancelOrder(sessionOrder);
              }
              }
              }
              Attached Files

              Comment


                #8
                Hello remorim,

                I wanted to provide a quick update here. it looks like this was determined to be expected for daily type series and since the help guide has been updated to reflect that. The ExitOnSessionClose property is only available for intraday type series.



                Please let me know if I may be of additional assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by josh18955, 03-25-2023, 11:16 AM
                6 responses
                435 views
                0 likes
                Last Post Delerium  
                Started by FAQtrader, Today, 03:35 PM
                0 responses
                3 views
                0 likes
                Last Post FAQtrader  
                Started by rocketman7, Today, 09:41 AM
                5 responses
                18 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by frslvr, 04-11-2024, 07:26 AM
                9 responses
                126 views
                1 like
                Last Post caryc123  
                Started by selu72, Today, 02:01 PM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Working...
                X