Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Short Orders Not Executing

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

    Short Orders Not Executing

    Hello NT,

    I'm trying to figure out why my short orders stopped executing when I added Targets and Stops. I get both long and short executions with the following code I started out with:

    Code:
     entry4_x = 1;
    }
    else if (State == State.Configure)
    {
    }
    }
    [NinjaScriptProperty]
    [Description("entry4_x")]
    [Category("Parameters")]
    public int entry4_x
    { get; set; }
    
    protected override void OnBarUpdate()
    {
    if (CurrentBar < BarsRequiredToTrade)
    return;
    
    EnterLongStopMarket(High[HighestBar(High, entry4_x)]);
    EnterShortStopMarket(Low[LowestBar(Low, entry4_x)]);
    When I modify it as follows the short trades stop working. Would appreciate if you could tell me why that's happening.

    Code:
     entry4_x = 1;
    Target = 1000;
    Stop = 1000;
    }
    else if (State == State.Configure)
    {
    SetProfitTarget(@"Entry04Long", CalculationMode.Currency, Target);
    SetStopLoss(@"Entry04Long", CalculationMode.Currency, Stop, false);
    SetProfitTarget(@"Entry04Short", CalculationMode.Currency, Target);
    SetStopLoss(@"Entry04Short", CalculationMode.Currency, Stop, false);
    }
    }
    [NinjaScriptProperty]
    [Description("entry4_x")]
    [Category("Parameters")]
    public int entry4_x
    { get; set; }
    
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Target", Description="Target Price", Order=1, GroupName="Parameters")]
    public int Target
    { get; set; }
    
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="Stop", Description="Stop Price", Order=2, GroupName="Parameters")]
    public int Stop
    { get; set; }
    
    protected override void OnBarUpdate()
    {
    if (CurrentBar < BarsRequiredToTrade)
    return;
    
    EnterLongStopMarket(High[HighestBar(High, entry4_x)],@"Entry04Long");
    EnterShortStopMarket(Low[LowestBar(Low, entry4_x)],@"Entry04Short");
    Thanks

    #2
    Hello harr5754,

    Thanks for your post.

    Whenever a script is not working as expected, please check your NinjaTrader control center's "Log" tab for any related error messages.

    What error message do you see?

    Comment


      #3
      Hi Paul,

      I'm used to seeing seeing error messages when I compile Ninjascripts so I didn't think to check the control center log. Good to know. There were two error messages showing up for this strategy:

      Stop/target handling set to 'By strategy position' since currency based stop order was placed.
      An Enter() method to submit an entry order at '2/1/2011 4:00:00 PM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.

      Not sure what this means.

      Thanks,
      Ben

      Comment


        #4
        Hello harr5754,

        Thanks for your reply.

        The compiler can only check static conditions so any run-time type errors would not show until the script is applied and any errors would be found in the Log window. When developing a script it is always a good practice to have the log window open to catch a view of what is going on.

        The stop/target handling is just an informative message letting you know that it will use the strategy position to adjust the current based stop, so the location of the stop will be based on that currency.

        The other message is the issue as to why you cannot place two opposing entry orders at once. Please see the help guide "managed approach" section and review the Internal Order Handling Rules. References:
        https://ninjatrader.com/support/help...d_approach.htm
        https://ninjatrader.com/support/help...antedPositions

        The specific violation is: Methods that generate orders to enter a position will be ignored if: The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction.

        So in summary the second-order is ignored (you can flip the sequence and then the long order would be ignored) because it would be used to open a position in the opposite direction.

        Your choices to accomplish your goal would be to:

        1) use the Unmanaged approach where there are no restrictions on orders however you have to take responsibility for handling, in your code, all situations.

        2) Continue with the managed approach and place only one limit order to enter and then use code to monitor price and if it goes in the other direction to then enter using a market order when it hits the price level. Or just monitor price and compare to levels and submit a market order when the price reaches the levels.

        Comment


          #5
          Hi Paul,

          I am just trying to backtest this strategy. I'm gathering it's only possible to backtest with the unmanaged approach. The managed approach requires me to monitor the prices with the code and manually enter the market in real time. Is that correct?

          Comment


            #6
            Hello harr5754,

            Thanks for your reply.

            The managed approach has entry and exit rules as specified in the links previously provided. These rules apply to live and historical testing.

            The managed approach will limit you to one limit or stop type entry in one direction at a time.

            You can accomplish your goal in the strategy analyzer, using the managed approach, with historical data and employing one limit entry order and monitoring price and placing market orders. You likely will want to use Tick Replay and a 1 tick added data series.

            The unmanaged approach does not restrict what orders you place but does require your code to cover all aspects of order control. Please see: https://ninjatrader.com/support/help...d_approach.htm


            Comment


              #7
              Thanks, Paul,

              I think I understand what the problem is now. So with this strategy after I'm stopped into a trade, I can use a limit order for the profit target, but would have to manually execute any stop losses because there is another stop entry waiting in the same direction of the stop loss. Correct? Regarding the Tick Replay, is it even possible with using the Strategy Analyzer or would I have to record everything manually?

              I'm thinking it might be better to exit after a certain number of bars.

              Comment


                #8
                Hello harr5754,

                Thanks for your reply.

                You can use the set methods for your stop and target. The issue is, in the managed approach, that you cannot have two resting entry orders in the opposite direction. I've suggest a couple of alternatives if you want to stay withing the managed approach.

                You can use tick reply with the Strategy analyzer. The only requirement would be to have historical tick data for the instrument for the duration of the backtest. Tick replay is needed so that the strategy can perform as you want. The 1 tick series is needed so you can get the order fill needed. Tick replay and the 1 tick series are needed so that the strategy analyzer can provide execution closer to what you want. Alternatively, you could use Playback with market replay data and not need to modify the strategy by adding the 1 tick series or using Tick replay.

                Comment


                  #9
                  Thanks, Paul.

                  For my purposes I'm thinking of splitting it into 2 strategies: one long and one short. I would then export the trades from the Strategy analyzer into excel and eliminate any overlapping trades based on dates in the sequence they occur before evaluating results. Do you see any problems with this approach?

                  Regards,
                  Ben

                  Comment


                    #10
                    Hello Ben,

                    Thanks for your reply.

                    You can certainly try that.

                    I have no knowledge that this would or would not work for you.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Today, 05:17 AM
                    0 responses
                    20 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    119 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    63 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    41 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    45 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X