Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SetStopLoss Not Enforced

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

    SetStopLoss Not Enforced

    NinjaTraders,
    While using the Strategy Analyzer I noticed that my StopLoss and Profit Target are not being enforeced. I used a custom method to set them, see below
    Using print statements I can see that they are being calculated correctly and the stop is being adjusted to the breakeven level correctly later in the program.
    However I am not stopped out when they are hit.
    Any ideas what to look for?

    private void GoLong()
    {

    SetProfitTarget("One Target Up", CalculationMode.Price, Close[0]+targ*TickSize);
    SetStopLoss(
    "One Target", CalculationMode.Price, Close[0]-(stopset*TickSize) , false);
    stoploss=Close[
    0]-stopset;
    EnterLong(Num,
    "Long Entry");
    DrawTriangleUp(
    "My triangle up" + CurrentBar, false, 0, High[0] + 4 * TickSize, Color.Lime);
    Print(
    " Stoploss is " + stoploss.ToString());
    }

    Mike

    #2
    Hello BigMike,

    Thank you for your post.

    To find out more about what's going on, you should add the following line to your Initialize() method.
    TraceOrders = true;

    Before you start your strategy click Tools > Output Window to see debug information regarding your orders.

    What may be happening is your stop loss is being adjusted somewhere else in your code.
    Last edited by NinjaTrader_RyanM1; 04-07-2010, 04:15 PM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Continued

      RyanM,
      I put in the trace order and It showed the Tragets and stops being placed. It showed the position being reversed correctly.
      I used a 5 tick stop on theYM, So with one contract I should have a $25 loss at most. I am getting very much higher than that,Hundreds more, so the stop is not enforced.
      Here is a part of the trace:
      Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='OneTarget'Mode=Price Value=10831 Currency=0 Simulated=False
      Entered internal PlaceOrder() method at 3/31/2010 7:45:07 AM Action=SellShort OrderType=Market Quanity=1 Limitprice=0 StopPrice=0 SignalName='Short Entry' FromEntrySignal="

      Still at a loss(Literally)
      Mike

      Comment


        #4
        Mike, have you tried other calc modes, too? Are you resetting those stops and targets properly when you're in a flat strategy position?

        Comment


          #5
          Continued

          Ryan,
          I tried Tick Mode with same result, Stops are set but not enforced, I also reset the stops when flat, per the reference sample Josh posted, with same result. I set the number of trades to one per day so there would be no possible conflict with reversing postion, and the stops and target to small values. The trades go on til they are forced shut at end of trading period withlLosses and profits far above the set values.
          Are there logic issues involved does ProfitTarget need to be declared before the other etc.?
          Has this occurred in the past? I didn't see any posts directly related.
          This has me completely mystified.

          Mike

          Comment


            #6
            Hello BigMike,

            Are you calling GoLong() more than once?

            If you are calling it while you are in a position, it would update the stop loss according to what's stated here:
            stoploss=Close[0]-stopset;
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              I'll keep trying

              Ryan,
              Here is the call I use:
              if (ITrendModified(Alpha).TriggerPlot[0] > ITrendModified(Alpha).TriggerPlot[1]
              && FisherTransform(Close,period)[
              0] > FisherTransform(Close,period)[1]
              && Position.MarketPosition == MarketPosition.Flat)
              {
              GoLong();
              PrintWithTimeStamp(
              "Initial Long Taken");
              }
              or I use:
              if (ITrendModified(Alpha).TriggerPlot[0] > ITrendModified(Alpha).TriggerPlot[1]
              && Position.MarketPosition == MarketPosition.Short
              && FisherTransform(Close,period)[
              0] > FisherTransform(Close,period)[1])
              {
              ExitShort(
              "Exit Short Now","Short Entry");
              GoLong();
              PrintWithTimeStamp(
              "Reversed to Long Position");
              }
              And similar for short position.
              So it doesn't look like it is calling GoLong when it is already long.

              Mike

              Comment


                #8
                The Plot Thickens

                Ryan,
                I put in a few more print statements and have found that when an entry comes from the initial long or initial stop an enrty price of 0 is assigned to Position.AvgPrice and so the stops are set at a value of +/- 0 not around the actual entry price. But, when the entry comes from the reversal the stop values printed out are correct. What is causing the 0 entry?
                Thanks for your efforts on this.
                Mike

                Comment


                  #9
                  Continued

                  Ryan,
                  If I look at the chart of the trades in Analyzer they all show the correct entry price for all trades.There is a discrepancy between the charts and the output window. I used the following print commands to check results.
                  profitwatch=Position.AvgPrice+targ;
                  stopwatch=Posistion.AvgPrice-stopset;
                  Print("Profit Target is "+profitwatch.ToString());
                  Print("Entry Price is "+Position.AvgPrice.ToString());
                  Print("Stop Loss is"+stopwatch.Tostring());

                  Mike

                  Comment


                    #10
                    Hi Mike,

                    A couple of your replies came in while I was working on one. I deleted that message.

                    What might be causing this is calling ExitShort() and the GoLong() method in the same block.

                    By default entries will reverse a position so you want to either exclude the ExitShort() for reversals or separate them.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      Continued

                      Ryan,
                      I took out the Exits and the same problem persists.
                      Am I missing something before the initial trade is taken? still get the 0 entry price in the output window and stops are still being ignored.

                      Comment


                        #12
                        It probably depends on where the print statments are. If you aren't in a position then Pos.Avg price will be 0.

                        You also can't check Position.Avg price in the same block that you use to place orders.

                        You can mail your strategy to [email protected]
                        I'll take a look and see if I'm able to reproduce what you're seeing.
                        Ryan M.NinjaTrader Customer Service

                        Comment


                          #13
                          Way To Go

                          Ryan,
                          The fix you sent me worked. It was the mismatched names of the entry signal and stoploss.
                          Thank you for your patience with me and putting so much effort into what turned out to be small problem.

                          Mike

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by NullPointStrategies, Yesterday, 05:17 AM
                          0 responses
                          54 views
                          0 likes
                          Last Post NullPointStrategies  
                          Started by argusthome, 03-08-2026, 10:06 AM
                          0 responses
                          130 views
                          0 likes
                          Last Post argusthome  
                          Started by NabilKhattabi, 03-06-2026, 11:18 AM
                          0 responses
                          72 views
                          0 likes
                          Last Post NabilKhattabi  
                          Started by Deep42, 03-06-2026, 12:28 AM
                          0 responses
                          44 views
                          0 likes
                          Last Post Deep42
                          by Deep42
                           
                          Started by TheRealMorford, 03-05-2026, 06:15 PM
                          0 responses
                          49 views
                          0 likes
                          Last Post TheRealMorford  
                          Working...
                          X