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 DJ888, 04-16-2024, 06:09 PM
          4 responses
          12 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by terofs, Today, 04:18 PM
          0 responses
          9 views
          0 likes
          Last Post terofs
          by terofs
           
          Started by nandhumca, Today, 03:41 PM
          0 responses
          6 views
          0 likes
          Last Post nandhumca  
          Started by The_Sec, Today, 03:37 PM
          0 responses
          3 views
          0 likes
          Last Post The_Sec
          by The_Sec
           
          Started by GwFutures1988, Today, 02:48 PM
          1 response
          9 views
          0 likes
          Last Post NinjaTrader_Clayton  
          Working...
          X