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

Strategy Builder - how to set strategy to run every day not just day it is added?

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

    Strategy Builder - how to set strategy to run every day not just day it is added?

    Hi,

    I have developed a strategy and back tested it and I would like to run it in my Sim account.

    I have added it to the Strategies, but it appears with today's date and it will only execute today, not every day going forward. To do that I need to add it every day...what am I doing incorrectly? Since it back tested fine (I run it for the past 3 months, 1 month, 2 weeks and 1 week), I thought it was ok. But while the back test run every day in the selected time, the live on the Sim account does not. See attached screenshot (red circled). The other strategies are from a third party and they run just fine, but I do not have the source code to check...

    Any help would be greatly appreciated!

    Thanks
    David

    #2
    Hello David,

    If the strategy is enabled and is not placing orders, this would be due to the logic or the data.

    If the strategy is applied to a chart, is there data with new bars appearing on the chart the Strategy is applied to?
    Is the strategy showing as enabled on the Strategies tab of the Control Center?
    If the strategy is in the Strategy Analyzer, is there data appearing on the Chart Display of the Strategy Analyzer?
    Importantly, are there errors appearing on the Log tab of the Control Center?

    Try testing the Sample MA Crossover strategy included with NinjaTrader on the same chart or Strategy Analyzer using the same instrument, bar type, interval, and date range.
    Do you see results with this strategy? (This would confirm for us data is available and the issue is with the logic in the custom script)

    If the strategy is getting data and the strategy is enabled or a backtest is run with no errors in the Log tab of the Control Center, then would likely indicate the logic conditions did not evaluate as true or orders are being ignored or cancelled.
    In order to better understand how the code is working, it will be necessary to use Print to see how the conditions are evaluating and enable TraceOrders to see if orders are being submitted, ignored, rejected, or cancelled.
    Below is a link to a forum post that demonstrates using prints to understand behavior and includes a link to a video recorded using the Strategy Builder to add prints.
    https://ninjatrader.com/support/foru...121#post791121
    Enable TraceOrders, print the time of the bar and all values used in the conditions that submit entry orders.
    Let me know if you need any assistance creating a print or enabling TraceOrders.
    Save the output from the output window to a text file and provide this with your reply.
    I'll be happy to assist with analyzing the output.

    If this is not a strategy you have coded yourself, you will need to contact the vendor or author that has distributed this script to you, to inquire about how their software works or to report issues with their software.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      Thanks for the prompt reply, I can confirm that I have data and that the strategy was enabled. I have a live account as well as several sim accounts. I only have issues running this Strategy, I have others from a third party that works well, but this is mine, I build it using the Strategy Builder.

      I will look at your link to add prints. I have enable trace orders already. do you know if I need to re-add the Strategy or is it enough to disable it, make the modification and re-enable it?

      In the meantime, I'll share some other error messages that I have gotten. Can all of this be looked at using the prints/trace orders that you mentioned above? Or is there something else to do for these? Just trying to get to the bottom of all these issues and collect all the relevant information.

      Thanks a lot!
      David

      Comment


        #4
        Hello David,

        The error 'SimORB-TRY-A, Buy stop or buy stop limit orders can't be placed below the market' is stating that the stop price of 2213.9 was below the current ask.

        Are you ensuring the prices you are choosing for the stop order are above the current ask for buy stop orders?

        Printing the ask and price used for the stop would confirm.

        The OCO error is because one order was rejected, the others are also rejected.

        If an order is rejected I would not expect that strategy to be enabled. I would expect the strategy would become disabled if using the default real-time error handling of StopCancelClose.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,

          I think I have managed to set up the print command correctly, please find it attached. I have enabled Trace Orders, is there anything that I need to do for that?

          I have gotten a good amount of error messages on screen when running the strategy yesterday and this morning, I have included them as .zip as well, just in case they are helpful to understand what is going on.

          About your reply: I want to buy if the current price goes above a certain value (which is a variable in the Strategy, because it is determined on the first bar) and sell if it goes below another value (which is another variable in the Strategy, again determined on the first bar). I used LongMIT(BuyContracts, ORBHigh, "") where BuyContracts is an Input and ORBHigh is the variable mentioned above. And ShortMIT(SellContracts, ORBLow, ""). Perhaps I should not have used LongMIT and ShortMIT? I tried Long Limit, Long Stop and Long Stop Limit, but they all failed to Buy/Sell when desired (in the backtest), whereas LongMIT correctly Bought and Sold at the right time and at the right value (again in backtest). But when I run it in the Sim I got all sort of error messages...

          Understood about the strategy being disabled if an order is rejected, so that would explain why it was always disabled. It seems like I got a lot of rejected orders...If we fix that, maybe the strategy would work.

          Thank you very much!

          David
          Attached Files

          Comment


            #6
            Hello david196,

            The output you have provided does not have comparison labels, so I am not sure how to read this information.

            As example if I want to print info for a cross above I would print:
            Print(string.Format("{0} | SMA(7)[1]: {1} < SMA(14)[1]: {2} & SMA(7)[0]: {3} > SMA(14)[0]: {4}", Time[0], SMA(7)[1], SMA(14)[1], SMA(7)[0], SMA(14)[0]));

            The output would appear as:
            3/18/2021 3:00:00 PM | SMA(7)[1]: 3936.10 < SMA(14)[1]: 3883.48 & SMA(7)[0]: 3942.28 > SMA(14)[0]: 3891.14

            With the above output I have labels showing what each value is, and how this compares with the next number. I can see that the SMA(7)[1] has a less than symbol between SMA(14)[1] so I know the first value is being compared to be less than the second value. I can evaluate the entire print and know if that line will evaluate as true or false.


            With MarketIfTouched orders, these would be opposite of the stop orders that are causing the errors.

            A buy MIT must be placed below the current ask, a sell MIT must be placed above the ask.

            I would recommend addressing the errors with the stop orders first, and then addressing the errors with the MIT next.

            With the stop errors, what is the current ask when the stop is submitted, and what is the stop price submitted for the order?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Chelsea,

              Thanks for the reply.

              I am not sure I follow what you are saying though. The SMA example is different than what I am trying to do. My Strategy does not compare the price of one bar with the price of the previous one, it compares the current price (bar 0) with two values (high and low) that are set in the first minute (8:31am CDT in this case). Those values are correct, I can see them in the printout and on screen when applying the script to the chart. The are ORBHigh (the high of that bar) and ORBLow (the low of that bar).

              If the current price is above ORBHigh, I Buy the Bid price. If the current price is below ORBLow, I Sell the Ask price. It seems to me that the error is in the Order Management, not in reading the charts and deciding what to do. If I look at how the script works on the chart, I see that it is placing orders at the right price and right time. See attachment. Also attached the print output for this morning. I think I have added the information that you requested (current price ask and current price bid).

              ORB high = 3959.75 (correct) and ORBLow = 3956.5 (also correct). Lines are also drawn correctly on the screen.

              The orders are placed at the right time and at the right place, but I get error messages (in previous attachments and in the print as well), which why I am wondering if the Order Management is not correct.

              I have attempted to include this is a second print (output-long-2).

              I hope I understood correctly what you were saying and I managed to describe what I am trying to do.

              Thank you very much!

              David
              Attached Files

              Comment


                #8
                Hello david196,

                I'm trying to suggest the importance of using labels in the prints to indentify what the information in the print means. This would be for any indicator, any values, any variables, any methods that a value, anything that is in the condition sets should have a label so we know what the information means and how it is being compared. You can ignore that the print copied from the forum post I have linked uses the SMA as an example. Your print should match your condition, and should include a label for the variable name and the symbols for how that information is being compared (comparison operators like plus, minus, less than, greater than, equal to, and, or)

                So the values are what you expect, and the condition evaluated as true?

                If the current price is above ORBHigh, I Buy the Bid price.
                If the condition set for this logic you have stated above is:
                Code:
                if (Close[0] > ORBHigh)
                {
                EnterLongLimit(0, true, 1, GetCurrentBid(), string.Empty);
                }
                I would print:
                Code:
                Print(string.Format("{0} | Close[0]: {1} > ORBHigh[0]: {2}", Time[0], Close[0], ORBHigh[0]));
                With this and TraceOrders we would see when the condition is true, and what happens with the order.


                On what date and at what time are you seeing an error message?

                Is this an error message like a rejection?
                Or is this a warning message like an ignored order?

                Does the strategy disable?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea,

                  I apologize, it appears that not all the files that I thought I uploaded were actually uploaded.

                  I think I have managed to print what you asked. Let me try uploading the files one more time.

                  Yes, orders were rejected and the strategy disabled. You explained to me that this is normal when an order is rejected. So the question is why are orders being rejected. I have enabled Trace Orders, yes. I have included examples of error messages in previous messages (from screenshots) and they are now in the print also.

                  I am using Calculate on prince change (not bar close), does it matter? I have tried on bar close, but it was not filling the orders at the right time/price. When I switched to On Price Change it started doing it correctly.

                  Thanks a lot! And again apologies for not noticing that the files that I wanted to upload were not uploaded.

                  David
                  Attached Files

                  Comment


                    #10
                    Hello david196,

                    I'm not seeing the rejection in the output. May I have screenshot from the Log tab of the Control Center?

                    Orders are typically rejected if the stop or limit price is invalid (on the wrong side of the market), or from margin requirement issues.

                    Using Calculate.OnPriceChange is fine. This allows the strategy to update OnBarUpdate in real-time for each price change instead of only when the bar closes.

                    In historical data, TickReplay and intra-bar granularity is necessary to implement that behavior.
                    Last edited by NinjaTrader_ChelseaB; 04-01-2021, 07:32 AM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Chelsea,

                      Here it is!

                      This is not a rejected order, but it still disabled the strategy for an error (two screenshots, one from this morning, one from this afternoon). I have added the "Signal name" to the Strategy to see if that fixed the order management issue. The market was behaving differently this morning, so the rejected order issue might not have shown up for that reason. When it is moving quickly, I think it hits the target values to buy/sell multiple times and it wants to close one to open one in the opposite direction. I have selected "Wait until flat" under start behavior, so I thought that would do it. I also have 1 entry per direction, so it shouldn't try to open multiple positions.

                      I included the error message for the order rejected also from a couple of days ago. That was on another instrument, but using the same strategy. At that time I did not have Trace Orders enabled yet. If this is not helpful, I can wait for it to show up again and send it then, perhaps when the market fluctuates more than this morning.

                      Thanks
                      David

                      ​​​​​​​
                      Attached Files

                      Comment


                        #12
                        Hi Chelsea,

                        Just got the same error about the order being rejected again. See attachment.

                        Thanks
                        David
                        Attached Files

                        Comment


                          #13
                          Hello david196, thanks for the follow up.

                          It looks like the order getting rejected is the Trailing stop order you have set up. If this is happening in a fast moving market, and not happening on other tests, like the Playback Connection, its possible it is putting the trial stop too close to the market price and an in-flight issue happens with the order because the price moved before the order was submitted, or the code is simply submitting the trailing stop in the incorrect place. Try loosening the constraints of the trail stop and do not place it so close to the market price and test the strategy for this order rejection again.

                          Best regards,
                          -ChrisL.
                          Chris L.NinjaTrader Customer Service

                          Comment


                            #14
                            Hi ChrisL,

                            Thanks for the reply, yes it was a fast moving market and the trailing stop was set fairly close.

                            I already tried relaxing it (40 ticks for profit and 20 ticks trailing) and it did execute a trade correctly, but still disabled the strategy...so there might be something else at play.

                            What about the other 2 errors? Could they be related to the same thing? The "OCO ID ... cannot be reused, please use a new OCO ID" and the one about "...accessing a series (bars ago) with a value of 5 when there are only 4 bars on the chart"? See attachments.

                            Thanks a lot!

                            David



                            Attached Files

                            Comment


                              #15
                              Hello David,

                              The OCO ID error means that an OCO ID from a cancelled, filled, or rejected order was used.
                              This is typically the opposing limit profit target or stop loss paired with an order that was rejected. If one order is rejected, the order paired orders are also rejected.

                              You can print out each ask and bid market update and print the price used for the stop to ensure that for a buy order this is at least one tick above the ask or with a sell order is at least one tick below the bid.



                              The indexing error is not related. This is caused with an invalid index is used.

                              For example on the first bar when CurrentBar is 0, calling Close[1] would cause this indexing error as there is bar 1 ago.
                              Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by trilliantrader, 04-18-2024, 08:16 AM
                              4 responses
                              18 views
                              0 likes
                              Last Post trilliantrader  
                              Started by mgco4you, Today, 09:46 PM
                              1 response
                              7 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by wzgy0920, Today, 09:53 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post wzgy0920  
                              Started by Rapine Heihei, Today, 08:19 PM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by Rapine Heihei, Today, 08:25 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post Rapine Heihei  
                              Working...
                              X