• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unmanaged Orders

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

    Unmanaged Orders

    I am trying to test the simplest case of unmanaged orders.
    See code below which simply goes long or shrot as price is above/below SMA(21). First order goes in fine. Second one is recorded but does not show in my strategy chart -- the Market.Position is Flat. I am missing something fundamental.
    Can someone hlep.


    if (Close[0] > SMA(21)[0])
    {
    if (ShortOrder != null && ShortOrder.OrderAction == OrderAction.Sell)
    {
    CancelOrder(ShortOrder);
    ShortOrder =
    null;
    }
    if (LongOrder == null)
    {
    LongOrder = SubmitOrder(
    0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "LongMarket");
    }
    }
    elseif (Close[0] < SMA(21)[0])
    {
    if (LongOrder != null && LongOrder.OrderAction == OrderAction.Buy)
    {
    CancelOrder(LongOrder);
    LongOrder =
    null;
    }
    if (ShortOrder == null)
    {
    ShortOrder = SubmitOrder(
    0, OrderAction.Sell, OrderType.Market, 1, 0, 0, "", "ShortMarket");
    }
    }
    }

    #2
    YakHerder, can you please clarify what you mean by "second one is recorded but does not show in my strategy chart"?

    I made a few changes to your code in order to get it to compile on my machine so I could test it, and everything looks fine here.
    Code:
    protected override void OnBarUpdate()
    {
        if (Close[0] > SMA(21)[0])
        {
            if (ShortOrder != null && ShortOrder.OrderAction == OrderAction.Sell)
            {
                CancelOrder(ShortOrder);
                ShortOrder = null;
            }
            if (LongOrder == null)
            {
                LongOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Market, 1, 0, 0, "", "LongMarket");
            }
        }
        else if (Close[0] < SMA(21)[0])
        {
            if (LongOrder != null && LongOrder.OrderAction == OrderAction.Buy)
            {
                CancelOrder(LongOrder);
                LongOrder = null;
            }
            if (ShortOrder == null)
            {
                ShortOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Market, 1, 0, 0, "", "ShortMarket");
            }
        }
    }
    Attached Files
    AustinNinjaTrader Customer Service

    Comment


      #3
      What I mean is that the orders aren't connected visually in the strategy window.
      If the first order is short, you see a line from the start of the short to the beginning of the long, but no line from the beginning the long to the next short and so on repeatedly.
      See attached for what my strategy window looks like. Note that no long lines are presenting.

      When I print 'position.ToString()' to the output windoe inside OnPositionUpdate, I notice that the initial order goes through as a Short, but the next order (long) is submitted long but is reported as Flat.

      OUTPUT WINDOW (partial example)
      ==============
      POSITION: Instrument='YM 09-10' Account='Sim101' Avg price=10454 Quantity=1 Market position=Short
      POSITION: Instrument='YM 09-10' Account='Sim101' Avg price=0 Quantity=0 Market position=Flat
      POSITION: Instrument='YM 09-10' Account='Sim101' Avg price=10454 Quantity=1 Market position=Short
      ==============
      (attached is the full output text file)

      Is this somehow related to the fact that I'm running on historical data on the evaluation NT7 product?
      I have been waiting to buy the license to connect to a broker until I have my rules working. My rules are all ready to go and have been written generically--I don't use any NT order logic. Now, it's time to buy the service, connect to a broker, and work on live data.
      Attached Files

      Comment


        #4
        YakHerder, the SubmitOrder in Unmanaged mode would not reverse the position for you automatically, like you're used to with the Enter() methods in managed mode - you would need to do the reverse in your custom code through proper qty's.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by teafortwo, Today, 04:26 AM
        4 responses
        12 views
        0 likes
        Last Post bltdavid  
        Started by borjanews, Today, 06:13 PM
        0 responses
        3 views
        0 likes
        Last Post borjanews  
        Started by Austiner87, Today, 05:13 PM
        0 responses
        2 views
        0 likes
        Last Post Austiner87  
        Started by Austiner87, Today, 04:59 PM
        0 responses
        4 views
        0 likes
        Last Post Austiner87  
        Started by Austiner87, Today, 04:58 PM
        0 responses
        1 view
        0 likes
        Last Post Austiner87  
        Working...
        X