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

Disable previous SetStopLoss

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

    Disable previous SetStopLoss

    Hi!

    In a strategy I have different StopLoss methods, one including not having a StopLoss at all. The problem is, once I use SetStopLoss for one Order entry, I don't know how to disable it for the next ones..

    Any ideas?

    Kind regards,
    David

    #2
    David,

    Thanks for your note. I am happy to assist you.

    In EnterLong() for example :

    EnterLong(int quantity, string signalName)

    You can tie this to specific stop-losses using the following :

    SetStopLoss(string fromEntrySignal, CalculationMode mode, double value, bool simulated)

    All you do is set the fromEntrySignal to be the same as the signalName in EnterLong().

    Please let me know if I may assist further.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the quick answer. That solved it! :-)

      Now I have another problem...

      The strategy enters a position and places the initial StopLoss correctly. Then on a different chart, with ChartTrader, I can manually move the StopLoss as the position progress... which is great, but when the strategy updates in each OnbarUpdate, it moves back the Stop to the initial position.

      I can see that happening in OnOrderUpdate(): where I can see two different OrderState.PendingChange messages (one for my manual move and another later when the strategy runs on bar close).

      How can I stop the strategy to re-update the StopLoss position once I've changed it manually?

      Comment


        #4
        dpicon,

        This would require the use of ATM strategies instead of the SetStopLoss method.

        You can find a reference sample on using these in Tools > Edit NinjaScript > Strategy > SampleATMStrategy.

        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Thanks for your answer, but the problem with an ATM is that the strategy does not receive updates on any manual StopLoss price changes.

          Is there any way to change an active StopLoss price from within a strategy once is entered?
          In other words if I have:
          Code:
          		EnterLong(qty,"buyMKT");
          		SetStopLoss("buyMKT",CalculationMode.Ticks, 10.0/TickSize),false);
          is there any way to change that StopLoss price later in the code (maybe in OnBarUpdate).

          In asking this because I could detect the manual change of StopLoss in OnOrderUpdate() to a new price and then set again the StopLoss within the strategy to that new price.

          Comment


            #6
            Yes, you can simply call SetStopLoss again in the OnBarUpdate() and move the stop to a new price as desired, please see this reference for an example with code - http://www.ninjatrader.com/support/f...ead.php?t=3222
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Thanks for all your answers... maybe you could answer just another one.. ;-)

              Within the same strategy I enter an order with an attached StopLoss with
              Code:
              SetStopLoss(CalculationMode.Ticks, stopLossTicks);
              . The problem is once I've exited that position... the SetStopLoss settings are still active so I can't enter any other position without a stop loss.

              How can I disable SetStopLoss once Position is flat again, so the next entry does not have a StopLoss?

              Comment


                #8
                dpicon,

                You could set a large stop loss when you detect a profit target or stop loss order filled, or you could generate unique ID's for each entry.

                SetStopLoss(string fromEntrySignal, CalculationMode mode, double value, bool simulated)

                Change fromEntrySignal to match signalName in :

                EnterLong(int quantity, string signalName)

                Something like : EnterLong(1,"Long"+CurrentBar.ToString());

                Would work.
                Adam P.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Salahinho99, 05-05-2024, 04:13 AM
                6 responses
                54 views
                0 likes
                Last Post Salahinho99  
                Started by knighty6508, 05-10-2024, 01:20 AM
                4 responses
                26 views
                0 likes
                Last Post knighty6508  
                Started by OllieFeraher, 05-09-2024, 11:14 AM
                6 responses
                19 views
                0 likes
                Last Post OllieFeraher  
                Started by PaulMohn, 05-02-2024, 06:59 PM
                2 responses
                44 views
                0 likes
                Last Post PaulMohn  
                Started by ETFVoyageur, Today, 02:10 AM
                0 responses
                17 views
                0 likes
                Last Post ETFVoyageur  
                Working...
                X