Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why does SetStopLoss survive?

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

    Why does SetStopLoss survive?

    Hi guys,

    I am a rookie here with little programming experience. Still I am able to create some startegies.

    Could anyone please tell me why does SetStopLoss() order survive even after the position it had belonged to has already been closed?
    let me discribe:

    1,I open a position ( let say a long position) and set a stop loss for it (by using SetStopLoss)
    2, The candles hit my SL, and the position is over.(But the StopLoss apparently survives!)
    3, Later, whenI want to open another position it activates the (previous) SL if the price is below the previous SL level. So the position opens and closes whithin the same seconds.

    Why is that? How can I avoid it? Why don't SL orders just cease to exist after their position is history?


    Regards

    ternero
    Last edited by ternero; 08-12-2009, 09:56 AM.

    #2
    Hi ternero, stop losses should cease to exist when their position is history. What is the code you're using to enter positions and set the stop losses?
    AustinNinjaTrader Customer Service

    Comment


      #3
      Hi Ninja Trader Austin,
      Thank you for your prompt answer. Let me answer your question by displaying my "strategy's" OnBarUpdate part.
      It works very well at the very beginning of the chart but as time goes by it is impossible to open new positions, as they seem to be instantly killed by previous SL and TP orders.

      Do I miss something? If yes, what could be the missing part?

      Regards,

      ternero


      Comment


        #4
        I can only post it in two parts:
        Part one:

        protectedoverridevoid OnBarUpdate()
        {

        if ((Position.MarketPosition==MarketPosition.Flat)&& (RSI(14, 1)[4])<30)

        {
        EnterLong(
        "lo");
        longkotes=
        0;
        }

        if
        ((Position.MarketPosition==MarketPosition.Long) && RSI(14,1)[0]<28)

        {
        EnterLong(
        "lo");
        longkotes++;
        }
        Last edited by ternero; 08-12-2009, 02:26 PM.

        Comment


          #5
          part two:

          if (Position.MarketPosition==MarketPosition.Long)
          {
          BackColor=Color.DarkSeaGreen;
          double PnL=Math.Round(Position.GetProfitLoss(Close[0], PerformanceUnit.Points),5 );
          double stopL= Math.Round((Position.AvgPrice+0.0005),5);
          double celarL= Math.Round((Position.AvgPrice+0.0015),5);
          if (PnL>0.0005)
          { SetStopLoss(
          "lo", CalculationMode.Price, stopL, true);
          SetProfitTarget(
          "lo", CalculationMode.Price, celarL);
          DrawText(
          "My textL" + CurrentBar, stopL.ToString(), 0, stopL, Color.Blue);
          DrawText(
          "My textL1" + CurrentBar, celarL.ToString(), 0, celarL, Color.Cyan);

          }

          if (longkotes>10)

          {
          BackColor=Color.YellowGreen;
          if (PnL>=0.00)
          {
          ExitLong();

          }
          }

          }

          }





          Many thanks.

          Comment


            #6
            Hi there, if you set TraceOrders = true in initialize, you can see what the strategy is "thinking". TraceOrders will print all order information to the output window, and if your orders are being ignored it will tell you why. Here is a great post by Josh that explains TraceOrders.

            In addition, can you try "resetting" your stop loss values when the strategy is flat? Something like this:
            Code:
            if (Position.MarketPosition == MarketPosition.Flat)
                        {
                            SetStopLoss("lo", CalculationMode.Price, 0);
                        }
            AustinNinjaTrader Customer Service

            Comment


              #7
              Thanks, I need a fresh mind for this trace order thing, and here is almost midnight. I'll do it tomorrow.

              Comment


                #8
                Hi there,

                What is "OCO paired order"?
                Trace order says it has been cancelled a number of times but I don't know what's the meaning of "OCO paired order".

                */
                And trace order also mentions SetStopTarget() Method which a bit confusing for me, is it a SL or a TP? If the latter, then why it is marked as "false" when its syntax does not contain a bool variable?
                */

                Anyway, it somehow does not seem working properly for me.(Most probably my fault, I admit) If I include the recommended part, (below) then SL and TP orders are apparently ignored from the very beginning (even when we do have positions and MarketPositions are NOT flat)


                if (Position.MarketPosition == MarketPosition.Flat)
                {

                SetStopLoss(
                "lo", CalculationMode.Price, 0, true);SetProfitTarget("lo", CalculationMode.Price, 0);

                }

                If I exlude it, then no SL or TP orders are ignored BUT the original problem occurs.

                Btw is copy and paste from Output Window possible?

                Thanks and regards,

                ternero
                Last edited by ternero; 08-13-2009, 03:35 AM.

                Comment


                  #9
                  OCO paired order means two orders were submitted with the same string for the OCO argument of the order. When that happens, if one order is filled/canceled the other order will be canceled as well.

                  The "reset" section of the code is half correct. The stop price should be set to 0 so it will never be hit. Likewise, the target portion should be set to an extremely high value so it won't be hit. Then, as your position goes from flat to not flat, these far-away values can be adjusted as necessary.

                  To copy and paste from the output window, just select the text you want and then hit Ctrl + C to copy and Ctrl + V to paste into your favorite editor. Can you copy the output here so I can see what is going on?
                  AustinNinjaTrader Customer Service

                  Comment


                    #10
                    Thanks, with the new corrections everything looks much better. Some minor mistakes still happen:

                    2009.07.28. 17:35:00 Entered internal PlaceOrder() method at 2009.07.28. 17:35:00: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='lo' FromEntrySignal=''
                    2009.07.28. 17:35:00 Cancelled pending exit order, since associated position is closed: Order='NT-00056/Sim101' Name='Profit target' State=Working Instrument='$EURUSD' Action=Sell Limit price=1,4241 Stop price=0 Quantity=1 Strategy='aaaaaaaaa' Type=Limit Tif=Gtc Oco='NT-00040' Filled=0 Fill price=0 Token='0985a9925ca2440d891e4e1bc2eb9cf3' Gtd='2099.12.01. 0:00:00'
                    2009.07.28. 17:35:00 Cancelled OCO paired order: BarsInProgress=0: Order='NT-00056/Sim101' Name='Profit target' State=Cancelled Instrument='$EURUSD' Action=Sell Limit price=1,4241 Stop price=0 Quantity=1 Strategy='aaaaaaaaa' Type=Limit Tif=Gtc Oco='NT-00040' Filled=0 Fill price=0 Token='0985a9925ca2440d891e4e1bc2eb9cf3' Gtd='2099.12.01. 0:00:00'
                    Last edited by ternero; 08-13-2009, 08:45 AM.

                    Comment


                      #11
                      In which part of this output does the "minor mistake" occur?
                      AustinNinjaTrader Customer Service

                      Comment


                        #12
                        Sorry, I corrected my previous entry. Usually everything is fine but for example around 2009.07.28.17.35 some "minor mistake" happens

                        What you can see below is funny thing, I have already 4 open long positions and according to the script EntriesPerDirection=5000)

                        Still no new position can open later as they are instatly killed by stop losses.
                        I use the script I posted here yesterday.
                        Last edited by ternero; 08-13-2009, 08:51 AM.

                        Comment


                          #13
                          Can you please export the full script (File -> Utilities -> Export NinjaScript. Select your strategy and give a file name and hit Export) and attach it to a post here? That way I can be sure I'm running exactly what you're running and I can take a closer look.
                          AustinNinjaTrader Customer Service

                          Comment


                            #14
                            Done.

                            Please run it on the EURUSD (5 MIN), between 2009.07.27- and today,
                            you'll see the problem around 2009.07.28. 15.15 -17.45
                            Thanks;

                            Sorry 2009 and NOT 2008
                            Attached Files
                            Last edited by ternero; 08-13-2009, 09:03 AM.

                            Comment


                              #15
                              I've been looking at your script, and I'm not sure I understand the problem. To clarify: are positions instantly being closed because of the stop loss? Could you strip down the strategy to show the bare essentials of the issue?

                              Also, during my testing, I noticed something that said the stop loss wasn't recognized because the stop price is 0. Can you try changing that value to 0.0001?
                              Code:
                              **NT** Calculated stop order price for strategy 'aaaaaaaaa' was smaller/equal 0. No stop order placed.
                              AustinNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              580 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              335 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              102 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              554 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              552 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X