Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

unmanaged approach

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

    unmanaged approach

    Hi
    I am trying to develop a trading program that has several signals. for now i am concentrating on only signal number 1 . Its a simple signal that fire if price is a above a point by 2 ticks , the code is as below. The problem I am having is that the program sets the limit price and ninjatrader register it as a trade even though price did not trade at the set limit price. Target and stops are being hit even though a trade should not have taken place because price did not reach that point. Can you give me some insight as to what I am doing wrong.

    Thanks

    #2
    if (Position.MarketPosition == MarketPosition.Flat)
    {
    if (entryOrderNType1 == null
    && High[0] > PBT + 2 * TickSize)
    {
    DrawVerticalLine(
    "My vertical line" + CurrentBar, 0, Color.Cyan);
    entryOrderNType1 = EnterShortLimit(
    0,true,DefaultQuantity, et1LP, "Entry type 1");
    PrintWithTimeStamp(
    "signal 1 fire");
    }
    elseif (entryOrderNType1 != null && (ToTime(Time[0]) >= 160000 && ToTime(Time[0]) <= 170000))
    {
    CancelOrder(entryOrderNType1);
    PrintWithTimeStamp(
    "cancel");
    entryOrderNType1 =
    null;
    }

    Comment


      #3
      protectedoverridevoid OnOrderUpdate(IOrder order)
      {
      if (entryOrderNType1 != null && entryOrderNType1.Token == order.Token)
      {
      // Check if entryOrder is cancelled.
      if (order.OrderState == OrderState.Cancelled)
      { Print(
      "zjkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk kkkkkkkkkkkk");
      // Reset entryOrder back to null
      entryOrderNType1 = null;
      PrintWithTimeStamp(
      "resettttttttttttttttttttttttttttttttt");

      }
      }
      }

      Comment


        #4
        protectedoverridevoid OnExecution(IExecution execution)
        {
        if (entryOrderNType1 != null && entryOrderNType1.Token == execution.Order.Token)
        {
        if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
        {
        stopOrderNtype1 = ExitShortStop(
        0, true, DefaultQuantity,StpRnd, "stop", "Entry type 1");
        targetorderNtype1 = ExitShortLimit(
        0, true, DefaultQuantity,Target, "target", "Entry type 1");
        PrintWithTimeStamp(
        "targggggggggggggggggeeeeeeeeeeeeeeeeeeeeet");
        //// DrawVerticalLine("My vertical line" + CurrentBar, 0, Color.DarkOrange);


        if (execution.Order.OrderState != OrderState.PartFilled)
        {
        entryOrderNType1 =
        null;
        }


        }
        }
        // Reset our stop order and target orders' IOrder objects after our position is closed.
        if ((stopOrderNtype1 != null && stopOrderNtype1.Token == execution.Order.Token) || (targetorderNtype1 != null && targetorderNtype1.Token == execution.Order.Token))
        {

        if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
        {
        stopOrderNtype1 =
        null;
        targetorderNtype1 =
        null;
        Print(
        "ggggggggggggggooooooo");
        }
        }
        }

        Comment


          #5
          Hi Trader413,

          In the future, please share a large block of code by attaching the file directly. You can either export or attach the .cs file from My Documents\Bin\Custom\Strategy

          To track strategy order submission issues, add TraceOrders = true; to your Initialize() method.

          Add Print() statements to confirm all values are what you expect.

          Here are some observations from viewing your code snippets.
          You're using managed orders but the title of your thread is unmanaged approach. Please see here for help using the unmanaged approach.

          You're using .token on your order objects which is no longer used in NinjaTrader 7. To test for equality, compare the objects directly.
          Ryan M.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          69 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          42 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          24 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          27 views
          0 likes
          Last Post TheRealMorford  
          Started by Mindset, 02-28-2026, 06:16 AM
          0 responses
          54 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X