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

When should i SetProfit or SetStopLoss

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

    When should i SetProfit or SetStopLoss

    Hello,
    I have question. What is proper order of calling SetProfit and SetStopLoss function?

    I have strategy and I have this solution:

    Code:
    tradeItem.Order = EnterLongLimit(timeFrameTicks, true, iContractsSet[index], tradeItem.EntryPrice, tradeItem.EntryName);
    then when order is submitted and filled i do
    Code:
    protected override void OnOrderUpdate....
    // Limit FILLED
    if (order.OrderState == OrderState.Filled || order.OrderState == OrderState.PartFilled)
    {​
       SetStopLoss(tradeItem.EntryName, CalculationMode.Price, tradeItem.StopLoss_Price, false);
    ​ SetProfitTarget(tradeItem.EntryName, CalculationMode.Price, tradeItem.ProfitTarget_Price);
    ​}
    but I guess this is not ok. Sometimes i get partfilled order and when i see in charttrader 2 orders on sl even when only 1 contract was filled and strategy disables.

    How should I proceed? I mean how to handle those partfills together with settings sl.
    Will calling SetStopLoss and SetProfitTarget beore EnterLongLimit do some trick?

    Thanks a lot

    Paul

    #2
    That would be fine, understanding there is a lag between the time you actually get filled and the time your exits reach the exchange. It would be superior, if you know the price in advance, to do the SetStopLoss and SetProfitTarget (or ExitLongLimit and ExitLongStop) before you place the entry order.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Yes I know the PT and SL values, so i should change order to
      Code:
      SetStopLoss(tradeItem.EntryName, CalculationMode.Price, tradeItem.StopLoss_Price, false);
      ​SetProfitTarget(tradeItem.EntryName, CalculationMode.Price, tradeItem.ProfitTarget_Price);
      
      and then
      
      tradeItem.Order = EnterLongLimit(timeFrameTicks, true, iContractsSet[index], tradeItem.EntryPrice, tradeItem.EntryName);

      and all these 3 commands call from OnBarUpdate() ?

      Will this also handle properly part fills?

      Comment


        #4
        Yes. Partial fills will be handled automatically.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Hello kujista,

          Thanks for your post.

          QuantKey_Bruce is correct in stating the code you shared would be okay to use and that partial fills will be handled automatically.

          Since Set methods (SetStopLoss()/SetProfitTarget()) prep NinjaTrader to submit protective orders upon the execution of an Entry order they should be called before the Entry order is placed as seen in the code you shared in post # 3.

          From the SetStopLoss and SetProfitTarget help guide pages: "Since they are submitted upon receiving an execution, the Set method should be called prior to submitting the associated entry order to ensure an initial level is set."

          SetStopLoss: https://ninjatrader.com/support/help...etstoploss.htm
          SetProfitTarget: https://ninjatrader.com/support/help...ofittarget.htm
          Brandon H.NinjaTrader Customer Service

          Comment


            #6
            Hello

            It seem it started to work but i am getting now issue

            Internal Order Handling Rules that Reduce Unwanted Positions

            when I do these commands :-(

            Code:
            SetStopLoss(tradeItem.EntryName, CalculationMode.Price, tradeItem.StopLoss_Price, false);
            ​SetProfitTarget(tradeItem.EntryName, CalculationMode.Price, tradeItem.ProfitTarget_Price);
            
            and then
            
            tradeItem.Order = EnterLongLimit(timeFrameTicks, true, iContractsSet[index], tradeItem.EntryPrice, tradeItem.EntryName);​
            is there problem using SetProfitTarget or what?

            Comment


              #7
              this is my custom log
              prices of sl pt seem to be ok
              Code:
              2023-02-02 15:53:15 --- TRADE --- PLACED STOP LOSS 4201,75 PRICE IS 4199,25
              2023-02-02 15:53:15 --- TRADE --- PLACED PROFIT TARGET AT 4196,75 PRICE IS 4199,25
              Strategy 'RangeBarsIntraday/-1': An Enter() method to submit an entry order at '02/02/2023 15:53:15' has been ignored. Please search on the term 'Internal Order Handling Rules that Reduce Unwanted Positions' in the Help Guide for detailed explanation.
              2023-02-02 15:53:15 --- TRADE --- LIMIT Short AWAITING AT 4199,75​

              Comment


                #8
                Hello kujista,

                Thanks for your notes.

                When creating a managed approach strategy there are some important internal order handling rules to keep in mind. To prevent situations in real-time in which you may have multiple orders working to accomplish the same task, there are some "under the hood" rules that a NinjaScript strategy follows when Managed order methods are called.

                Methods that generate orders to enter a position will be ignored if:
                • A position is open and an order submitted by a non market order exit method (ExitLongLimit() for example) is active and the order is used to open a position in the opposite direction​.
                • A position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction​
                • The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction.
                • The entry signal name is not unique
                See this help guide page for more information about the Managed Approach Internal Order Handling Rules: https://ninjatrader.com/support/help...rnalOrderHandl ingRulesThatReduceUnwantedPositions
                Brandon H.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Haiasi, 04-25-2024, 06:53 PM
                2 responses
                16 views
                0 likes
                Last Post Massinisa  
                Started by Creamers, Today, 05:32 AM
                0 responses
                4 views
                0 likes
                Last Post Creamers  
                Started by Segwin, 05-07-2018, 02:15 PM
                12 responses
                1,786 views
                0 likes
                Last Post Leafcutter  
                Started by poplagelu, Today, 05:00 AM
                0 responses
                3 views
                0 likes
                Last Post poplagelu  
                Started by fx.practic, 10-15-2013, 12:53 AM
                5 responses
                5,407 views
                0 likes
                Last Post Bidder
                by Bidder
                 
                Working...
                X