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

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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Great! It works ;-)

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by llanqui, Today, 03:53 AM
          0 responses
          6 views
          0 likes
          Last Post llanqui
          by llanqui
           
          Started by burtoninlondon, Today, 12:38 AM
          0 responses
          10 views
          0 likes
          Last Post burtoninlondon  
          Started by AaronKoRn, Yesterday, 09:49 PM
          0 responses
          15 views
          0 likes
          Last Post AaronKoRn  
          Started by carnitron, Yesterday, 08:42 PM
          0 responses
          11 views
          0 likes
          Last Post carnitron  
          Started by strategist007, Yesterday, 07:51 PM
          0 responses
          14 views
          0 likes
          Last Post strategist007  
          Working...
          X