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

Error when multiple order with Target PT1 and PT2 and SL dynamic change when Hit PT1

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

    Error when multiple order with Target PT1 and PT2 and SL dynamic change when Hit PT1

    Hello I am creating a scipt when cross occur, take 2 orders with same SL and different Target PT1 and PT2, After 1st order hit PT1, SL become BE.

    I am getting error " cant be submitted.The OCO ID '94239842394" cannot be reused. Please use new OCO ID affectedOrder: BuytoCover 1 limit @"

    i given SetprofitTarget and SetStoploss in Dataloaded.

    ​​​​​​SetProfitTarget("Long1", CalculationMode.Ticks,PT1);
    SetProfitTarget("Long2", CalculationMode.Ticks,PT2);
    SetStopLoss("", CalculationMode.Ticks, StopLoss, true);​

    And Dynamic SL i given in onbar update.

    ​​​​​​if (Position.MarketPosition == MarketPosition.Long)
    {
    if (Close[0] >= Position.AveragePrice + 10 * TickSize)
    {
    SetStopLoss(CalculationMode.Price, Position.AveragePrice);
    }
    }​

    #2
    Hello jenishij,

    Thanks for your post.

    You could use Exit order methods for your profit target and stop loss orders instead of using Set methods if you want to move the stop to breakeven.

    You can use exit order methods and add coding logic in the Strategy Builder to accomplish this goal. Please note that you would not be able to use the exit methods and the stops in the stop and targets window as that creates a violation of the managed approach internal order handling rules, linked here: https://ninjatrader.com/support/help...d_approach.htm

    My colleague Chelsea has created educational examples of strategy builder breakeven and trailing stop in the strategy builder here:

    https://ninjatrader.com/support/forum/forum/suggestions-and-feedback/suggestions-and-feedback-
    aa/103992-request-breakeven-functions-in-strategy-builder#post806596
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      I could not open both links. Showing page not found .

      Comment


        #4
        Hello jenishij,

        Thanks for your notes.

        I have readded the links below for you to view.

        Managed Approach: https://ninjatrader.com/support/help...d_approach.htm

        My colleague Chelsea has created educational examples of strategy builder breakeven and trailing stop in the strategy builder here:

        Brandon H.NinjaTrader Customer Service

        Comment


          #5
          Thanks Brandon. Exit order works. But when i place 2 order, It is executing only 1. We cannot do 2 orders in same condition with different name?

          if ((Position.MarketPosition == MarketPosition.Long)&& (Condition == 0)

          ​​​​​​{

          EnterLong(1, @"Long1");
          EnterLong(1, @"Long2");

          }

          Comment


            #6
            Hello jenishij,

            Thanks for your notes.

            The Entries Per Direction property should be set to 2 if you would like to have more than 1 position placed by the strategy at a time.

            EntriesPerDirection and EntryHandling could be used to control the maximum number of entries allowed per direction while a position.

            If you set Entry Handling to EntryHandling.AllEntries, NinjaScript will process all entry order methods up to the maximum allowable entries set in the EntriesPerDirection property. For example, if you set EntriesPerDirection to 3 and use EntryHandling.AllEntries, up to a total of 3 entry orders will process.

            If you set Entry Handling to EntryHandling.UniqueEntries, NinjaScript will process order entry methods up to the maximum allowable entries set by the EntriesPerDirection property for each uniquely named entry. For example, if you have two entry order methods using unique signal names ("entry1" and "entry2"), set EntriesPerDirection to 3, and use EntryHandling.UniqueEntries, a maximum number of 3 entry orders will process for each uniquely named entry order (up to 3 orders for "entry1" and 3 orders for "entry2").​

            EntriesPerDirection: https://ninjatrader.com/support/help...rdirection.htm
            EntryHandling: https://ninjatrader.com/support/help...ryhandling.htm
            Brandon H.NinjaTrader Customer Service

            Comment


              #7

              What exactly Stop price in the managed approach in EnterLongStopMarket(int quantity, double stopPrice, string signalName) means? document mentioned "The stop price of the order."

              Is stop price is like Stop Loss?


              Comment


                #8
                Hello jenishij,

                Thanks for your notes.

                EnterLongStopMarket() is used to submit a buy stop market order to enter a long position.

                These orders wait for the price of the instrument to pass your stop price. Once it passes the stop price the order becomes a market order for execution. Stop orders increase your chances of getting filled at a particular price, but are not guaranteed because they are still ultimately market orders.

                See the help guide documentation below for more information.

                NT8 Order Types: https://ninjatrader.com/support/help...rder_types.htm
                NT8 EnterLongStopMarket(): https://ninjatrader.com/support/help...stopmarket.htm
                Brandon H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by fx.practic, 10-15-2013, 12:53 AM
                5 responses
                5,403 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Started by Shai Samuel, 07-02-2022, 02:46 PM
                4 responses
                95 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Started by DJ888, Yesterday, 10:57 PM
                0 responses
                7 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by MacDad, 02-25-2024, 11:48 PM
                7 responses
                159 views
                0 likes
                Last Post loganjarosz123  
                Started by Belfortbucks, Yesterday, 09:29 PM
                0 responses
                8 views
                0 likes
                Last Post Belfortbucks  
                Working...
                X