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 rhyminkevin, Today, 04:58 PM
          4 responses
          52 views
          0 likes
          Last Post dp8282
          by dp8282
           
          Started by iceman2018, Today, 05:07 PM
          0 responses
          5 views
          0 likes
          Last Post iceman2018  
          Started by lightsun47, Today, 03:51 PM
          0 responses
          7 views
          0 likes
          Last Post lightsun47  
          Started by 00nevest, Today, 02:27 PM
          1 response
          14 views
          0 likes
          Last Post 00nevest  
          Started by futtrader, 04-21-2024, 01:50 AM
          4 responses
          50 views
          0 likes
          Last Post futtrader  
          Working...
          X