Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to Enter multiple Orders

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

    How to Enter multiple Orders

    Hi,

    I've just tried to create a strategy that places after the bar close two orders. Unfortunately it does not work. It just places 1 order and that's it!

    Thank's for your help.

    Regards,


    Here is the code:


    Namespace NinjaTrader.NinjaScript.Strategies
    {
    public class Short : Strategy
    {
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Place 3 Limit Orders after Bar Close";
    Name = "Short";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 100;
    EntryHandling = EntryHandling.UniqueEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.ImmediatelySubmit;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = true;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 0;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {

    EnterShortLimit(Convert.ToInt32(DefaultQuantity), (Close[0] + (10 * TickSize)) , "Limit20");
    EnterShortLimit(Convert.ToInt32(DefaultQuantity), (Close[0] + (8 * TickSize)) , "Limit8");
    }
    }
    }

    #2
    Hello dinico,

    Thank you for your inquiry.

    I'm seeing that it is submitting 2 orders on each bar. However, what you end up seeing occurs because the second order isn't always hit and filled within the bar in which it was placed. Since NinjaTrader will automatically cancel limit orders at the end of a bar if the conditions for entry are no longer true, you see a number of places where only the closer entry gets placed. This is due to the fact that there are no conditions for the entry to evaluate to true.

    If you wish for the orders to stay live until explicitly cancelled, you can certainly do so.

    From our help guide:

    The following method variation is for experienced programmers who fully understand Advanced Order Handling concepts:

    EnterShortLimit(int barsInProgressIndex, bool isLi veUntilCancelled, int quantity, double limitPrice, string signalName)


    An example of how to keep orders alive until they are explicitly cancelled may be found in our help guide here:



    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Hi Kate,

      Thank's for the quick reply.

      Could you provide a the code that I need to add to my script? I've tried to add the code in this way:

      EnterShortLimit(Convert.ToInt32(DefaultQuantity), bool isLiveUntilCancelled, (Close[0] + (10 * TickSize)) , "Limit20");

      but it does produce syntax errors. Probably I need to do it in another way. Sorry, but I'm not really a programmer...

      Regards,

      Comment


        #4
        Hello dinico,

        Thank you for your reply.

        A bool is simply either true or false. So in this case the correct syntax would be:

        EnterShortLimit(0, true, Convert.ToInt32(DefaultQuantity), Close[0] + (10 * TickSize)) , "Limit20")

        Where 0 is the index of the primary series on the chart, and true is the IsLiveUntilCancelled value.

        Please let us know if we may be of further assistance to you.

        Comment


          #5
          Great! It works ;-)

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          54 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          130 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          72 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X