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

SetTrailStop with EnterLongStopLimit

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

    SetTrailStop with EnterLongStopLimit

    Hi Guys

    I've tried adding a trailing stop (by placing SetTrailStop in the Initialize method) to orders placed by EnterLongStopLimit - but it doesn't seem to work.

    I know this works fine with EnterLong but maybe, for whatever reason, it isn't possible with stop and limit orders.

    Thanks very much in advance for any advice you may have.

    #2
    arbuthnot,

    I am happy to assist you.

    Could you perhaps post more of your code here?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Adam - firstly, that was a superb webinar you gave just now. Thanks very much.

      The instrument is ^DJIA where 1 Dow point = 100 'Ninja' ticks.

      You asked me to post some code. The order entry coding below was supplied by Joydeep and works great. However, the trailing stop in the Initialize method that I entered myself doesn't seem to have any effect.

      Can trails (or just stop losses) be added to EnterLongStopLimit orders?

      Thanks for letting me know and if this is possible, maybe you could show me where I've gone wrong.

      ---

      protected override void Initialize()
      {
      SetTrailStop("", CalculationMode.Ticks, 1000, false);
      CalculateOnBarClose = true;
      }

      Conditions

      {
      EnterLongStopLimit(0, true, 1, Close[0] + LIMITa * TickSize, Close[0] + STOPa * TickSize, "BuyStop");
      }

      Conditions


      {
      EnterShortStopLimit(0, true, 1, Close[0] - LIMITa * TickSize, Close[0] - STOPa * TickSize, "SellStop");
      }

      Comment


        #4
        arbuthnot,

        Thank you for the feedback, it was a good opportunity there. We do those webinars bi-weekly so you can check it out again 2 weeks from yesterday, a Tuesday at 5:00 PM EST. There is also a video in our youtube channel on NinjaScript coding.

        Download NinjaTrader FREE at http://www.ninjatrader.comThis video is a NinjaScript tutorial on creating a strategy based on overbought/oversold conditions of...


        It looks like you are giving your orders a signal name, but not assigning the same name in the SetTrailStop() method.

        The "fromEntrySignal" below :

        SetTrailStop(string fromEntrySignal, CalculationMode mode, double value, bool simulated)

        Must match the "signalName" below :

        EnterLongStopLimit(int quantity, double limitPrice, double stopPrice, string signalName)

        Please let me know if I may assist further.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          That works perfectly. I really should have seen that. I've sent myself to the bottom of the class!

          I'll realize the importance of the signal names for future reference.

          Ref your webinar,you mentioned it would be possible to set up SMS alerts. Could you kindly indicate how this could be done? (By the way, I'm in the UK and I'm wondering if these would work on the networks here.) Thanks again.

          Comment


            #6
            arbuthnot,

            No worries. Getting the hang of everything can take a little while, which is why we have a NinjaScript team--for education. I believe sending a SMS in the UK would be the same as long as your cellular provider offers it, please find a link below describing how to do it.

            How to send text messages from email, via SMS and MMS gateways. A list of SMS & MMS gateways from all carriers to help you text from email.


            You can test it from your own email address and see if it works.

            Please let me know if I may assist further.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Thanks again and for that link re SMS.

              If I can take advantage just one more time in this thread of your kind offer of assistance:

              I use range bars, which are effectively untradeable at the open, as so many appear almost at once adjusting from the day before. Is there a way, in backtesting, to exclude, say,the first half-hour of every trading day? I'm sure it may well be but I can't quite figure it out.

              Much obliged for your further help.

              Comment


                #8
                arbuthnot,

                You could use a time filter or could keep track of the bars.



                Code:
                if( Bars.FirstBarOfSession )
                {
                   time = DateTime.Now;
                   time = time.AddMinutes(30);
                }
                
                if( ToTime(Time[0]) <= ToTime(time))
                {
                return;
                }
                Something like that may work for you.
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks as always, Adam. I'm sure I'll be able to insert that in my strategy.

                  Much obliged.

                  Comment


                    #10
                    Hi everyone

                    What I want to try to achieve is to exclude the first half-hour, say, of the session from a strategy.

                    I've been trying to apply the following code that Adam kindly supplied in this thread simply by pasting it into OnBarUpdate of a strategy :
                    Code:
                    if( Bars.FirstBarOfSession )
                    {    
                    time = DateTime.Now;
                    time = time.AddMinutes(30);
                    } 
                    if( ToTime(Time[0]) <= ToTime(time))
                    {
                    return;
                    }
                    However, it doesn't compile correctly. I've tried adding 'time' as a variable but it doesn't help.

                    Any further advice about this would be greatly appreciated.

                    Comment


                      #11
                      Originally posted by arbuthnot View Post
                      Hi everyone

                      What I want to try to achieve is to exclude the first half-hour, say, of the session from a strategy.

                      I've been trying to apply the following code that Adam kindly supplied in this thread simply by pasting it into OnBarUpdate of a strategy :
                      Code:
                      if( Bars.FirstBarOfSession )
                      {    
                      time = DateTime.Now;
                      time = time.AddMinutes(30);
                      } 
                      if( ToTime(Time[0]) <= ToTime(time))
                      {
                      return;
                      }
                      However, it doesn't compile correctly. I've tried adding 'time' as a variable but it doesn't help.

                      Any further advice about this would be greatly appreciated.
                      What is the error message when it does not compile?

                      Comment


                        #12
                        What is the error message when it does not compile
                        Thanks for getting back to me on this, Koganam.

                        There is the same error message that comes up each time the term 'time' appears:

                        The name 'time' does not exist in the current context
                        I've tried adding

                        Code:
                        int time = 0;
                        but this didn't help.

                        I get the impression that coding to deal with time issues is quite difficult unless you're a real C# expert.

                        Much obliged in advance for any advice on how to crack this.

                        Comment


                          #13
                          The variable "time" needs to be a DateTime type

                          Code:
                          DateTime time;
                          This should allow you to set time to a DateTime object:

                          Code:
                          time = DateTime.Now;
                          MatthewNinjaTrader Product Management

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Carolscogginsi, Yesterday, 10:45 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post Carolscogginsi  
                          Started by RaddiFX, Yesterday, 10:15 AM
                          2 responses
                          15 views
                          0 likes
                          Last Post RaddiFX
                          by RaddiFX
                           
                          Started by patrickmlee007, Yesterday, 09:33 AM
                          2 responses
                          18 views
                          0 likes
                          Last Post patrickmlee007  
                          Started by magnatauren, 08-15-2020, 02:12 PM
                          5 responses
                          208 views
                          0 likes
                          Last Post RaddiFX
                          by RaddiFX
                           
                          Started by rene69851, 05-02-2024, 03:25 PM
                          1 response
                          23 views
                          0 likes
                          Last Post rene69851  
                          Working...
                          X