Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

only one ATM strategy should be active

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

    only one ATM strategy should be active

    hi ,
    i am trying to make only one ATM strategy is active with below code but what is happening is it places one order id and when it is executed agait it places one more order. but i don't want to create one more order until existing closes .can u please help me?

    if (orderId.Length == 0 ) //Create order only one time
    {

    //To create ore
    isAtmStrategyCreated = false; // reset atm strategy created check to false
    atmStrategyId = GetAtmStrategyUniqueId();
    orderId = GetAtmStrategyUniqueId();
    AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, (lstop+((entryOffsetPer*lstop)/100)), 0, TimeInForce.Day, orderId, ATM_TemplateName, atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
    //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
    if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
    isAtmStrategyCreated = true;
    });
    Print(string.Format("{0};{1}",Time[0],"New ATM Strategy created !!="+orderId.Length));

    } else{ //Change entry order

    Print("In change order -ATM Startegy already creaated -orderId="+orderId); // In market order type if ATM is executed it will place one more order with modifed price so this modify should not be used for market order only limit order it should be used
    }

    #2
    Hello, thanks for your post.

    The best example to reference for ATM strategies is the "SampleAtmStrategy" that is in the platform by default. There we check orderId.Length == 0 and atmStrategyId.Length == 0 + (some condition) for the order entry. Then we check for:

    atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat

    This will reset the atmStrategyId when it has gone to a flat position in the market.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi ,
      I HAVE USED below code but still not working as expected .

      if (orderId.Length == 0 ) //Create order only one time
      {

      //To create ore
      isAtmStrategyCreated = false; // reset atm strategy created check to false
      atmStrategyId = GetAtmStrategyUniqueId();
      orderId = GetAtmStrategyUniqueId();
      AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, (lstop+((entryOffsetPer*lstop)/100)), 0, TimeInForce.Day, orderId, ATM_TemplateName, atmStrategyId, (atmCallbackErrorCode, atmCallBackId) => {
      //check that the atm strategy create did not result in error, and that the requested atm strategy matches the id in callback
      if (atmCallbackErrorCode == ErrorCode.NoError && atmCallBackId == atmStrategyId)
      isAtmStrategyCreated = true;
      });
      Print(string.Format("{0};{1}",Time[0],"New ATM Strategy created !!="+orderId.Length));

      } else{ //Change entry order
      string[] entryOrder = GetAtmStrategyEntryOrderStatus(orderId);
      Print(string.Format("{0};{1}",Time[0],"Current status of order="+entryOrder[2] ));
      // checks if the entry order exists
      // and the order state is not already cancelled/filled/rejected
      if (entryOrder.Length > 0 && entryOrder[2] == "Working")
      {
      bool isEntryOrderExist = AtmStrategyChangeEntryOrder((lstop+((entryOffsetPe r*lstop)/100)),lstop-1,orderId);

      if(!isEntryOrderExist){
      AtmStrategyCancelEntryOrder(orderId);
      orderId=string.Empty; // clear order id if it doesn't exist otherwise it will not place order contineously
      }
      } // If the order state is terminal, reset the order id value
      if ((((GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat) && entryOrder[2] != "Working"))|| entryOrder[2] == "Cancelled" || entryOrder[2] == "Rejected" )
      {
      atmStrategyId = String.Empty ;

      orderId = string.Empty;
      }

      }

      Comment


        #4
        Hello, thanks for your reply.

        I am sorry but I will not be able to review and debug your custom strategy code. Please take the SampleAtmStrategy as an examplar of proper use of an ATM strategy.

        Best regards.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          i used that example only but it is not working as expected

          Comment


            #6
            Hello, thanks for your reply.

            The SampleATMStrategy is working fine on my end. Could you please let me know exactly what is not working?

            ​​​​​​​Best regards.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Hi ,
              I tested above code . It is creating ATM strategy first time when buy signal come and also modifies buy order. But when ones pending ATM strategy fiilled it again adds one more BUY order . But actually i want to avoid this as this will be contineous process. It will go on cumulative and adds many long positions.

              Regards,
              Shankar

              Comment


                #8
                Hello, thanks for your reply.

                You will need to use Prints within your code to explain the behavior. Using prints is a good way to see data from your strategy to understand its output. You will be able to see things like, where the last print was and why the buy order happens more than once. This will let you implement stops like a simple boolean that can control the flow of the program.

                https://ninjatrader.com/support/help...nt8/?print.htm

                Please let me know if I can assist any further.
                Chris L.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Rapine Heihei, 04-23-2024, 07:51 PM
                2 responses
                30 views
                0 likes
                Last Post Max238
                by Max238
                 
                Started by Shansen, 08-30-2019, 10:18 PM
                24 responses
                942 views
                0 likes
                Last Post spwizard  
                Started by Max238, Today, 01:28 AM
                0 responses
                9 views
                0 likes
                Last Post Max238
                by Max238
                 
                Started by rocketman7, Today, 01:00 AM
                0 responses
                4 views
                0 likes
                Last Post rocketman7  
                Started by wzgy0920, 04-20-2024, 06:09 PM
                2 responses
                28 views
                0 likes
                Last Post wzgy0920  
                Working...
                X