• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss not send to the broker

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

    SetStopLoss not send to the broker

    Hi

    when i write this code :

    // Condition Buy
    if (CrossAbove(Stochastics(5,Stoch, 3).K, survente, 1)
    {
    EnterLong(DefaultQuantity,
    "Achat");
    SetProfitTarget(
    "Achat", CalculationMode.Ticks, target);
    SetStopLoss(
    "Achat", CalculationMode.Ticks, stop, true);
    }

    My profit order is sent to the broker, the state in NT is green "working"

    but the StopLoss is yellow and "initialzed" and i cannot see it on the broker plateforme... so the time NT send the order to the broker i have a slippage of many ticks, so how it is possible to have a stoploss order state green and "working" sent to the broke like the profit ?

    Can you help ?

    #2
    Hello,

    You have the "Simulated" bool set to true in your SetStopLoss method. The simulated Stop will be held on your local PC and not send to the broker until the stop is triggered.

    If you would like to send the Stop to the broker, please change this to false:

    Code:
    SetStopLoss("Achat", CalculationMode.Ticks, stop, false);
    MatthewNinjaTrader Product Management

    Comment


      #3
      I have another problem, when i change the EnterLong by an EnterLongLimit like that:

      // Condition Buy
      if (CrossAbove(Stochastics(5,Stoch, 3).K, survente, 1)
      {
      EnterLongLimit(DefaultQuantity, Close[
      0], "STSAchat");
      SetProfitTarget(
      "STSAchat", CalculationMode.Ticks, target);
      SetStopLoss(
      "STSAchat", CalculationMode.Ticks, stop, true);
      }
      // Condition Sell
      if (CrossBelow(Stochastics(5,Stoch, 3).K, surachat, 1)
      {
      EnterShortLimit(DefaultQuantity,Close[
      0], "STSVente");
      SetProfitTarget(
      "STSVente", CalculationMode.Ticks, target);
      SetStopLoss(
      "STSVente", CalculationMode.Ticks, stop, true);
      }

      when for example the position is long and a bearish signal is sent, it is not reversing the position... but if the entry order are not limit (EnterLong and EnterShort), it is reversing... i don't understand why the nature of the entry order is changing the reversal position...

      Comment


        #4
        Hello,

        There are some Internal Order Handling Rules that Reduce Unwanted Positions
        that can be envoked that will prevent you from entering multiple orders at the same time. For example:

        Methods that generate orders to enter a position will be ignored if:
        • A position is open and an order submitted by an 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
        There are ways to avoid these however - can you please clarify if you're completing your strategy by hand through code or through the Strategy Wizard?
        MatthewNinjaTrader Product Management

        Comment


          #5
          i'm completing my strategy by hand through code.

          Comment


            #6
            I would recommend using OnExecution or OnOrderUpdate to set your SetStop and SetTarget to prevent these orders from being ignored at the OnBarUpdate call when the entry condition is true.

            Please see our Reference Sample on Using OnOrderUpdate() and OnExecution() methods to submit protective orders
            http://www.ninjatrader.com/support/f...ead.php?t=7499

            I'd also suggest enabling the TraceOrders property for additional debugging to understand exactly why the order are being ignored or canceled.

            More information on TraceOrders can be found below:

            http://www.ninjatrader.com/support/f...ead.php?t=3627
            MatthewNinjaTrader Product Management

            Comment


              #7
              Hi Matthew

              i wrote the code with OnExecution and OnOrderUpdate but the problem is when the strategy is long and there is a sell condition, the strategy stay long untill the stop or the target is hit.

              With the previous script OnBarUpdate, it is reversing if i'm long and a sell condition appears.

              you will find enclosed my code if you can help.

              Thx.
              Attached Files

              Comment


                #8
                Hi Thomas79,

                This will require some advanced order handling to work around, and you have to move away from "set" statements completely.

                Set orders are mainly for convenience and your strategy will require more control with orders. Once set, they cannot become unset (they'll be applied to any position matching signal name), they can't be cancelled, and these working orders will always prevent submission of a limit reversal order according to internal order handling rules.

                Here is what's required for limit order reversal while having protective orders:
                Use the previously linked OnOrderUpdate()/ OnExecution reference sample for help submitting protective orders with the same timing as set orders. Instead of set, your target order needs to be submitted with either ExitLongLimit() or ExitShortLimit().

                If you want a reversal with a limit order, you must first cancel the working exit order, and then submit your entry order. This sample can help with CancelOrder()
                http://www.ninjatrader.com/support/f...ad.php?t=18890

                This can be a bit tricky to code and knowledge of advanced topics like IOrders and advanced event handlers is needed. These pages can help you more with that:
                http://www.ninjatrader.com/support/h...r_handling.htm
                http://www.ninjatrader.com/support/h...n_program2.htm
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Ryan

                  if i well understand, if the position is long and there is a selling signal

                  i have to:

                  1 - cancel the exitlongstop() and the exitlonglimit() orders
                  2 - exit the long position with a exitlong() order (because i want to exit at market not with a limit)
                  3- and then send an entershortlimit() order

                  is it all right ?

                  but i have to call all this handling in the OnBarUpdate or in OnOrderUpdate ?

                  Thx

                  Comment


                    #10
                    Hello Thomas79,
                    Yes, but you have to make sure the orders are cancelled and the position is flat before submitting the Sell limit order.

                    You can put the Exit orders and the order cancellation order in OnOrderUpate (or OnExecution) and put the entry order in OnBarUpdate (after making sure that you are flat etc).

                    http://www.ninjatrader.com/support/h...nexecution.htm
                    http://www.ninjatrader.com/support/h...rderupdate.htm

                    Please let me know if I can assist you any further.
                    JoydeepNinjaTrader Customer Service

                    Comment


                      #11
                      Internal order handling rules will not apply to market orders like ExitLong() and ExitShort(). This means you do not have to cancel working exit limit orders since this would already be handled by these market exit orders.

                      Cancelling is needed when you want to replace the working exit limit order with an entry limit order for reversal.
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        ok Ryan

                        so i have just to say

                        if position long and selling condition appears, exitlong() order and entershortlimit() order

                        and that on the OnBarUpdate ?

                        Comment


                          #13
                          That's the idea but you can't have both orders in the same place. They need to be submitted in a sequence. This is ultimately the sequence you should go for and it could be done all in OnBarUpdate or using advanced handlers depending on your experience with them:
                          Market sell condition > Submit ExitLong() > ExitLong filled > Submit EnterShortLimit() order.

                          Since part of this sequence depends on the exit long order filled, OnExecution() is the best place to check for this.

                          If you wanted to work only in OnBarUpdate() you would still need to code a sequence with bool flags (or user variables), and a MarketPosition check.
                          Ryan M.NinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by vpzdcv, Today, 02:31 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post vpzdcv
                          by vpzdcv
                           
                          Started by YevhenShynkarenko, Today, 01:22 AM
                          0 responses
                          7 views
                          0 likes
                          Last Post YevhenShynkarenko  
                          Started by ttodua, Today, 12:52 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post ttodua
                          by ttodua
                           
                          Started by ttodua, Today, 12:50 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post ttodua
                          by ttodua
                           
                          Started by mulshah, Yesterday, 11:12 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post mulshah
                          by mulshah
                           
                          Working...
                          X