Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

order and ATM template

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

    order and ATM template

    I am not able to implement the function so that my strategy uses the predefined template in chart trader atm:

    Account acct = Account.All.FirstOrDefault(); // Asume que usas la primera cuenta encontrada

    // Ahora, según la acción determinada por la predicción:
    switch (action)
    {
    case 1: // Compra
    // Crea una orden de compra en el mercado

    Order entryOrderBuy = acct.CreateOrder(Instrument, OrderAction.Buy, OrderType.Market, TimeInForce.Day, 1, 0, 0, "Entry", Core.Globals.MaxDate,null);
    // Vincula una estrategia ATM si es necesario
    NinjaTrader.NinjaScript.Strategies.Strategy.StartA tmStrategy("40_180_bv30", entryOrderBuy);
    // Envía la orden
    acct.Submit(new[] { entryOrderBuy });
    break;

    case 2: // Venta
    // Crea una orden de venta en el mercado
    Order entryOrderSell = acct.CreateOrder(Instrument, OrderAction.Sell, OrderType.Market, TimeInForce.Day, 1, 0, 0, "Entry",Core.Globals.MaxDate, null);
    // Vincula una estrategia ATM si es necesario
    NinjaTrader.NinjaScript.Strategies.Strategy.StartA tmStrategy("40_180_bv30", entryOrderSell);
    // Envía la orden
    acct.Submit(new[] { entryOrderSell });
    break;

    case 0: // Nada
    default: // En caso de cualquier otro valor no esperado, no hacer nada.
    break;​

    Cannot convert system date to string

    #2
    Hello dcriador,

    It looks like you are missing some parameters, all parameters need to be filled in with CreateOrder. The error hints at that because a DateTime was used where a string should have been used instead.

    These are the required parameters:

    Code:
    CreateOrder(Instrument instrument, OrderAction action, OrderType orderType, OrderEntry orderEntry, TimeInForce timeInForce, int quantity, double limitPrice, double stopPrice, string oco, string name, DateTime gtd, CustomOrder customOrder)
    ​You are missing OrderEntry.Automated ​and the OCO string. If no OCO is to be used you can just add a blank string ""

    Comment


      #3
      I get error:
      Error on calling 'OnBarUpdate' method on bar 180: Object reference not set to an instance of an object.
      03/05/2024 12:36:23: Current State is State.Terminated

      Code:
      Print("Accion: " + action);
      Account acct = Account.All.FirstOrDefault(); // Asume que usas la primera cuenta encontrada
      // Ahora, según la acción determinada por la predicción:
      switch (action)
      {
      case 1: // Compra
      // Crea una orden de compra en el mercado
      Print("Entra en compra");
      Order entryOrderBuy = acct.CreateOrder(Instrument, OrderAction.Buy, OrderType.Market,OrderEntry.Automated, TimeInForce.Day, 1, 0, 0,"", "Entry", new DateTime(),null);

      // Vincula una estrategia ATM si es necesario
      NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy("40_180_bv30", entryOrderBuy);
      // Envía la orden
      acct.Submit(new[] { entryOrderBuy });
      Print("Fin entra en compra ");
      break;

      case 2: // Venta
      Print("Entra en venta");
      // Crea una orden de venta en el mercado
      Order entryOrderSell = acct.CreateOrder(Instrument, OrderAction.Sell, OrderType.Market,OrderEntry.Automated, TimeInForce.Day, 1, 0, 0,"", "Entry", new DateTime(),null);
      // Vincula una estrategia ATM si es necesario
      NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrate gy("40_180_bv30", entryOrderSell);
      // Envía la orden
      acct.Submit(new[] { entryOrderSell });
      Print("Fin entra en venta ");
      break;

      case 0: // Nada
      default: // En caso de cualquier otro valor no esperado, no hacer nada.


      ATM
      Click image for larger version  Name:	image.png Views:	0 Size:	12.3 KB ID:	1302133
      Last edited by dcriador; 05-03-2024, 06:24 AM.

      Comment


        #4
        Hello dcriador,

        Object reference not set to an instance of an object means that some variable you are using was null when you tried to use it. To find which part of the code is related you will need to use Prints. Placing a print between each line will let you see what the last line executed was in the output window. You have some prints already so you should be able to see some of them in the output window to guide which part was called last before the error happened.

        Comment


          #5
          Solved problem:

          else if (State == State.Configure)
          {
          client = new HttpClient();
          Account acct = Account.All.FirstOrDefault();
          if (acct != null)
          {
          Print("Nombre de la cuenta: " + acct.Name);
          }
          else
          {
          Print("No se encontró ninguna cuenta.");
          }
          }​
          ------


          Account acct = Account.All.FirstOrDefault(); // Asume que usas la primera cuenta encontrada

          // Ahora, según la acción determinada por la predicción:
          switch (action)
          {
          case 1: // Compra
          Print("Accion: " + action);
          if (atmStrategyId.Length == 0)
          {
          atmStrategyId = GetAtmStrategyUniqueId();
          AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day, atmStrategyId, "40_180_bv30", atmStrategyId, AtmStrategyCallback);
          }
          break;

          case 2: // Venta
          Print("Accion: " + action);
          if (atmStrategyId.Length == 0)
          {
          atmStrategyId = GetAtmStrategyUniqueId();
          AtmStrategyCreate(OrderAction.SellShort, OrderType.Market, 0, 0, TimeInForce.Day, atmStrategyId, "40_180_bv30", atmStrategyId, AtmStrategyCallback);
          }
          break;

          My new problem is how i could monitor order, i need wait when the order is submited and when order is finished do a new order.

          Comment


            #6
            Hello dcriador,

            I would recommend looking over the code for the SampleATMStrategy that comes with NinjaTrader. That outlines what logic is needed to monitor an ATM from start until finish so it does not place additional trades until it is done.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            50 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            126 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            69 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            42 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X