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 zstheorist, Today, 07:52 PM
          0 responses
          7 views
          0 likes
          Last Post zstheorist  
          Started by pmachiraju, 11-01-2023, 04:46 AM
          8 responses
          150 views
          0 likes
          Last Post rehmans
          by rehmans
           
          Started by mattbsea, Today, 05:44 PM
          0 responses
          6 views
          0 likes
          Last Post mattbsea  
          Started by RideMe, 04-07-2024, 04:54 PM
          6 responses
          33 views
          0 likes
          Last Post RideMe
          by RideMe
           
          Started by tkaboris, Today, 05:13 PM
          0 responses
          6 views
          0 likes
          Last Post tkaboris  
          Working...
          X