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 Aviram Y, Today, 05:29 AM
        0 responses
        2 views
        0 likes
        Last Post Aviram Y  
        Started by quantismo, 04-17-2024, 05:13 PM
        3 responses
        25 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by ScottWalsh, 04-16-2024, 04:29 PM
        7 responses
        34 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by cls71, Today, 04:45 AM
        0 responses
        6 views
        0 likes
        Last Post cls71
        by cls71
         
        Started by mjairg, 07-20-2023, 11:57 PM
        3 responses
        217 views
        1 like
        Last Post PaulMohn  
        Working...
        X