Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sample Script/Code to set initial stop loss and when it reverses also set the stop...

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

    Sample Script/Code to set initial stop loss and when it reverses also set the stop...

    Hi:

    Anyone can respond...

    Could you post or include Sample Script/Code to set initial stop loss but also when a reversal takes place it sets a stop loss for the other direction as well?

    Thanks...

    Greg

    #2
    Hello Greg,

    Thank you for your post.

    If you use SetStopLoss() in the Initialize() method it will be the Stop Loss regardless of the position (long or short).

    For information on SetStopLoss() please visit the following link: http://www.ninjatrader.com/support/h...etstoploss.htm

    Please let me know if I may be of further assistance.

    Comment


      #3
      I do have that now.

      It works fine when this initial entry is executed and the stop loss it places.

      However, on a reversal where I have:

      Code:
      {
                          Print("Reverse BuyMkt");
                          EnterLong(DefaultQuantity, "Reverse BuyMkt"); 
      }
      The above code is when it does make the opposite position that I would be in (here a Short) exit and cancels the initial stop loss fine. The it enters the reversal position just fine too. BUT, the only thing that is not working is that the reverasal stop loss is not placed (like the initial entry). How do I fix that?

      Also...would I need to make it "ExitShort" first and then "EnterLong"...

      Anyway, there has to be a easy fix for this...

      Thanks...G

      Originally posted by NinjaTrader_PatrickH View Post
      Hello Greg,

      Thank you for your post.

      If you use SetStopLoss() in the Initialize() method it will be the Stop Loss regardless of the position (long or short).

      For information on SetStopLoss() please visit the following link: http://www.ninjatrader.com/support/h...etstoploss.htm

      Please let me know if I may be of further assistance.
      Last edited by birdog; 03-25-2013, 01:38 PM.

      Comment


        #4
        Hello Greg,

        Thank you for your response.

        Please provide the code used to place the Stop Loss, the condition used to determine the reversal and the original entry order and it's condition.

        Comment


          #5
          Originally posted by birdog View Post
          I do have that now.

          It works fine when this initial entry is executed and the stop loss it places.

          However, on a reversal where I have:

          Code:
          {
                              Print("Reverse BuyMkt");
                              EnterLong(DefaultQuantity, "Reverse BuyMkt"); 
          }
          The above code is when it does make the opposite position that I would be in (here a Short) exit and cancels the initial stop loss fine. The it enters the reversal position just fine too. BUT, the only thing that is not working is that the reverasal stop loss is not placed (like the initial entry). How do I fix that?

          Also...would I need to make it "ExitShort" first and then "EnterLong"...

          Anyway, there has to be a easy fix for this...

          Thanks...G
          If you are entering and using SetStopLoss(), I am pretty sure that you are not reversing at all with your construct. The rules for managed entries preclude it. You can only reverse on the fly, if you do not have any protective order in place. Is your protective order by any chance a simulated order? Is COBC true or false in your setup?

          Comment


            #6
            Hey Kog...

            How are ya?

            There is no simulated stops. I have it on COBC True.

            But, after looking closer, all I had to do is be sure the description on the SetStopLoss() in the Initialize() sections below had the exact same descriptor like "BuyMkt" for it to work on both the initial entries and the reversal entries...so, I can happily report that that fixed the problem...before I had slightly different names for each entry...I guess I could have a different SetStopLoss() string in the Initialize with a different name and the amount of ticks of stop I would want if I wanted them to have different names right?:

            Code:
            SetStopLoss("[B][COLOR=Red]BuyMkt[/COLOR][/B]", CalculationMode.Ticks, LongStop, false);
            matches entries like:

            Code:
            {
                                Print("BuyMkt"); 
                                EnterLong(DefaultQuantity, "[COLOR=Red][B]BuyMkt[/B][/COLOR]"); 
            }
            I also tested in on COBC False...with Market Replay too...I can confirm that is ALSO works setting the stop loss on the initial and reversal now too...big smile!!!

            Originally posted by koganam View Post
            If you are entering and using SetStopLoss(), I am pretty sure that you are not reversing at all with your construct. The rules for managed entries preclude it. You can only reverse on the fly, if you do not have any protective order in place. Is your protective order by any chance a simulated order? Is COBC true or false in your setup?

            Comment


              #7
              Patrick...

              After looking closer, all I had to do is be sure the description on the SetStopLoss() in the Initialize() sections below had the exact same descriptor like "BuyMkt" for it to work on both the initial entries and the reversal entries...so, I can happily report that that fixed the problem...before I had slightly different names for each entry...I guess I could have a different SetStopLoss() string in the Initialize with a different name and the amount of ticks of stop I would want if I wanted them to have different names right?:

              Code:
              SetStopLoss("[B][COLOR=Red]BuyMkt[/COLOR][/B]", CalculationMode.Ticks, LongStop, false);
              matches entries like:

              Code:
              {
                                  Print("BuyMkt"); 
                                  EnterLong(DefaultQuantity, "[COLOR=Red][B]BuyMkt[/B][/COLOR]"); 
              }


              Originally posted by NinjaTrader_PatrickH View Post
              Hello Greg,

              Thank you for your response.

              Please provide the code used to place the Stop Loss, the condition used to determine the reversal and the original entry order and it's condition.

              Comment


                #8
                Greg,

                Yes, that's correct - you can add additional signal names to your set stop loss for each unique entry name
                MatthewNinjaTrader Product Management

                Comment


                  #9
                  Wonderful!

                  Thanks...

                  G
                  Originally posted by NinjaTrader_Matthew View Post
                  Greg,

                  Yes, that's correct - you can add additional signal names to your set stop loss for each unique entry name

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by argusthome, Yesterday, 10:06 AM
                  0 responses
                  22 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  19 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  14 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post TheRealMorford  
                  Started by Mindset, 02-28-2026, 06:16 AM
                  0 responses
                  41 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Working...
                  X