Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Fixed Stop Strategy

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

    Fixed Stop Strategy

    Hi, I wonder if you could help, I’m trying to amend the price of a Fixed Stop as the price moves into profit.
    So for example when the trade is executed, the Fixed stop is initially set at -30pts, as the price moves up to +32pts the stop amends to +10, and when the price moves to +62 the stop amends to +45pts and so on.
    The problem with the code I have is that when the price moves up to +62 and the stop amends to +45 which is fine, but if the price then drops below +62 again the stop amends back to +10, but strangely if the price falls below 32 the stop still remains at +10???!!! So in effect I only have a stop at +10.

    I have also tried putting a price range in the code (as below)but this also doesn't work.
    How can prevent SetStopLoss from amending downwards?

    Thanks in advance

    if (Position.MarketPosition == MarketPosition.Flat)
    {
    SetStopLoss("", CalculationMode.Ticks, FixedStop, true);
    }

    elseif (Position.MarketPosition == MarketPosition.Long)
    {
    if (GetCurrentAsk() > Position.AvgPrice + 32 * TickSize && GetCurrentAsk() < Position.AvgPrice + 42)
    {
    SetStopLoss("", CalculationMode.Price, (Position.AvgPrice + 10), true);
    }

    if (GetCurrentAsk() > Position.AvgPrice + 62 * TickSize && GetCurrentAsk() < Position.AvgPrice + 77)
    {
    SetStopLoss("", CalculationMode.Price, (Position.AvgPrice + 45), true);
    Last edited by John833; 11-05-2008, 03:54 PM.

    #2
    Hi John833,

    Thanks for your post.

    Your stoploss order modifications will depend on the logic that triggers them, so make sure the conditions deliver the change you intend.

    Your code below is working correctly - profit drops below 62 again, this means the 'profit is bigger than 32 but smaller then 62' rule kicks in and backadjusts the stop to the + 10 level.

    Next when your open profit falls below 32, the stop stays at 10, also correct, since this is the last stop value and you have not defined another condition handling this scenario.

    Please also review this reference sample here -

    Comment


      #3
      Thanks for your reply.
      If you have a look at the code again, when the price drops below 62, the previous statement code still is not true as the price is not between 32 and 42. Even before the price reaches 32 to 42 the stop at 45 should be triggered. So therefore the stop should not amend to 10.
      (Thanks, I already have seen the sample code, that is where I originally got the code from).
      I forgot to add fixedStop = 66, which is the original stop value.

      Any thoughts on why it is doing this?
      Last edited by John833; 11-05-2008, 05:19 PM.

      Comment


        #4
        Hi John833,

        At some point your conditions must evaluate to true, otherwise the stop value would not be adjusted.

        You should use the Print() statement inside your if conditions to see from which condition the order is adjusted, then run your calculations by hand and compare the values and if the conditions reflect your expectation.

        You can also enable TraceOrders = True in the Initialize section, this will then help you seeing order changes in the Output window of the Control Center.

        Here are three links dealing with debugging:

        1. http://www.ninjatrader-support2.com/...ead.php?t=9825

        2. http://www.ninjatrader-support2.com/...ead.php?t=3418

        3. http://www.ninjatrader-support2.com/...ead.php?t=3627




        Originally posted by John833 View Post
        Thanks for your reply.
        If you have a look at the code again, when the price drops below 62, the previous statement code still is not true as the price is not between 32 and 42. Even before the price reaches 32 to 42 the stop at 45 should be triggered. So therefore the stop should not amend to 10.
        (Thanks, I already have seen the sample code, that is where I originally got the code from).
        I forgot to add fixedStop = 66, which is the original stop value.

        Any thoughts on why it is doing this?

        Comment


          #5
          I already use print statements and trace orders.
          The output shows when the price is above 65 the stop amends to +45, when the price falls below 65 even though the price is not between +32 and +42 the stop still amends to +10.

          This is my point, the command SetStopLoss, I understand will only change when it is told to change, therefore, this should not happen.

          Is my understanding of SetStopLoss incorrect?

          Comment


            #6
            Hi John833,

            No, your understanding of SetStopLoss() is correct, it will only change the Stop Value, when one of your conditions tell it to do so.

            Here is your code snippet with the Print() statements included, please use this to debug and also please post a screenshot of your output window here. Thanks!

            Code:
             
            [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Position.MarketPosition == MarketPosition.Flat)[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] FixedStop = [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]66[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]SetStopLoss([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], CalculationMode.Ticks, FixedStop, [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"The current Stop value is "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + FixedStop.ToString());[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (Position.MarketPosition == MarketPosition.Long)[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"Ask Price: "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + GetCurrentAsk() + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]" AvgPrice: "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + Position.AvgPrice);[/SIZE][/FONT]
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (GetCurrentAsk() > Position.AvgPrice + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]32[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] * TickSize && GetCurrentAsk() < Position.AvgPrice + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]42[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]SetStopLoss([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], CalculationMode.Price, (Position.AvgPrice + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]), [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"The current Stop value is "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + (Position.AvgPrice + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]).ToString());[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] (GetCurrentAsk() > Position.AvgPrice + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]62[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] * TickSize && GetCurrentAsk() < Position.AvgPrice + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]77[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
            [SIZE=2][FONT=Courier New]SetStopLoss([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], CalculationMode.Price, (Position.AvgPrice + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]45[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]), [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"The current Stop value is "[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] + (Position.AvgPrice + [/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]45[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]).ToString());[/SIZE][/FONT]
            [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
            [/SIZE][/FONT]
            Originally posted by John833 View Post
            I already use print statements and trace orders.
            The output shows when the price is above 65 the stop amends to +45, when the price falls below 65 even though the price is not between +32 and +42 the stop still amends to +10.

            This is my point, the command SetStopLoss, I understand will only change when it is told to change, therefore, this should not happen.

            Is my understanding of SetStopLoss incorrect?
            Last edited by NinjaTrader_Bertrand; 11-06-2008, 09:42 AM.

            Comment


              #7
              thanks Bertrand, by the way how do I post from the output window, when I right click the only function I have is 'clear'?

              Comment


                #8
                Hi John833,

                You can simply take a screenshot with the PrintScreen command and save it in Paint to post it here. Thanks!


                Originally posted by John833 View Post
                thanks Bertrand, by the way how do I post from the output window, when I right click the only function I have is 'clear'?

                Comment


                  #9
                  Hi Bertrand, I seem to have figured out my problem from a different perspective. Instead of using SetStopLoss, I’ve used IOrder for each of my stop order limits which I think works better for my strategy.
                  Thanks again for your help.
                  Last edited by John833; 11-07-2008, 10:37 AM.

                  Comment


                    #10
                    You are welcome John! Great you got your issue solved.


                    Originally posted by John833 View Post
                    Hi Bertrand, I seem to have figured out my problem from a different perspective. Instead of using SetStopLoss, I’ve used IOrder for each of my stop order limits which I think works better for my strategy.
                    Thanks again for your help.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    636 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    366 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    107 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    568 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    571 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X