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

Problem in Optimizacion_ Backtest and ExitLongStopMarket

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

    Problem in Optimizacion_ Backtest and ExitLongStopMarket

    Click image for larger version

Name:	image_63372.jpg
Views:	0
Size:	0
ID:	1132088​​​​
    Hello,
    I have a problem with the order :ExitLongStopMarket (StopVol, "SL_ATR",""):
    Log:"An order has been ignored since the stop price ‘5489.5’ near the bar stamped ‘06/10/2011 15:15:00’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored."
    I understand the case of this type of orders when its setup is produced in the 1 candle of the input, that's why I include a condition: if (Close[0] < StopVol) ExitLong("Stop_ATR level exceeded", "");

    The problem is that Strategy analyzer, in the optimizations that occur in this case, slows down enormously, even blocking the NT...
    I have tried to solve it with: if (BarsSinceEntryExecution() >= 1) ExitLongStopMarket (StopVol, "SL_ATR","");
    But the problem I have again when in range of the glider exceeds the Stop_ATR

    How can I solve it without going to "SetStopLoss"?
    Optimizacion Backtest (TF 15_ FDAX)Click image for larger version  Name:	problem_NT_order Stop.jpg Views:	0 Size:	648.7 KB ID:	1132086
    Last edited by elopezh; 12-13-2020, 03:10 PM.

    #2
    Hello elopezh,

    For ExitLongStopMarket this must be below the market price. In historical data it must be below the high of the bar or the order will be ignored.

    May I confirm that the stop price chosen for the order is below the high of the submission bar?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,
      As you can see in the screenshot, the Stop_price (blue dot) is under the maximum, the problem I have with the S.Analyzer, because as you see in the log, continues the process of iterations, but in each optimization slows down the calculation, and if the number of optimizations is high (+100) takes about 4 minutes to solve it
      I am lost in something, because I don't know how to put another order that performs the same function in the strategy: closing the position if it exceeds the StopPrice...
      This "anomaly" happens in two or three bars in 6 years of history, I have reviewed it and I do not see anything strange ...
      It is implemented to me because I have two exits like ExitLongStopMarket, I only show you one ( ATR_stop ), for this still it is slowed down more the iterations...
      I would be grateful, if you could look at it, if you need something more, I send it gladly.

      Comment


        #4
        Hello elopezh,

        The error is letting you know the order stop price is incorrect. So there is an issue with the stop price.
        This may indicate you may be looking at things visually instead of analyzing what the strategy is processing.

        May I have you print the values so that we are not looking at these visually which will cause confusion?

        Please enable TraceOrders, and print the open, high, low, and close of the bar.


        Then save the output to a text file and attach this with your next post.


        Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one on one educational support over the phone in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our partners.

        This thread will remain open would like to debug your script as a convenience to you.

        You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.


        With that said, I am happy to guide you through the debugging and printing process if you would like to debug the script yourself.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Great, I'll send it.
          My apologies in advance, because I'm sure there's some evidence that escapes me. I appreciate the help you are giving me
          Attached Files

          Comment


            #6
            Hello elopezh,

            As an example of printing the open high low and close of the bar:

            Print(string.Format("{0} | Open[0]: {1}, High[0]: {2}, Low[0]: {3}, Close[0]: {4}", Time[0], Open[0], High[0], Low[0], Close[0]));
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello,
              Indeed, if you look at the file I sent, I have included it:
              Print("id". string.Format("{0};{1};{2};{3};{4}", Time[0], Open[0], High[0], Low[0], Close[0]));
              Both for the order of entry to market, and for the exit in stopmarket (id=Bar_Send_Order....Bar_StopVol:...), which is the one of the problem that we are analyzing.

              Comment


                #8
                Hello elopezh,

                May I confirm that this print is outside of all conditions and is printing for every bar?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  In the *.txt file, (at the end - below) include the NS code that I have used to obtain the print .
                  If that is what you ask me.....
                  I can send you *.txt with more range of analyzed data if you want.

                  Comment


                    #10
                    Hello elopezh,

                    When using Calculate.OnBarClose, after a bar closes, the order is submitted and will be filled using the data of the next bar.

                    (edited, this is a sell stop order and must be below the open of the next bar)
                    So we will need the open, high, low, and close, for the succeeding bar as this will be the submission bar. If the price of the order is greater than the open in historical data, that order will be ignored.

                    By printing the data for every bar, we will have the information we need to know if the price is an invalid price.
                    Last edited by NinjaTrader_ChelseaB; 12-15-2020, 01:38 PM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi Chelsea,
                      It's like you say, and you can see it in the first image, actually the Stop_ is over the High of the next bar, which is when the order comes in; that's why, as I told you, in the code I include: if (Close[0] < StopVol) ExitLong("Stop_ATR level exceeded", "");
                      The problem is that NT (S. Analyzer), whenever this is the case, slows down the optimization a lot, and if you have a +200 opt. number and there are 3 situations like the one described, it gets blocked... or takes 10 minutes to solve...
                      The truth is, Chelsea, I don't know how to change this output order without affecting the operation of the S.A.

                      Comment


                        #12
                        Hello elopezh,

                        Are we looking at two different issues?

                        As far as optimization speed, this involves amount of data, amount of iterations, and amount of objects created and stored in memory for each iteration.

                        Below is a link to the help guide on IsInstantiatedOnEachOptimizationIteration.
                        https://ninjatrader.com/support/help...niteration.htm
                        Also, below are a few links to forum posts where IsInstantiatedOnEachOptimizationIteration is discussed.
                        https://ninjatrader.com/support/foru...39#post1069339
                        https://ninjatrader.com/support/foru...036#post838036
                        https://ninjatrader.com/support/foru...57#post1045557

                        However, we are currently addressing an issue of an ignored order. We need to make sure that the sell stop price is below the open of the submission bar (bar after the bar that closed that triggered the order).

                        Would you like to continue investigating this?

                        May I have the output with prints of the open, high, low, and close of every bar?
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Hi Chelsea,
                          Indeed, these are two issues really.
                          I've attached a file where the values of the candle confirm what you say, that the price of the order (ExitLongStopMarket) is higher than the high (bar after the bar that closed that triggered the order).
                          But from this event, it follows that the optimizer warns of the error or inconsistency; this produces a "delay" effect in the resolution of the sequence of iterations.
                          I do not see more option than cancel the order (CancelOrder) that generates this problem ....

                          What do you think?
                          Attached Files

                          Comment


                            #14
                            Hello elopezh,

                            Is the order in question Entrada Larga:
                            06/08/2010 14:45:00 Strategy 'MyRupertBuy/-1': Entered internal SubmitOrderManaged() method at 06/08/2010 14:45:00: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=0 LimitPrice=0 StopPrice=6315,0 SignalName='SL_ATR' FromEntrySignal='Entrada Larga'
                            Strategy 'MyRupertBuy/-1': An order has been ignored since the stop price ‘6315’ near the bar stamped ‘06/08/2010 14:45:00’ is invalid based on the price range of the bar. This is an invalid order and subsequent orders may also be ignored.

                            06/08/2010 14:45:00 Strategy 'MyRupertBuy/-1': Ignored SubmitOrderManaged() method at 06/08/2010 14:45:00: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=0 LimitPrice=0 StopPrice=6315,0 SignalName='SL_ATR' FromEntrySignal='Entrada Larga' Reason='Invalid order price, please see log tab'
                            The next bar print after the 14:45 bar has closed is the 15:00, I am assuming this a 15 minute chart and so the order will be submitted and filled, ignored, or rejected by the 15:00 bar.

                            There are no labels on the bar prints.. So we don't know the values of the bar are. We see some numbers have been printed, but without labels we have no idea what each one of these numbers are.
                            Bar_Entry_Order-StopVol[1]:06/08/2010 15:00:00;6295,5;6307,5;6287;6291
                            I am assuming its the open, high, low, and close, possibly in that order, but there is no label to confirm.

                            The order is a sell stop market order and must have the stop price of 6315 below the open.

                            The lowest number in the numbers is 6287, so we can assume this is the low, and we can assume 6307 is the high. This means one of the remaining two numbers, either 6295 or 6291, is the open.

                            Either way, the stop price is completely over the high. So the order price is not a valid order price. Your broker would reject this order and this would disable the strategy. In historical data, the order is ignored because it is invalid.

                            Choose a stop price that is below the open, either 6295 or 6291 and the order will not be ignored.


                            When an order is ignored, the order does not have to be processed and will not need any further resources, and will not contribute to CPU performance impact. Performance impact is caused by thing that have to be processed. Data, orders that are actually submitted, drawing objects, any other objects you are creating.


                            You can have mentioned CancelOrder(). Do you have question about cancelling orders?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi Chelsea,

                              Finally I have solved my problem, notice that nonsense: with a conditional if... else.... sometimes we look for logarithms and a sum is perfect...
                              As for what I said, I'll tell you that I don't agree with "When an order is ignored......", with a simple random entry and exit script in ExitLongStopMarket you can confirm it, if you also add an N-optimization, you will even notice it.
                              Regarding the doubts CancelOrder, I've been watching it and I'll study it further and if I have any questions I'll tell you.
                              Thank you very much for your kindness

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by elirion, Today, 01:36 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Started by gentlebenthebear, Today, 01:30 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post gentlebenthebear  
                              Started by samish18, Yesterday, 08:31 AM
                              2 responses
                              9 views
                              0 likes
                              Last Post elirion
                              by elirion
                               
                              Started by Mestor, 03-10-2023, 01:50 AM
                              16 responses
                              391 views
                              0 likes
                              Last Post z.franck  
                              Started by rtwave, 04-12-2024, 09:30 AM
                              4 responses
                              34 views
                              0 likes
                              Last Post rtwave
                              by rtwave
                               
                              Working...
                              X