Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Coding a 'Buy Stop' order

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

    Coding a 'Buy Stop' order

    hello, I want to implement in my strategy the same 'Buy Stop' order I place on my charts via Chart Trader (by right-clicking on the chart). Specifically, I want to enable my strategy to place a long order above the current price so that, if price rises through it, the long order is placed.

    I am currenty using EnterLongStopLimit to achieve this but I get this error: "Buy stop or buy stop limit can't be placed below the market. affected Order: Buy 1 StopLimit @ 1067.0x1067.4" The GetCurrentAsk() price for this example was 1067.2

    Here's my code:
    limitPrice = GetCurrentAsk() + 2*TickSize;
    limitStop = GetCurrentAsk() -
    2*TickSize;
    myEntryOrder = EnterLongStopLimit(limitPrice, limitStop);

    First, I want to make sure I'm using the correct command. If so, I do not understand why I'm getting this error message. I assumed that GetCurrentAsk() is the 'market' so I don't know why the order is placed below it?

    Any insight is greatly appreciated!

    #2
    Originally posted by pman777 View Post
    hello, I want to implement in my strategy the same 'Buy Stop' order I place on my charts via Chart Trader (by right-clicking on the chart). Specifically, I want to enable my strategy to place a long order above the current price so that, if price rises through it, the long order is placed.

    I am currenty using EnterLongStopLimit to achieve this but I get this error: "Buy stop or buy stop limit can't be placed below the market. affected Order: Buy 1 StopLimit @ 1067.0x1067.4" The GetCurrentAsk() price for this example was 1067.2

    Here's my code:
    limitPrice = GetCurrentAsk() + 2*TickSize;
    limitStop = GetCurrentAsk() -
    2*TickSize;
    myEntryOrder = EnterLongStopLimit(limitPrice, limitStop);

    First, I want to make sure I'm using the correct command. If so, I do not understand why I'm getting this error message. I assumed that GetCurrentAsk() is the 'market' so I don't know why the order is placed below it?

    Any insight is greatly appreciated!
    Compare your syntax correctly to the declared syntax. You have a Stop trigger at the limitPrice, and the entry price at the limitStop. limitStop is identically less than limitPrice by 4 ticks, so you are trying to enter at a price below your stop, and actually at a price that will always be behind the market as, by your declaration, it is 2 ticks behind the Ask.

    Comment


      #3
      thank you knoganam ... I probably do not understand the syntax then ... I assumed that the limitPrice (which is the first variable) is my target entry price (2 ticks above the current market price). So that's the price I want to enter that's above the current market price given I have the expectation that price will rise through it and execute the order. Do I have that wrong?

      Comment


        #4
        Originally posted by pman777 View Post
        thank you knoganam ... I probably do not understand the syntax then ... I assumed that the limitPrice (which is the first variable) is my target entry price (2 ticks above the current market price). So that's the price I want to enter that's above the current market price given I have the expectation that price will rise through it and execute the order. Do I have that wrong?
        Something is definitely wrong, but I am not sure what. I am not sure if the syntax has changed, or my initial reply was wrong.

        There are 2 things that I can suggest you try, to help isolate the problem.
        1. Have both the Stop and Limit price at the same price (Close[0] or Ask), and see if that works.
        2. Reverse the limitPrice and stopPrice as you have it, and see if that works.

        If your second option works, then it means that the syntax may have been reversed.

        Unfortunately, I am rebuilding my NinjaTrader development station at this time, so I cannot test this myself right now. (I do not run ANY tests on my NT Trading Station: the only thing that I ever do on it is trade).
        Last edited by koganam; 10-13-2013, 07:23 AM. Reason: Corrected spelling.

        Comment


          #5
          when I swap the variable (limitPrice & limitStop) I still get the same error message. However, when I set them to the same value (GetCurrentAsk() + 2*TickSize) I do not get the message. I'm not sure how to interpret these results.

          Comment


            #6
            Originally posted by pman777 View Post
            when I swap the variable (limitPrice & limitStop) I still get the same error message. However, when I set them to the same value (GetCurrentAsk() + 2*TickSize) I do not get the message. I'm not sure how to interpret these results.
            I expected that you would not get the error if the stopPrice and limitPrice were the same, which is what I was seeking to confirm.

            That also explains your result. You will probably have to use:
            Code:
            stopPrice = GetCurrentAsk();
            as neither the stop nor the price can be behind the market when the order is issued. That is an exchange issue, not a NinjaTrader one.

            The alternative is to check the price, then issue a LimitOrder when the price reaches the required stopPrice, which is how I issue orders to ensure that the market ticks back to put me in at a better price.

            Comment


              #7
              thank you!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              647 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              368 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              108 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              571 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              573 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X