Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strategy works on chart but not in Analyzer

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

    Strategy works on chart but not in Analyzer

    Hi - I have a simple test strategy that looks fine when I apply background colors to a chart (so I know it's effective). But when I adapt it to place trades, with code reading as follows, no trades are entered at all on the Analyzer.

    // Condition set 1
    if (Rising(WMA(Typical, WMAD)) == true)
    {
    EnterLongStopLimit(Size, LIMITa, STOPa, "up");
    }

    // Condition set 2
    if (Falling(WMA(Typical, WMAD)) == true)
    {
    EnterShortStopLimit(Size, LIMITa, STOPa, "down");

    I'd guess there's something wrong with how the trades are entered (but this was done completely in the Wizard though).

    Thanks for any ideas you may have so I can work out what I'm doing wrong!

    Much obliged.

    #2
    Hello,

    If you switch to Market Orders using EnterLong or EnterShort, does it take the trades?

    It might be that the StopLimit orders are not meeting the requirements to fill. You should double check the LIMIT and STOP values you are using and ensure that they are at the correct values.

    If you were able to draw these values and they look correct, it could also be that the order is canceling before it fills.

    The default behavior is to cancel orders if the condition is no longer true after the next bar is evaluated, however it possible to change this to keep the orders alive. Please see our Reference Sample on that topic should that be the case:

    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks, Matthew, for your very comprehensive reply.

      Yes, Analyzer does take the trades if I enter EnterLong or EnterShort.

      The LIMIT and STOP values I've used seem very reasonable. For example, with the ES, I've set these both to 4 ticks.

      I've looked at the SampleLiveUntilCancelled strategy you suggested and I'm trying to work out how it can help me. I have to say that the order the parameters in EnterLongLimit, for example, as used in SampleLiveUntilCancelled strategy seem different from those I've been using. The 'LiveUntilCancelled' parameter seems to be in the 2nd place in this but in 5th place in Help.

      My essential problem is this: I'd like to enter stops and limits on strategies that depend on rising/falling conditions.

      Could you give me any further pointers as I'm a bit confused by exactly how to use LiveUntilCancelled.

      Thanks very much in advance.

      P.S. Some of the links in SampleLiveUntilCancelled are no longer valid, such as:

      Comment


        #4
        Hello arbuthnot,
        Thanks for your post and I am replying for Matthew.

        A limit order will be cancelled if it is not filled on the bar on which it is submitted. In your code your orders are not getting filled and thus getting cancelled. But if you use the overload

        EnterLongStopLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, double stopPrice, string signalName)


        and set the liveUntilCancelled to true, then the order will not be cancelled on a new bar. However the said overload is for experienced programmers only and you cannot code it via the Strategy Wizard. You have to unlock your code and recode the Entry() codes.

        Please let me know if I can assist you any further.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          And to add, a basic code will look like:
          Code:
          protected override void OnBarUpdate()
          {
              // Condition set 1
              if (Rising(WMA(Typical, 14)) == true)
              {
                  EnterLongStopLimit(0, true, 1, Close[0] + 10 * TickSize, Close[0] + 10 * TickSize, "BuyStop");
              }
          
              // Condition set 2
              if (Falling(Typical) == true)
              {
                  EnterShortStopLimit(0, true, 1, Close[0] - 10 * TickSize, Close[0] - 10 * TickSize, "SellStop");
              }
          }
          Also please watch the webinar as present by Josh at a popular forum recently. http://www.youtube.com/watch?v=riLnopGNGzc

          Please let me know if I can assist you any further.
          JoydeepNinjaTrader Customer Service

          Comment


            #6
            I'm much obliged to you, Joydeep, for all that information and the code. I feel confident I'll be able to work most of it out from here with a lot of study in the right places.

            If there's something I really can't work out, I'll come to back to you.

            By the way, I watched Josh's webinar yesterday as well as Adam's one. I think they're both terrifically helpful - but there is a great deal to digest and work on.

            As a teaching tool, videos are a far more powerful than text, in my opinion.

            I hope you'll be making more webinars on NinjaScript in the near future.

            Many thanks to you and all the team.

            Comment


              #7
              Originally posted by arbuthnot View Post
              I'm much obliged to you, Joydeep, for all that information and the code. I feel confident I'll be able to work most of it out from here with a lot of study in the right places.

              If there's something I really can't work out, I'll come to back to you.

              By the way, I watched Josh's webinar yesterday as well as Adam's one. I think they're both terrifically helpful - but there is a great deal to digest and work on.

              As a teaching tool, videos are a far more powerful than text, in my opinion.

              I hope you'll be making more webinars on NinjaScript in the near future.

              Many thanks to you and all the team.
              Hello,

              Thank you for watching the NinjaScript Tips and webinar! We do plan on releasing more videos in the future, but I have no ETA yet on the next one. Feel free to contact us any time, or post to the support forum if you have any educational questions. We also monitor the forum so one of us will respond.

              Please don't hesitate to contact us should you require additional assistance.
              Adam P.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_Joydeep View Post
                And to add, a basic code will look like:
                Code:
                protected override void OnBarUpdate()
                {
                    // Condition set 1
                    if (Rising(WMA(Typical, 14)) == true)
                    {
                        EnterLongStopLimit(0, true, 1, Close[0] + 10 * TickSize, Close[0] + 10 * TickSize, "BuyStop");
                    }
                
                    // Condition set 2
                    if (Falling(Typical) == true)
                    {
                        EnterShortStopLimit(0, true, 1, Close[0] - 10 * TickSize, Close[0] - 10 * TickSize, "SellStop");
                    }
                }
                Also please watch the webinar as present by Josh at a popular forum recently. http://www.youtube.com/watch?v=riLnopGNGzc

                Please let me know if I can assist you any further.
                Hey JOYDEEP can you show me an example of Enter Long limit order i am having a hard time with coding.

                All I want is to go long or short on previous candles close. must be a limit order

                Comment


                  #9
                  Hello,

                  You can specify the "double price" for your limit order as the close of the last bar by using an index value of 1 for that price:

                  Code:
                  EnterLongLimit(Close[1]);
                  I'm including the Help Guide on EnterLongLimit() as well as EnterShortLimit():





                  Please review our article on Order types for more information on order types

                  MatthewNinjaTrader Product Management

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by alifarahani, Today, 09:40 AM
                  6 responses
                  36 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
                  14 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