Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stops don't always work?

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

    Stops don't always work?

    Hello...i being backtesting my strategies - and i have two stops that are supposed to be modified after a certain price level is reached. But the trouble is the stops don't always work - somedays the trades get stopped out where i want them to - and other days the stops are never placed. Is there something wrong with my code? (i debugged my code and i traced my orders and i don't see what's wrong with it - especially since my stops work on some days)

    else if (Position.MarketPosition == MarketPosition.Long)
    {
    if (High[0] >= Position.AvgPrice + 7 * TickSize){
    SetStopLoss("Long",CalculationMode.Price, Position.AvgPrice - 7 * TickSize,false);
    if (High[0] >= Position.AvgPrice + 10 * TickSize){
    SetStopLoss("Long",CalculationMode.Price, Position.AvgPrice, false);
    }
    }
    }

    #2
    You need to make sure that you are actually entering your if statements. Check your Position.AvgPrice value along with the High[0] values. Your code looks fine with a quick glance.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thank you Josh for your help....i used the print command and my if statements are working ok - i can see the high price and ave price in the output window. But the problem is:

      1. when the price goes to aveprice + 7: the stop moves to -7.
      2. then when the price goes to ave price + 10: stop moves to breakeven.
      3. but if the price goes back to ave price + 7: the stop is moving back to -7 (this is reason why my stops aren't getting placed on some trades, but work on other trades)

      So...is there any way i can prevent step 3 from happening...for instance once the price reaches +10 ticks - i want the stop from 2nd if statement to be placed and even if the price goes back to +7 ticks - i don't want the 1st if statement to be read. how can i accomplish this?



      thank you for your time,
      Samuel








      else if (Position.MarketPosition == MarketPosition.Long)
      {
      if (High[0] >= Position.AvgPrice + 7 * TickSize){
      SetStopLoss("Long",CalculationMode.Price, Position.AvgPrice - 7 * TickSize,false);
      if (High[0] >= Position.AvgPrice + 10 * TickSize){
      SetStopLoss("Long",CalculationMode.Price, Position.AvgPrice, false);
      }
      }
      }
      Last edited by samuelg; 03-22-2008, 08:52 AM.

      Comment


        #4
        That is expected behavior of how you coded it. If you want to prevent it from reentering at the lower -7 level just use an intermediate variable that starts off as true. When your stop loss raises to break even make the variable false. If the variable is false don't do the -7 if-statement.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          thank you very much Josh for your help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by tgn55, Today, 09:51 PM
          0 responses
          1 view
          0 likes
          Last Post tgn55
          by tgn55
           
          Started by cxxazssx, Today, 09:45 PM
          0 responses
          1 view
          0 likes
          Last Post cxxazssx  
          Started by southpacific001, 02-26-2021, 09:25 PM
          14 responses
          65 views
          0 likes
          Last Post REI140205  
          Started by punkiy2111, Today, 05:22 PM
          0 responses
          3 views
          0 likes
          Last Post punkiy2111  
          Started by secrettrader, Today, 03:36 PM
          0 responses
          8 views
          0 likes
          Last Post secrettrader  
          Working...
          X