Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Disable

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

    Disable

    I looking for the best way to Disable a Strategy when Trailing Stop is hit.
    Can you help?

    #2
    Hello girda,


    You can use Disable() to ensure your strategy is disabled when your trailing stop is hit. Please note that using Disable() will require your unlock your code and enter the code manually. There would also no way to re-enable the strategy from the code.
    for example:
    Code:
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]        [/SIZE]
     [FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]OnBarUpdate()[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]       {    [/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]            SetTrailStop(CalculationMode.Ticks,[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]12[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]            [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](Position.MarketPosition == MarketPosition.Long)[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]            {[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]            trailing =[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];  [/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]            }[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]            [/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]            [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](Position.MarketPosition == MarketPosition.Flat && trailing ==[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]            {[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]            Disable();[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]            }[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [COLOR=#000000][FONT=Tahoma][LEFT][FONT=Courier New][SIZE=2]         }[/SIZE][/FONT][/LEFT][/FONT][LEFT][/LEFT][/COLOR][LEFT][/LEFT]
    [/FONT][/COLOR]

    Here are the Disable(), MarketPosition, and SetTrailStop() Help Guides to assist you further.
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      Where and how did you name "trailing"

      Comment


        #4
        Hello girda,


        "Trailing" is a bool variable. However, you could also could use OnExecution() to disable the strategy when there is a fill of an order.
        Here is the OnExecution() Help Guide to assist you further. I have included an example of this below.


        Code:
        [LEFT][FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]Initialize()[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]        { [/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]            SetTrailStop([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"Trail stop"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],CalculationMode.Price, Position.AvgPrice,[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]false[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]        }[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]
        [/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]            [/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]       [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]OnBarUpdate()[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]       {   [/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]            [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#008000]// Enter the conditions you would like to use here.[/COLOR][/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]            [/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]         }[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]
        [/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]      [/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]       [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]protected[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]override[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]void[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]OnExecution(IExecution e)[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]            {[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]            [/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2](e.Name ==[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"Trail stop"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]            {[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]            Disable();[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]            }}[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000FF][/COLOR][/SIZE][/FONT]
        [/LEFT]
        Shawn B.NinjaTrader Customer Service

        Comment


          #5
          Hello ShawnB,
          The method you're proposing came in force as soon as the stop is in.
          What I'm looking for is a method who trigger an action when the stop is hit.
          Can you help me in that way?

          Comment


            #6
            Hello,
            If by hit you are meaning the stop order is filled then creating events in OnExecution() would do this for you. OnExecution() is called on an incoming execution. An execution is another name for a fill of an order. What ShawnB has provided in his example does this.
            If this is not what you are looking for please clarify further on what you are wanting it to do and what you mean by "the stop is hit."
            Cody B.NinjaTrader Customer Service

            Comment


              #7
              Sorry I have to learn the Ninja language.
              By "stop is hit" I mean the stop order is filled.
              I don't know why but contrary to your experience in my script the action is triggered at the stop entry. Maybe I missed some logic but it's what happened.

              Comment


                #8
                Hello,
                Just to ensure we are on the same page here when you are saying the strategy is disabling on the stops entry are you meaning the stop order is submitted and waiting to fill?
                If so please attach your strategy so I may fully look at the logic of the strategy, if you are not comfortable posting this on the forum you can email this to us at platformsupport[AT]ninjatrader[DOT]com. You can attach your Strategy to your response by going to File > Utilities > Export NinjaScript > Export selected source files > select your Strategy> select the right arrow > Export. The file will be located under (My) Documents\NinjaTrader 7\bin\Custom\ExportNinjaScript.
                Cody B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by cls71, Today, 04:45 AM
                0 responses
                1 view
                0 likes
                Last Post cls71
                by cls71
                 
                Started by mjairg, 07-20-2023, 11:57 PM
                3 responses
                213 views
                1 like
                Last Post PaulMohn  
                Started by TheWhiteDragon, 01-21-2019, 12:44 PM
                4 responses
                544 views
                0 likes
                Last Post PaulMohn  
                Started by GLFX005, Today, 03:23 AM
                0 responses
                3 views
                0 likes
                Last Post GLFX005
                by GLFX005
                 
                Started by XXtrader, Yesterday, 11:30 PM
                2 responses
                12 views
                0 likes
                Last Post XXtrader  
                Working...
                X