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

Why SetStopLoss doesn't work sometimes?

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

    Why SetStopLoss doesn't work sometimes?

    I'm using SetStopLoss in OnBarUpdate().
    My Stop level is price calculated, and it's the result of Math.Min(value1, value2).
    I'm plotting it with green dots (for SetStopLoss Short). The price crosses through my Stop level and the Stop Loss doesn't work! See chart attached.

    Thank you
    Attached Files

    #2
    Are you sure the SetStopLoss() is in place? Make sure you called SetStopLoss() before you entered into your position.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I have this problem too.

      I call the SetStopLoss() Method before I enter the Trade an set it to Zero.

      SetStopLoss("long",CalculationMode.Price, 0,true);
      EnterLong("long");

      and then i call the SetStopLoss() Method every BarUpdate, to move it.

      I was debugging with Visual Studio and could seen that the code goes trough the execute. But the StoppLoss is not executed in the Chart. My positions were not closed until a new Order came.

      I´ve done it this way before, but never had problems.

      I Set the SetStopLoss() Method to 0 before the trade that the rate cannot trigger the StopLoss because maybe there is still and old StopLoss. Is this right? Or is there a other possibility to do this?

      Comment


        #4
        Hi FlexW,

        If you are calling SetStopLoss, using the same fromEntrySignal then it should move that stop loss or give you an error.

        Are you getting any error messages?

        Are you using 'long' as the fromEntrySignal when trying to move the stop loss?

        Attached is an example script I have written that does breakeven movements and then starts trailing action. This is done by calling SetStopLoss when i want to move the stop loss.

        Does this script function on your end?
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I achieve no errors. Yes I had the Order namend and used this name at from entry Signal. As I said it had worked for me all the time until now...
          I have no removed the signal names, but it dosen´t works.

          I don´t call the SetStopLoss() Method in the Initialize() Method as you done in your script. I thougt it would be enough to call it in the OnBarUpdate() Method. But I also tried this, it dosen´t work even when I call the Method in the Initalize() Method.

          Comment


            #6
            I tested your script. It works fine. I must anything missing...

            Comment


              #7
              I have now opend a ne ninjaScript file and wrote the code again. Now the StopLoss Order works but it dosen´t work correctly. Now every Position is instandley closed by the StopLoss Order.

              I have done everything like in your script, expect the stop logic..

              Comment


                #8
                Hello FlexW,

                If the stop loss is causing the order to immediately exit, then its probably being set to a price on the wrong side of the market.

                Is the entry long or short?

                What is the price the stoploss is being moved to when the entry is made?

                What is the current price at the time?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I solved the problem. I changed the value from the SetStopLoss() Method where I reset the StopLoss. I changed the price value from 0 to1 for the long stopLoss and for the short stopLoss I changed the value from 0 to 20000(just a point wich is far away from the actual rate).

                  Now everything works like it should. I guess the problem was the value 0 in the setStopLoss() Method. But I´m wondering why it has worked in the past.

                  Comment


                    #10
                    Hello FlexW,

                    If a stop loss is set to 0 and a short order is made, that stop loss would be rejected because it is a buy stop limit below market price.
                    Chelsea B.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by adeelshahzad, Today, 03:54 AM
                    5 responses
                    32 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by stafe, 04-15-2024, 08:34 PM
                    7 responses
                    32 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by merzo, 06-25-2023, 02:19 AM
                    10 responses
                    823 views
                    1 like
                    Last Post NinjaTrader_ChristopherJ  
                    Started by frankthearm, Today, 09:08 AM
                    5 responses
                    22 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    43 views
                    0 likes
                    Last Post jeronymite  
                    Working...
                    X