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

Trades not executing when conditions are met

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

    Trades not executing when conditions are met

    Hello Community!

    I'm having an issue with the strategy i'm building and any suggestions would be appreciated!

    The following code will result in a green diamond

    Code:
    if (CurrentBearLeg.signalBar.CandleStick.Pattern == CandleStick.BarPatterns.PINBAR) {
    if (LongTrade == null) {
    Draw.Diamond(this, System.Guid.NewGuid().ToString(), true, 1, Low[1] - (TickSize * 15), Brushes.GreenYellow);
    EnterLongStopLimit(0, true, 1, High[1] + .25, High[1] + .25, "Test Trade - Long");
    }
    The ONLY condition in order to place a trade is the same condition that will result in the green diamond.
    Click image for larger version

Name:	longtradercondition.png
Views:	223
Size:	8.8 KB
ID:	1145788

    This is calculating pertick so this is under `firstickofbar`. so the stoporder should be placed on the previous day's high

    Code:
    EnterLongStopLimit(0, true, 1, High[1] + .25, High[1] + .25, "Test Trade - Long");
    This only executes SOMETIMES. I'd say more often then not this is ignored.

    Note, I do not have anything that should cancel the order so in theory it should sit there until it gets hit.

    any suggestions?

    Thanks!

    #2
    Hello jaboo,

    Thank you for your post.

    EnterLongStopLimit() would be placed at a limit price and stop price value of the High of the previous bar + .25.

    If the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true or the order is being ignored for other reasons.

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

    Below is a link to a forum post that demonstrates using prints to understand behavior and including a link to a video recorded using the Strategy Builder.
    https://ninjatrader.com/support/foru...121#post791121

    Please let me know if I may further assist
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the response.

      I added printing. Looks like they are just not executing.

      3/3/2021 3:54:55 PM | Test Trade
      3/3/2021 3:55:41 PM Strategy 'SecondEntryStrat/-1': Entered internal SubmitOrderManaged() method at 3/3/2021 3:55:41 PM: BarsInProgress=0 Action=Buy OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=3824.75 SignalName='Test Trade - Long' FromEntrySignal=''
      3/3/2021 3:54:55 PM | Long Position : False - Bear Pin Bar: PINBAR - Test Trade Criteria : True
      3/3/2021 3:55:41 PM | Long Position : False - Bear Pin Bar: undefinded - Test Trade Criteria : False
      3/3/2021 3:58:02 PM Strategy 'SecondEntryStrat/-1': Cancelled custom managed order: orderId='NT-00055-2498' account='Backtest' name='Test Trade - Long' orderState=Working instrument='MES 03-21' orderAction=Buy orderType='Stop Market' limitPrice=0 stopPrice=3824.75 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2021-03-03 15:55:41' gtd='2099-12-01' statementDate='2021-03-10'

      Click image for larger version

Name:	2021-03-10 12_57_06-Window.png
Views:	172
Size:	21.1 KB
ID:	1145849

      Also, a lot of my orders seem to be ignored

      My long order is pretty basic. its just at the high of the day before. not sure why its invalid.
      2/25/2021 10:51:56 AM Strategy 'SecondEntryStrat/-1': Entered internal SubmitOrderManaged() method at 2/25/2021 10:51:56 AM: BarsInProgress=0 Action=Buy OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=3881.25 SignalName='Test Trade - Long' FromEntrySignal=''
      2/25/2021 10:51:56 AM Strategy 'SecondEntryStrat/-1': Ignored SubmitOrderManaged() method at 2/25/2021 10:51:56 AM: BarsInProgress=0 Action=Buy OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=3881.25 SignalName='Test Trade - Long' FromEntrySignal='' Reason='Invalid order price, please see log tab'


      Attached Files

      Comment


        #4
        Hello jaboo,

        Thank you for your note.

        Please enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

        TraceOrders - https://ninjatrader.com/support/help...aceorders2.htm

        In the information you shared I see that the order is being ignored due to being placed at an invalid order price. The message states to see the Log tab. What does the Log tab report?

        2/25/2021 10:51:56 AM Strategy 'SecondEntryStrat/-1': Ignored SubmitOrderManaged() method at 2/25/2021 10:51:56 AM: BarsInProgress=0 Action=Buy OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=3881.25 SignalName='Test Trade - Long' FromEntrySignal='' Reason='Invalid order price, please see log tab'

        Let us know if we may assist further.
        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thanks for reply. this is what the log says

          Click image for larger version

Name:	2021-03-10 16_21_13-Window.png
Views:	164
Size:	18.1 KB
ID:	1145896

          Comment


            #6
            Hello jaboo,

            Thank you for that information.

            ExitLongStopLimit orders must be below the current price at the time they are placed, and vice versa for ExitShortStopLimit or they will be ignored as you have seen. Since the order is not placed until the open of the next bar, by the time the order is placed it is already on the wrong side of the current price and is summarily ignored. I recommend placing your stops farther from the current price to avoid these scenarios.

            See the Tips section of the help guide documentation below for more information.
            ExitLongStopLimit - https://ninjatrader.com/support/help...gstoplimit.htm

            Please let us know if we may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Thanks for the reply. I increased the stop price and it helped.

              Another issue i'm facing is the fact that my orders are being placed on the incorrect bar.

              example
              Click image for larger version

Name:	2021-03-11 12_19_15-Window.png
Views:	174
Size:	8.3 KB
ID:	1146093

              on the first tick of the bar with the arrow, it will look at the previous day and will place the M E text. this evaluates to true and an order should be placed at the low of the previous bar. However, it is executing at the bar after. This is giving wildly inaccurate results in the backtest as it ignores what actually happened on the bar that it was supposed to execute on.

              anything I can do here?

              Comment


                #8
                Hello jaboo,

                Thank you for your note.

                Prints would need to be added to the script to determine why the script is behaving as it is, such as placing orders or not placing orders when expected. Adding prints to the script that print the values used for the logic of the script will allow us to understand how the script is evaluating.

                In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).

                Below is a link to a forum post that demonstrates using prints to understand behavior and including a link to a video recorded using the Strategy Builder.
                https://ninjatrader.com/support/foru...121#post791121

                Please let us know if we may assist further.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  This trade is submitted at 10:14:52. There is no bar on this day that has this timestamp.

                  It also shows the high of the preivous day at 3792. There is also no high around this time that has a high of this price.

                  Here is the code for the print statement.
                  Code:
                   Print(string.Format("{0} | Test Trade | Signal Bar Time - {1} | Signal Bar high {2} | Chart High {3}", Time[1], CurrentBearLeg.signalBar.barData.time, CurrentBearLeg.signalBar.barData.high, High[1]));

                  where .signalBar.barData comes from my indicator. These are clearly synced right as they show the same time and high

                  Click image for larger version  Name:	2021-03-11 18_29_27-Window.png Views:	0 Size:	7.5 KB ID:	1146191
                  ^ the crosshair is at price 3792
                  Click image for larger version  Name:	2021-03-11 18_30_14-Window.png Views:	0 Size:	23.9 KB ID:	1146190
                  Last edited by jaboo; 03-12-2021, 08:20 AM.

                  Comment


                    #10
                    in the video, the person has a tool tip for hovering over a candle. is this a custom script or something I can get my hands on?

                    Comment


                      #11
                      Hello jaboo,

                      Thank you for your note.

                      I do not see the video that you are referring to. If you are referring to the crosshair cursor in the screenshot you shared, you would be able to change your cursor to a Global Crosshair by selecting the 'Crosshair' button in the Chart Toolbar and selecting Global Crosshair. Then, if you click the 'Show Data Box' button in the Chart Toolbar to open a Data Box window, you would be able to see the OHLC price values for a candle by hovering the Global Crosshair over the candle and observing the Data Box window.

                      Regarding your print, you would need to print Time[0] and High[0] instead of Time[1] and High[1] to get the Time value and High price value for when the order is submitted.

                      Also, please provide an example and brief description of the problem you are reporting also so we may accurately assist you.

                      Let us know if we may assist further.
                      Last edited by NinjaTrader_BrandonH; 03-12-2021, 10:07 AM.
                      Brandon H.NinjaTrader Customer Service

                      Comment


                        #12
                        Kind of confused.

                        If on the first tick of bar A I Iook at the yesterdays bar (Bar B) and a condition is true I will place a trade at the High of bar B. This means that the "signal" bar is bar B. So the time and high of bar B is whats most important.

                        If I'm on the first tick of the bar, then Time[0] would just be the open. and the High[0] would just be the opening price. no?

                        Comment


                          #13
                          Hello jaboo,

                          Thank you for your note.

                          Please provide a brief description of the issue that you are reporting so we may accurately assist.

                          Time[0] would get the Time of the current bar. Time[1] would get Time of the previous bar. High[0] would print the High value of the current bar. If you would like to print the High value of the previous bar then you would use High[1].

                          If your order is placed on the current bar at a price value of the previous bar High, then you would need to use Time[0] to print the Time of the current bar that the order was placed on. Also, print out Time[1] to get the Time value of the previous bar. You would need to print High[1] to get the High of the previous bar and compare that to the price that the order was placed.

                          Are you seeing that Time[0] matches the Time that the order was placed? Does Time[1] match the Time of the previous bar? Are you seeing that the order was placed at the High value of the previous bar, High[1]?

                          To determine this, you could compare your prints to the Data Box values by opening a Data Box window and hovering the mouse over the current bar and the previous bar. See the steps in post # 11 for how to accomplish this.

                          I look forward to assisting further.
                          Brandon H.NinjaTrader Customer Service

                          Comment


                            #14
                            Thanks Brandon. I just realized I misunderstood how and when the orders get executed. Looking over it, it appears to work as intended. sorry for the confusion.

                            Comment


                              #15
                              Actually there is an issue. I will try and do a better job at explaining.

                              Given a certain condition is true I will enter a trade. This is the print statement and the order

                              Code:
                               Print(string.Format("{0} | Test Trade | Signal Bar Time - {1} | Signal Bar high {2} | Chart High {3}", Time[0], CurrentBearLeg.signalBar.barData.time, CurrentBearLeg.signalBar.barData.high, High[0]));
                              EnterLongStopLimit(0, true, 1, High[index] + 1, High[index] + .25, "Test Trade - Long");
                              This is the print statement
                              2/25/2021 1:28:24 PM | Test Trade | Signal Bar Time - 2/25/2021 1:28:24 PM | Signal Bar high 3845.5 | Chart High 3845.5
                              2/25/2021 1:28:24 PM Strategy 'SecondEntryStrat/-1': Entered internal SubmitOrderManaged() method at 2/25/2021 1:28:24 PM: BarsInProgress=0 Action=Buy OrderType=StopLimit Quantity=1 LimitPrice=3846.50 StopPrice=3845.75 SignalName='Test Trade - Long' FromEntrySignal=''
                              2/25/2021 1:28:24 PM Strategy 'SecondEntryStrat/-1': Entered internal SubmitOrderManaged() method at 2/25/2021 1:28:24 PM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=3842.50 SignalName='Stop Order' FromEntrySignal='Test Trade - Long'
                              2/25/2021 1:28:24 PM Strategy 'SecondEntryStrat/-1': Entered internal SubmitOrderManaged() method at 2/25/2021 1:28:24 PM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=3847.50 StopPrice=0 SignalName='Target Order' FromEntrySignal='Test Trade - Long'
                              Click image for larger version  Name:	2021-03-13 17_39_52-Window.png Views:	0 Size:	29.6 KB ID:	1146506there is NO bar that has a time of 1:28:24 PM
                              there is also NO bar that has a high of 3845.5

                              So this particular trade is wrong.



                              Thanks!
                              Last edited by jaboo; 03-13-2021, 05:34 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by andrewtrades, Today, 04:57 PM
                              1 response
                              8 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by chbruno, Today, 04:10 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post chbruno
                              by chbruno
                               
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              436 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              19 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Working...
                              X