Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLongStop

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

    EnterLongStop

    Hi,

    I am having difficulties in developing a strategy (a simple one) which launch an order long stop, more specifically, I am executing

    EnterLongStop in the updateOnBar() method, and the order is launched in the control center, pending in the accept Mode and after a minute or so, it goes in Cancelled mode. I searched in the log and I found that the order was logged as buy Limit !!!

    if I launch an order manually from an open chart in the GUI, then the order is taken as a buy stop, so I think this is a bug problem.

    Please help me,
    Best regards

    #2
    OOps,

    I forgot to mention that I am connected to the Simulated Data Feed so it is possible that if this is a bug of your framework, it might have to deal with this, I didn't try my strategy with real data market, but since the manual order launch is working on simulated data feed with the sim account, I think it should work from strategy deployment also.

    Best regards.

    Comment


      #3
      Please provide a simple-as-possible scenario (including strategy) in order to reproduce the problem.

      Comment


        #4
        protected override void OnBarUpdate()
        {
        if (ToTime(Time[0]) == ToTime(DateTimeHour, DateTimeMinute, DateTimeSecond)) {
        Print("current value of instrument " + Instrument.ToString() + " is " + High[0].ToString());
        double val = High[0] + 7 * 0.0001;
        Print("buy long stop at " + val);
        EnterLongStop(High[0] + 7 * 0.0001, "signalLongStop");
        SetProfitTarget("signalLongStop", CalculationMode.Price, High[0] + 27 * 0.0001);
        SetStopLoss("signalLongStop", CalculationMode.Price, Low[0], false);
        }
        }



        I've noticed that sometimes work, but most of the time it says oredr pending and in the end it tells me that order has been cancelled.

        DateTimeHour, DateTimeMinute, DateTimeSecond are set as static variables with the timestamp of a future closing bar.
        I work with this strategy on simulated feed with the sim account and on a currency. In the Initialize method I have only CalculateOnCloseBar = true

        I don't understand why the order gets cancelled.

        Best regards.

        Comment


          #5
          Please consult the logs: there likely is logged the cause of trouble. Since you likely are testing your strategy on the sim feed (so on "realtime" data and not as backtest on historical data), I would speculate that you do not have set a starting price for the tested instrument for the sim feed: http://www.ninjatrader-support.com/H...struments.html

          Comment


            #6
            Based on your speculation I checked the Instrument Manager and it provides for my currency a Seem Feed Start Price of 1.00

            and anyway I am checking the bars always on the chart and when the order is submitted, a cross tagged with the stop loss and take profit is displayed and a voice is telling me that order is pending, the cross is places above my current High bar value (because it is an Enter Long Stop order), and a few seconds later the same voice is telling me that order is cancelled.

            Here it is my last order in the log :

            8/12/2007 1:56:01 PM,Order,Order='bfcf77b1e4c04eabb6710ec51d39cd56/Sim101' Name='signalLongStop' New State=Cancelled Instrument='$GBPUSD' Action=Buy Limit price=0 Stop price=1.0033 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
            8/12/2007 1:56:00 PM,Order,Order='bfcf77b1e4c04eabb6710ec51d39cd56/Sim101' Name='signalLongStop' New State=PendingCancel Instrument='$GBPUSD' Action=Buy Limit price=0 Stop price=1.0033 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
            8/12/2007 1:55:01 PM,Order,Order='bfcf77b1e4c04eabb6710ec51d39cd56/Sim101' Name='signalLongStop' New State=Accepted Instrument='$GBPUSD' Action=Buy Limit price=0 Stop price=1.0033 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
            8/12/2007 1:55:00 PM,Order,Order='bfcf77b1e4c04eabb6710ec51d39cd56/Sim101' Name='signalLongStop' New State=PendingSubmit Instrument='$GBPUSD' Action=Buy Limit price=0 Stop price=1.0033 Quantity=1 Type=Stop Filled=0 Fill price=0 Error=NoError Native error='',
            8/12/2007 1:52:26 PM,Strategy,Starting NinjaScript strategy 'TestEnterLongStop/68a60bb13e0a4391bd653b71d676912e' : On starting a real-time strategy - SubmitLive,

            Comment


              #7
              NT cancels out orders as they are not "confirmed" by the next bar. Since you have a time base filter in place the order just could get canceled out on next bar after your filter. You will see that as you set TraceOrders=True (please consults the docs).

              Comment


                #8
                This is very strange behaviour from my point of view <NT cancels out orders as they are not "confirmed" by the next bar>

                Why is that my logic works with a EnterLong() order in a time filter frame and not with an EnterLongStop() ?


                Why does an order get cancelled if I don't say so ? in the logic of onBarUpdate() which is just a callback triggered on a closing event bar. It should do just that, trigger the event not cancel my orders if I am not specifying this in the logic of the method.

                And in my method I am saying that at some specific moment in time execute an order and carry on with that order. If I am giving up for the time filter then the logic of onBarUpdate will execute an order at each closing bar event.

                Comment


                  #9
                  >> This is very strange behaviour from my point of view <NT cancels out orders as they are not "confirmed" by the next bar
                  This by no means is strange behavior. Most retail backtesting products like e.g. TradeStation operate the same way.

                  Comment


                    #10
                    Ok, but still,

                    Why is that my logic works with a EnterLong() order in a time filter frame and not with an EnterLongStop() ?

                    Comment


                      #11
                      Sorry, not sure I follow.

                      Comment


                        #12
                        Ok, I will try to be very explicit, hope I'll make myself understood.

                        I have this following code in onBarUpdate

                        protected override void OnBarUpdate()
                        {
                        if (ToTime(Time[0]) == ToTime(09, 00, 00)) {
                        EnterLong(1, "signalLongStop");
                        SetProfitTarget("signalLongStop", CalculationMode.Price, High[0] + 27 * 0.0001);
                        SetStopLoss("signalLongStop", CalculationMode.Price, Low[0], false);
                        }
                        }

                        and I have this time filter which says that when it is 9:00 AM it will submit with NT a long order for market price, ok ? if I deploy the strategy, it works, it launches a stop loss and a take profit for this long market price order.

                        OK, now my problem is that the same code doesn't work for EnterLongStop() or EnterShortStop(), and I don't understand why it is cancelled on the next bar close, because it shouldn't. it doesn't make any sense, and I would like to ask you if this is not the way to do it, HOW CAN I PUT AN ENTERLONGSTOP() order on the NT platform when I want that order at some specific time. (if this is not the way to do it, the docs are not clear about this, I spent hours looking and found nothing)

                        Thanks.

                        Comment


                          #13
                          As pointed out below your code will not work, since any pending order will be cleared out next bar if the signal is not confirmed by the previous bar processed.

                          The reason your market order below works is, that it got filled before the "cancel if signal is not confirmed" logic is triggered. As soon as you place a limit or stop(limit) order is might not get filled immediately by then would be canceled out due to the "cancel if signal is not confirmed" logic.

                          -> you need to call EnterLongStop on every OnBarUpdate call as loong as your entry condition is true and not only once at 09:00:00

                          Comment


                            #14
                            Ok, I understand now, I will try to adapt the code to fit the requirements for enterlongstop(),

                            thanks

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                            0 responses
                            607 views
                            0 likes
                            Last Post Geovanny Suaza  
                            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                            0 responses
                            353 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by Mindset, 02-09-2026, 11:44 AM
                            0 responses
                            105 views
                            0 likes
                            Last Post Mindset
                            by Mindset
                             
                            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                            0 responses
                            560 views
                            1 like
                            Last Post Geovanny Suaza  
                            Started by RFrosty, 01-28-2026, 06:49 PM
                            0 responses
                            561 views
                            1 like
                            Last Post RFrosty
                            by RFrosty
                             
                            Working...
                            X