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

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, 09: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 alifarahani, Today, 09:40 AM
          6 responses
          29 views
          0 likes
          Last Post alifarahani  
          Started by Waxavi, Today, 02:10 AM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by Kaledus, Today, 01:29 PM
          5 responses
          13 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by Waxavi, Today, 02:00 AM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_LuisH  
          Started by gentlebenthebear, Today, 01:30 AM
          3 responses
          17 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Working...
          X