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 fx.practic, 10-15-2013, 12:53 AM
        5 responses
        5,406 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by Shai Samuel, 07-02-2022, 02:46 PM
        4 responses
        98 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by DJ888, Yesterday, 10:57 PM
        0 responses
        8 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        160 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Yesterday, 09:29 PM
        0 responses
        9 views
        0 likes
        Last Post Belfortbucks  
        Working...
        X