Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error in script when putting an entry

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

    Error in script when putting an entry

    Hello everyone.
    I am new and I don't know if I have created the post in the right place.

    My problem is that I have a script running and I have the following problem:

    There are times when the script is trading I get the following error and the script stops working:

    Buy order stop price must be above last trade price ExchangeRejectCode = 2061 affected Order: Buy 2 StopMarket @ 15133.75

    The strategy 'xxxxxxx' has sent an order that has generated the following error 'Order rejected'. The strategy has sent cancellation requests, tried to close the position and terminated itself.

    The question is that I have tried to fix the problem and I have not succeeded.

    This is the last test I have done to try to solve the problem at the time of placing the entry.

    if(High[0] - GetCurrentBid() < 4){

    EnterLongStopMarket(0, true, 1, GetCurrentBid()+3, "MyEntry");

    }else{

    EnterLongStopMarket(0, true, 1, High[0], "MyEntry");

    }

    I hope someone can help me

    Thank you very much​​​​

    #2
    Hello alexjrj,

    Welcome to the NinjaTrader forums!

    As this pertains to strategy development, I have moved your thread from the Platform Technical Support section of the forums to the Strategy Development section.

    So a buy stop order must have the stop price above the current ask price. (buys at the ask, sells at the bid)

    If you are wanting to use the High of the bar (or any calculated price) you will want to ensure this is a valid price.

    Code:
    double stopPrice = High[0];
    
    if (High[0] <= GetCurrentAsk())
        stopPrice = GetCurrentAsk() - TickSize;
    
    EnterLongStopMarket(0, true, 1, stopPrice, "MyEntry");
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I had not understood the GetCurrentBid() and GetCurrentAsk(), it seems that the first time I wrote the code I did it right but with the functions on the contrary.

      Thank you very much.

      Comment


        #4
        Good I have tried the code and I got the error again.

        This is the code:

        double stopPrice = High[0];

        if (High[0] <= GetCurrentAsk())
        stopPrice = GetCurrentAsk() - TickSize;

        EnterLongStopMarket(0, true, 1, stopPrice, "MyEntry");

        what could it be about? I am using several dataseries, could it have something to do with it?

        thanks​

        Comment


          #5
          Hello alexjrj,

          Apologies, that should be GetCurrentAsk() + TickSize.​

          Code:
          double stopPrice = High[0];
          
          if (High[0] <= GetCurrentAsk())
          stopPrice = GetCurrentAsk() + TickSize;
          
          EnterLongStopMarket(0, true, 1, stopPrice, "MyEntry");


          With the added series, is this with the same instrument or a different instrument?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            I have corrected it, thank you very much.

            The dataseries are from the same instrument.​

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            110 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            59 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            37 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            41 views
            0 likes
            Last Post TheRealMorford  
            Started by Mindset, 02-28-2026, 06:16 AM
            0 responses
            78 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X