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 Mindset, 04-21-2026, 06:46 AM
          0 responses
          118 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by M4ndoo, 04-20-2026, 05:21 PM
          0 responses
          166 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by M4ndoo, 04-19-2026, 05:54 PM
          0 responses
          85 views
          0 likes
          Last Post M4ndoo
          by M4ndoo
           
          Started by cmoran13, 04-16-2026, 01:02 PM
          0 responses
          130 views
          0 likes
          Last Post cmoran13  
          Started by PaulMohn, 04-10-2026, 11:11 AM
          0 responses
          88 views
          0 likes
          Last Post PaulMohn  
          Working...
          X