Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Two Orders in a Row

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

    Two Orders in a Row

    Hello

    I'm running an automated strategy across multiple markets that works great, but once an order has been executed in a specific market, something in my code prevents the strategy from triggering a subsequent order in that same market.

    When the trade is cancelled, the bool flag "orderPlacedLong" is set to false but when the trade is executed, I'm not sure how to set that same flag to false to allow the code to trigger another trade.

    Thanks for your pointers.

    Here's the code snippet:

    if (!orderPlacedLong && my criteria here)

    {
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(Cbi.OrderAction.Buy, OrderType.StopLimit,High[0]+1*TickSize,High[0]+1*TickSize, TimeInForce.Day, orderId, "MyStrat", GetAtmStrategyUniqueId());
    orderPlacedLong = true;
    }


    else if (orderPlacedLong == true && High[0] <= High[1])
    {
    AtmStrategyCancelEntryOrder(orderId);
    orderPlacedLong = false;
    }
    Last edited by laocoon; 06-05-2013, 06:10 AM.

    #2
    Hello laocoon,

    Thank you for your post.

    Are you looking to have multiple positions open on the same market at the same time? Or are you asking why no further positions are taken after the first position is closed? When enabling your strategy are you setting the EntriesPerDirection to 1?

    I look forward to your response.

    Comment


      #3
      Hello PatrickH,

      Thanks for your reply. I'm asking why no further positions are taken after the first position is closed.
      EntriesPerDirection is indeed set to 1, but this can't be the problem as it only deals with entries while a position is active, which is never the case in my strategy.
      I guess it has something to do with the bool flag that's not set to false after a trade is executed, as I'm not sure how to do that.

      Thanks.
      Last edited by laocoon; 06-05-2013, 06:56 AM.

      Comment


        #4
        Hello laocoon,

        Thank you for your response.

        You will need to check the orderId is greater than 0 and the position of the ATM strategy if flat and then set the bool to false:
        Code:
        if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
        {
        				atmStrategyId = string.Empty;
                                        orderPlacedLong = false;
        }
        I recommend reviewing the SampleAtmStrategy which can be found by going to the NinjaTrader Control Center > Tools > Edit NinjaScript > Strategy > SampleAtmStrategy.

        Please let me know if you have any questions.

        Comment


          #5
          Thanks a lot PatrickH, I'm currently implementing the modifications as per your last post.

          Have a great day.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          110 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          59 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          37 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          41 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          78 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X