Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy Wizard Time Settings – Time Value Settings

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

    #16
    OK. I am back again with more annoying Regression Channel questions. Here is the syntax;

    && RegressionChannel(35, 2).Upper[0] > RegressionChannel(35, 2).Upper[34])
    {
    EnterLong(1, "");

    && RegressionChannel(35, 2).Lower[0] < RegressionChannel(35, 2).Lower[34])
    {
    EnterShort(1, "");

    These 2 entries seem to stop my strategy from opening trades. The strategy works fine before placing these conditions but still falls victim to whipsaws. I am reading the Regression Channel from 34 bars ago and comparing to the present bar. For long orders the present bar should be higher. For short orders the present bar should be lower. This to me would indicate at least somewhat of a trend. What am I missing here?

    Best regards,

    Dolfan

    Comment


      #17
      Hello Dolfan,

      These conditions are in two different condition sets correct?

      I would recommend you copy the script, unlock the copy, and print the values you are comparing in the condition to see why the order is not placing.

      Print(string.Format("{0} | {1} > {2} -- EnterLong", Time[0], RegressionChannel(35, 2).Upper[0], RegressionChannel(35, 2).Upper[34]));

      What does this print in the output window when run?

      The time of each bar will show next to the comparison. For a bar where you think that an order should have been placed, what is the channel upper value on the current bar? What is the channel upper value 34 bars ago?

      Below is a link to a video that demonstrates using prints to debug your code.
      https://youtu.be/K8v_2ONBbqI?t=48m27s
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        And the output is....

        **NT** Error on calling 'OnBarUpdate' method for strategy 'HMAoverRegression/28ed635c5f264af9a58bafbc0daa265c': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.

        Seems to me I a asking for input from a bar 34 back when the channel is 35 long. Ideas?

        Comment


          #19
          Hello Dolfan,

          Thank you for posting the error in the output window that provides the information of why your script is not running.

          In your code you are accessing an index with a value that is invalid since its out of range.

          In your condition you are calling an indicator value of a bar 34 bars ago. Is there a check to prevent this if there are not 34 bars?
          If this condition is called on the first bar of historical data, or the second bar or any bar under 34, it will be looking 34 bars ago and that bar will not exist.

          You can also set BarsRequired to 34 to prevent the script from processing until bar 34.

          Any time an index is used on a collection, array, or dataseries that doesn't exist this will cause an error and terminate the script.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #20
            I see said the blind carpenter as he....well you know the rest.

            So the problem is not in the strategy but in the setup. OK, getting results now. Thanks so much for your continued guidance.

            Now back to timing. If I want to trade up until 8:25 AM and get out before market open, return 1 hour later and get out at 3:00 PM, and finally resume at 5 PM and close of day at 11:00 PM, would those times be entered individually in different sets?

            Example;

            Set1 5am to 8:25am
            Set2 9:30am to 3pm
            Set 3 5pm to 11pm

            Best regards,

            Dolfan

            Comment


              #21
              Hello Dolfan,

              If you are using the Strategy Wizard, yes, these need to be in different sets.

              If you are coding the script manually, this could be one set and each portion would separated with an or represented by two vertical lines ||.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #22
                OK Chelsea, I told you I would be getting back to you later, and here I am. I am attempting to enter a short order 5 ticks below the current price. Here is the present syntax I am attempting;

                {
                EnterShortLimit(DefaultQuantity, GetCurrentBid() + -5 * TickSize, "");
                }

                Note that I have tried Bid, Ask, Median, etc. and none of them give me an order below current price. I always get filled at current price. I am using the Strategy Wizard to code this and I am happy to unlock if need be. Please tell me what I am doing wrong here.

                Also, if I tell it to enter at a certain time of day, can I not add seconds to the time? For example, if I want to enter at 9:29:45 AM, the Strategy Wizard rejects the input if I include the seconds. I unlocked the code and changed it from this....

                if (ToTime(Time[0]) == ToTime(9, 29, 0))

                to this....

                if (ToTime(Time[0]) == ToTime(9, 29, 45))

                ...thinking that the '45' was seconds. The order never placed so I assumed wrong. What is the '0' for in (9, 29, 0)) and can I enter an order with seconds as part of the order time?

                Thanks once again!

                Best regards,

                Dolfan

                Comment


                  #23
                  Hello Dolfan,

                  From Investopedia:
                  "A limit order is an order placed with a brokerage to buy or sell a set number of shares at a specified price or better."
                  http://www.investopedia.com/terms/l/limitorder.asp#ixzz4E74YVSTi

                  A Sell Limit Order must be placed above the market price (current bid).
                  A Sell Stop or Sell Stop Limit must be placed below the market price.

                  A Buy Limit Order must be placed below the market price (current ask).
                  A Buy Stop or Buy Stop Limit must be placed above the market price.

                  If you place a Sell Limit Order below the market price, the market price will be a better price and the order will fill at market.


                  You are correct, the Strategy Wizard does not allow seconds to be specified and will use a 0 if the time is not left with the default value.
                  However, the seconds can be set when manually editing the code.
                  if (ToTime(Time[0]) == ToTime(9, 29, 45))

                  This would trigger only if the close time of the bar is exactly 9:29:45 (45 seconds). If this is on a minute chart, this would never trigger as each bar closes at the end of the minute.
                  If this was on a 15 second, 5 second, or 1 second chart then this code could be triggered.

                  Below is a link to Microsoft documentation on TimeSpan.
                  https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
                  Last edited by NinjaTrader_ChelseaB; 07-11-2016, 09:16 AM.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #24
                    Thanks Chelsea. Very informative but I am still falling short somewhere. I changed to a 15 second chart and the order entries as follows;

                    EnterLongStopLimit(DefaultQuantity, GetCurrentBid() + 5 * TickSize, 0, "");

                    ...but I get an error message as detailed in the following .jpg. It seems to be telling me that I cannot place an order at 48.59 below the market price of 48.54. I thought I followed your lead to the letter but I must have missed something.

                    Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


                    Best regards,

                    Dolfan

                    Comment


                      #25
                      Hello Dolfan,

                      Please see my previous post #23.

                      EnterLongStopLimit places a Buy Stop Limit.

                      I'm showing in the screenshot the order was placed at 48.50 which was 5 ticks below the current price shown on the chart (though I cannot confirm the price at the exact time of the rejection).

                      You can verify the limit and stop price on the Orders tab of the Control Center.
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #26
                        By entering a Long order with this syntax EnterLongStopLimit(DefaultQuantity, GetCurrentBid() + 5 * TickSize, 0, ""); I thought I was entering an order 5 ticks ABOVE the current price. Why is it below? What am I misreading???

                        Dolfan

                        Comment


                          #27
                          Hello Dolfan,

                          Are you certain that this code is generating the order in the screenshot?

                          The code shows that the limit would be placed at the current bid plus 5 ticks and the stop would be placed at 0. The stop is not at 0 and this would imply that this code did not generate the order.

                          EnterLongStopLimit(DefaultQuantity, GetCurrentBid() + 5 * TickSize, 0, "");
                          EnterLongStopLimit(int quantity, double limitPrice, double stopPrice, string signalName)
                          http://ninjatrader.com/support/helpG...gstoplimit.htm

                          The order would have been rejected even if this code was generating the order, but that would be due to the stop being at 0 which is guaranteed to be below the current stop price.

                          Do you have TraceOrders = true; in the Initialize() method along with a print to show that this is the exact call that is generating the error?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #28
                            Yes, I am certain of the code. The long order was created in the Strategy Wizard and I am modifying in the short strategy.

                            I am confused by the stop order. I want the stop order handled by the strategy which has a 12 tick trailing stop. If I have to enter a stop with the StopLimit order, what happens with my 12 tick trailing stop? Why is it necessary to enter a stop with the StopLimit order? Should I change this to 12 ticks and will it be fixed versus trailing?

                            I am so confused.

                            Dolfan

                            Comment


                              #29
                              Hello Dolfan,

                              I still disagree that this code could generate this order. The stop is set to 0 in the code, and is showing 48.50 in the screenshot.
                              The price used for the stop price is not the stop price of the order. Thus, this code did not generate that order.

                              If you want the order to trail, you would need to continuously set the price of the stop to 12 ticks above the current ask price if the price of the order is greater than the current price plus 12 ticks. (Buy orders fill at the ask)

                              Each time you call the order with the same signal name and a different price, this will cause the order to move to the new location.

                              From Investopedia:
                              "A stop-limit order will be executed at a specified price (or better) after a given stop price has been reached. Once the stop price is reached, the stop-limit order becomes a limit order to buy (or sell) at the limit price or better."


                              This means that a stop limit must have two prices, a stop and a limit price. The stop will be where the order is initially accepted. When the price reaches the stop price, the order will become a limit order at the limit price.

                              So your order will have the initial placement at 0, at the bottom of the scale. This order would be rejected due to the stop being below the current ask price.

                              (If it was not rejected, it would never fill anyway unless the instrument stop trading completely, or the company went bankrupt, and hit 0)
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #30
                                I tried putting a stop in of -5 ticks and have since taken it out.

                                Here is the entire simple strategy and the error that accompany it.
                                Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.


                                protected override void Initialize()
                                {
                                SetProfitTarget("", CalculationMode.Ticks, 50);
                                SetTrailStop("", CalculationMode.Ticks, 12, false);

                                CalculateOnBarClose = true;
                                }

                                /// <summary>
                                /// Called on each bar update event (incoming tick)
                                /// </summary>
                                protected override void OnBarUpdate()
                                {
                                // Condition set 1
                                if (ToTime(Time[0]) == ToTime(9, 29, 0))
                                {
                                EnterLongStopLimit(DefaultQuantity, GetCurrentBid() + 5 * TickSize, 0, "");
                                }
                                }

                                #region Properties
                                [Description("")]
                                [GridCategory("Parameters")]
                                public int MyInput0
                                {
                                get { return myInput0; }
                                set { myInput0 = Math.Max(1, value); }
                                }
                                #endregion

                                Perhaps we should start again at the beginning. The goal was to enter orders at 9:29:45 AM, one strategy would be for longs and the other would be for shorts. The long strategy is still locked and the short strategy is unlocked so I can put in the :45 second variable. This time requirement works fine. The plan was for the strategies to read the price at the appropriate time and enter one limit order 5 ticks above and one limit order 5 ticks below. The strategy has a 12 tick trailing stop and a 50 tick profit target. I cannot move on to other variables in the strategy until I can get the entry order commands to function properly.

                                Clearly I am missing something here......

                                Dolfan

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by tonynt, 05-21-2019, 06:27 AM
                                10 responses
                                530 views
                                1 like
                                Last Post fiendtrades  
                                Started by awwenzovs, Today, 08:03 AM
                                2 responses
                                14 views
                                0 likes
                                Last Post NinjaTrader_Eduardo  
                                Started by Ashkam, 04-29-2024, 09:28 AM
                                4 responses
                                44 views
                                0 likes
                                Last Post Ashkam
                                by Ashkam
                                 
                                Started by nightstalker, Yesterday, 02:05 PM
                                1 response
                                30 views
                                0 likes
                                Last Post NinjaTrader_Eduardo  
                                Started by dcriador, Today, 02:09 PM
                                0 responses
                                8 views
                                0 likes
                                Last Post dcriador  
                                Working...
                                X