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

Exit Time Before Entry Time

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

    Exit Time Before Entry Time

    Hi
    If I add a second bar with granularity ie 1 min some trades shows entry Time Date after the Exit Date!!

    IE backtesting on ES#### on a 90 min series , RTH exit con close true I get that strange behavior.

    Are the backtests not valid at all with increased granuality?
    On others strategies is even more freqent!

    #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.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion

    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
    /// <summary>
    /// Enter the descrislion of your strategy here
    /// </summary>
    [Description("Enter the descrislion of your strategy here")]
    public class A : Strategy
    {
    #region Variables
    // Wizard generated variables

    private int t=1;

    // 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(PeriodType.Minute ,1);

    this.ExitOnClose=true;

    this.BarsRequired=1;
    this.Slippage=1;
    this.SetProfitTarget(CalculationMode.Ticks,3);
    }

    protected override void OnBarUpdate()
    {



    if(this.BarsInProgress==0)

    {
    bool buy;

    if(SMA(Closes[0],50)[0]>SMA(Closes[0],200)[0])
    buy=true;
    else
    buy=false;


    if(buy&&MarketPosition.Flat==Position.MarketPositi on)
    {
    this.EnterLongLimit(1,true,1,Closes[0][0]-0.25*t,"BuyA");
    return;
    }

    else if(!buy&&MarketPosition.Flat==Position.MarketPosit ion)
    {
    //
    this.EnterShortLimit(1,true,1,Closes[0][0]+0.25*t,"SellA");
    return;
    }
    }

    }


    #region Properties
    [Description("")]
    [GridCategory("Parameters")]
    public int T
    {
    get { return t; }
    set {t= Math.Max(0,value); }
    }



    #endregion
    }
    }
    Attached Files
    Last edited by gileper; 06-02-2013, 03:03 PM.

    #2
    Hello gileper,

    Thank you for your post.

    This would not be expected when adding an additional series to your script. Please take a screenshot of the trades and/or executions that show an exit before the entry and attach the screenshot to your response so I may investigate this matter further.

    Comment


      #3
      Hi
      Attached to the previous thread the screenshots.

      Moreover, in a different strategy, it seems that the profit target it is not affected by the increased granularity. In a 60 min back and a 1 min additional series, I get a profit target never realized since from the moment the entering trade has been executed the profit target has been never filled (just look at this attached and the real data of last 45 minutes on friday 31 May 2013 ES0613, the target price was inside the 60min bar but after the trade). So adding a secondary 1min series it produces not good results, given that it seems to work only on the primary..really bad thing ..if this is the case)
      Attached Files
      Last edited by gileper; 06-02-2013, 03:10 PM.

      Comment


        #4
        Hello gileper,

        Thank you for your response.

        Your screenshot shows a Profit Target filled to Exit the Long Position after the entry was filled.

        Please provide additional information on the matters you speak of, including and if possible the strategy code you are using to place the orders on the 1 minute bar series in backtesting.

        Comment


          #5
          Originally posted by NinjaTrader_PatrickH View Post
          Hello gileper,

          Thank you for your response.

          Your screenshot shows a Profit Target filled to Exit the Long Position after the entry was filled.

          Please provide additional information on the matters you speak of, including and if possible the strategy code you are using to place the orders on the 1 minute bar series in backtesting.
          Hi

          In post 1 attachments you can see that exit time is before entry time. The strategy is the one in the post.


          In post 3 I was showing a DIFFERENT problem. It seems that even with an increased granularity the profit target is filled only looking at the primary bar. The profit target price was actually inside the 60m bar but the target price has been reached BEFORE the entry time.
          So what I mean is: the secondary bar seems to be not used by the setprofitarget void function. Adding a secondary series gives accurate results for the entry but seems to not offer any benefits for the profit target.
          After the entry time the price never reached the target up to the end of the session on 31 may 2013 15.15.. Just look at the mkt prices ...

          Best
          G

          Comment


            #6
            Hello gileper,

            Thank you for your response.

            For the exit before the entry, please follow the instructions below to repair the NinjaTrader database.
            • Disconnect NinjaTrader from any open connections via File > Disconnect
            • From the NinjaTrader Control Center window select the menu Tools > Options
            • Select the "Data" tab
            • Press the "Repair DB" button
            • Press the "OK" button
            • Restart NinjaTrader

            For the second item Set() orders (SetProfitTarget() and SetStopLoss()) will execute based off of the primary series and not the secondary series. The fill algorithm checks the next bar of the primary series and sees that your stop loss or profit target would have been filled and that is what you end up getting in your output.

            There are two options for how you can proceed.
            1. Swap your primary and secondary series. One minute as primary, 60 minute as secondary.
            2. Use explicit Exit() methods instead of Set() methods for your stop loss. This option would allow you to preserve the use of 60 minute as the primary series.

            Please let me know if you have any questions.

            Comment


              #7
              Thanks, I will try that

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by judysamnt7, 03-13-2023, 09:11 AM
              4 responses
              57 views
              0 likes
              Last Post DynamicTest  
              Started by ScottWalsh, Today, 06:52 PM
              4 responses
              36 views
              0 likes
              Last Post ScottWalsh  
              Started by olisav57, Today, 07:39 PM
              0 responses
              7 views
              0 likes
              Last Post olisav57  
              Started by trilliantrader, Today, 03:01 PM
              2 responses
              19 views
              0 likes
              Last Post helpwanted  
              Started by cre8able, Today, 07:24 PM
              0 responses
              9 views
              0 likes
              Last Post cre8able  
              Working...
              X