Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Some Basic AT Issues

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

    Some Basic AT Issues

    I have a couple of issues with my strategy that I can't quite resolve. It is a very simple strategy as follows.

    When price is below a defined level + the the time is >1.45pm (due to my time zone) then enter a buy stop order at a higher specified level.

    I then have commands to scratch intraday if my order triggers but then the price falls back.

    One issue is that today the order was placed on the open (1.30pm my time and my computers time) despite my strategy saying that nothing should trigger before 1.45pm ie:

    Time series 0 bars ago >= Time value 1.45pm

    I assume that the time is based on my computer clock so how could this happen?

    Also when I select the strategy I have to select the data series. I assume it makes no difference with this strategy whether I select a 1 minute bar or a 1 days bar?

    The final question is that I have several order cancelled after being placed and I don't know why. The error message is 200 or 202. My broker is IB and I understand that these are IB error codes and not Ninja Traders so does that mean there are no issues with my strategy?

    #2
    Hi Shanghai,

    If you can share the code you're using and some settings, we can take a look and are able to offer more input.

    If you're using Time[0] then this is the time stamp of bars, which can be in advance of your computer clock for the most recent bar. It represents the time that the bar will end, so if you're viewing a 30 minute bar at 1:31 then it's time stamped at 2:00.

    For general debugging help with strategies, please see here. Using TraceOrders and Print() statements really help show what the strategy is doing.

    Unfortunately not sure what the error codes mean. For the order cancellation messages, can post here or maybe contact IB for more information.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Thanks a lot Ryan. So if I specifiy a daily bar then that means that the strategy will assume that the time is also at the end of the day. That explains why the order was placed before my specified strategy time. If I use 1 minute bars then that problem should be solved.

      I will try to investigate the error codes further.

      Comment


        #4
        Yes, daily bars are time stamped by the end of the day, so that would explain it.

        For real-time time conditions, you may consider using DateTime.Now instead of Time[0]. This uses your computer date time instead of a bar's time stamp.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          For real-time time conditions, you may consider using DateTime.Now instead of Time[0]. This uses your computer date time instead of a bar's time stamp.
          That sounds like what I need, That way the strategy will work irrespective of bar duration. However it seems like a basic question but where can I find the DateTime.Now function? In the condition builder it just has Date value, Time value and Time series.

          Comment


            #6
            Shanghai, this method is unfortunately not available in the Strategy Wizard.
            AustinNinjaTrader Customer Service

            Comment


              #7
              Thanks for the reply. So it appears that it is not possble to configure a strategy using the wizard that will only place orders after the first 15 minutes of trading if the orders are not filled immediately.

              If I use one minute bars then the orders will be cancelled if they are not filled by the start of the next bar. If I use higher time frame bars then the time stamp on the bars means that the orders will trigger at the market open.

              Comment


                #8
                Sorry to revisit this one but just when I thought I had this cracked I am still having problems. My simple strategy is to place a buy stop order once price has dropped to a predetermined level. That part is fine. However I don't want the strategy to place any orders before 13.45 my time. I was having problems before due to the bar's time stamp, however with Ryan's help I revised this to a DateTime.Now code. However my strategy has just placed an order at the open again (13.30). I am specifiying a daily bar as I assume that the bar time stamp is irrelevant now. My code is below. Any thoughts?

                Originally posted by NinjaTrader_RyanM View Post
                Yes, daily bars are time stamped by the end of the day, so that would explain it.

                For real-time time conditions, you may consider using DateTime.Now instead of Time[0]. This uses your computer date time instead of a bar's time stamp.
                Code:
                 
                // This namespace holds all strategies and is required. Do not change it.
                namespace NinjaTrader.Strategy
                {
                /// <summary>
                /// Daily trend trading trigger
                /// </summary>
                [Description("Daily trend trading trigger")]
                public class Trigger : Strategy
                {
                #region Variables
                // Wizard generated variables
                private double trigger = 1; // Default setting for Trigger
                private double entry = 1; // Default setting for Entry
                private int shares = 1; // Default setting for Shares
                private double scratch = 1; // Default setting for Scratch
                // 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()
                {
                CalculateOnBarClose = false;
                }
                /// <summary>
                /// Called on each bar update event (incoming tick)
                /// </summary>
                protected override void OnBarUpdate()
                {
                // Condition set 1
                if (GetCurrentBid() <= Trigger
                && ToTime(DateTime.Now) >= ToTime(13, 45, 0))
                {
                EnterLongStop(Shares, Entry, "");
                }
                // Condition set 2
                if (GetCurrentBid() <= Scratch)
                {
                ExitLong("", "");
                }
                // Condition set 3
                if (GetCurrentBid() < Entry
                && ToTime(DateTime.Now) > ToTime(20, 55, 0))
                {
                ExitLong("", "");

                Comment


                  #9
                  Are you evaluating this in real time only? As DateTime.Now pulls info from your computer clock, if you use this historically or in a backtest it could trigger true when you don't expect.

                  The code looks OK. To track what is happening with your strategy, it may help to print the value returned by this:
                  Print(ToTime(DateTime.Now) );
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    This was in real time. Its useful that you think the code looks OK. I will try on a few more markets and see if the issue repeats itself.

                    Comment


                      #11
                      I am getting a really strange performance from this strategy now. Not only did the strategy enter trades yesterday before the allocated time of 13:45 but they were entered in the wrong direction. My entire strategy is shown below so it can be seen that it is a long only strategy but it sold 2 markets short soon after the open. How can this happen? Just to repeat, the strategy is (or should be) as follows:

                      1 Market opens
                      2 If the time is after 13;45 and the price is below the "trigger" then a buy stop order will be placed at the "entry"
                      3 If the order is filled then the system should sell when either:
                      a) The price falls to the "scratch" level
                      b) The time is after 20:55 and the price is below "entry".

                      It seems that yesterday two trades out of three entered short postions at the "scratch" level with no long order ever being filled.

                      It may be unconnected but the only thing I did yesterday differently to normal was having the "Immediately submit live working historical orders" box checked.

                      The only other point that may be worth noting is that being in China presently my connection does get lost for a few seconds quite frequently. Not sure if that will make a difference.

                      I have the activity log of yesterday but it is quite long so I don't know how best to post it.

                      Comment


                        #12
                        Hi Shanghai,

                        This sounds like a strategy sync issue, where the order you see that opens in the other direction is intended to be a closing order for the strategy.

                        What is your selection for Tools > Options > Strategies > NinjaScript
                        On Starting a real time strategy.

                        What is Sync Account Position when you run the strategy?
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_RyanM View Post
                          Hi Shanghai,

                          This sounds like a strategy sync issue, where the order you see that opens in the other direction is intended to be a closing order for the strategy.

                          What is your selection for Tools > Options > Strategies > NinjaScript
                          On Starting a real time strategy.

                          What is Sync Account Position when you run the strategy?
                          For the first question, for that day I had ticked "Immediately submit live working historic orders". Usually I have the "Wait until flat before execting live" option ticked.

                          For the Sync Account Position question this is normally left in the default position which is false.

                          I also don't see how trades can be made before my specified time of 13:45. I am selecting daily bars for the strategy although the time stamp should not matter now that I am using the DateTime.Now command.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by bortz, 11-06-2023, 08:04 AM
                          47 responses
                          1,605 views
                          0 likes
                          Last Post aligator  
                          Started by jaybedreamin, Today, 05:56 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post jaybedreamin  
                          Started by DJ888, 04-16-2024, 06:09 PM
                          6 responses
                          18 views
                          0 likes
                          Last Post DJ888
                          by DJ888
                           
                          Started by Jon17, Today, 04:33 PM
                          0 responses
                          4 views
                          0 likes
                          Last Post Jon17
                          by Jon17
                           
                          Started by Javierw.ok, Today, 04:12 PM
                          0 responses
                          13 views
                          0 likes
                          Last Post Javierw.ok  
                          Working...
                          X