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

I am trying to create an ATM strategy

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

    I am trying to create an ATM strategy

    I am trying to create an ATM strategy. At this stage, it creates the trade. Now, I want to get the current Stop price & Target price, so that I can change them. Here's the code:

    Code:
    if (AtmIsFlat())
    {
    
        if (_enterLong)
       {
    
       _atmStrategyId = GetAtmStrategyUniqueId();
       atmStrategyOrderId = GetAtmStrategyUniqueId();
       Print(_atmStrategyId + " A ");
    
       AtmStrategyCreate(OrderAction.Buy, OrderType.Market, 0, 0, TimeInForce.Day,
       atmStrategyOrderId, ATMTemplateName, _atmStrategyId, (atmCallbackErrorCode, atmCallbackId) =>
       {
    
          // checks that the call back is returned for the current atmStrategyId stored
          if (atmCallbackId == _atmStrategyId)
          {
             Print(_atmStrategyId + " B ");
             // check the atm call back for any error codes
             if (atmCallbackErrorCode == Cbi.ErrorCode.NoError)
             {
                Print(_atmStrategyId + " C ");
                // if no error, set private bool to true to indicate the atm strategy is created
                isAtmStrategyCreated = true;
             }
            }
       });
    
    }
    
    if (isAtmStrategyCreated)
    {
       string[,] orders = GetAtmStrategyStopTargetOrderStatus("Stop1", _atmStrategyId);
    
    
       // Check length to ensure that returned array holds order information
       if (orders.Length > 0)
       {
          for (int i = 0; i < orders.GetLength(0); i++)
          {
             Print(_atmStrategyId + " L ");
             Print("Average fill price is " + orders[i, 0].ToString());
             Print("Filled amount is " + orders[i, 1].ToString());
    
          }
       }
    }

    I am getting this OUTPUT:

    35a006e31c2f4837ba6924dd8f606a98 A
    35a006e31c2f4837ba6924dd8f606a98 B
    35a006e31c2f4837ba6924dd8f606a98 C

    35a006e31c2f4837ba6924dd8f606a98 L
    Average fill price is 0
    Filled amount is 0


    Why am I getting all zeroes? What am I doing wrong?
    Last edited by fawzanalim; 06-08-2021, 11:48 AM.

    #2
    Hello fawzanalim,

    With NinjaTrader 7, this would only return the fill price once the order has filled.

    There would not be a supported approach for NinjaTrader 7 to get the working stop price.

    With NinjaTrader 8 these could be fetched from the <Account>.Orders.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Sorry i forgot to mention that I am using NT 8. Can you elaborate please? I am a beginner

      Comment


        #4

        Hello fawzanalim,

        Your post was in the NinjaTrader 7 general development section of the forums.

        I have moved this to the NinjaTrader 8 Strategy Development section of the forums as you have stated this is for NinjaTrader 8.

        Keep in mind accessing the Account properties through the Addon approach is advanced coding.

        Below is a link to the help guide on the Account.Orders collection.


        There is also a collection of strategies run on the account.


        There is also an undocumented example of getting orders from an strategy id.
        NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrategy(&quot;S10_P10&quot;, entryOrder); This does not return a strategyID, which is needed for any following action, like closing the strategy. How can I get it? Thanks.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          I beg your pardon, but i don't think it is doing what i wanted it to do. Right now, my strategy creates an ATM trade and saves the Unique ATM ID of that trade for future use. I want to know the current stop price of that trade using the Unique ATM ID. I think GetAtmStrategyStopTargetOrderStatus() does that. Please correct me if I am wrong.

          Comment


            #6
            Hello fawzanalim,

            The current stop price is not part of the order status, you can see details of what is reported with this method in the following link:



            I am not aware of a way that you can use the ATM methods to get the stop price. One possiblity would be to calculate the stop price yourself and issue a change to the ATM to have it match your calculated stop price. You would then know the price because you changed the target to that price.



            The alternative was what Chelsea had posted about using the account and its orders collection to find the order in question.

            JesseNinjaTrader Customer Service

            Comment


              #7
              Can you please at least tell me why do all the values are zero in the output? I know the ID is not wrong because I have used the same ID to change the stop and it worked. Besides, if it was wrong then it would have printed an error message. (Sorry for repeating the question.)

              Code:
              protected override void OnBarUpdate()
              {
                  string[,] orders = GetAtmStrategyStopTargetOrderStatus("Target1", "idValue");
              
                  // Check length to ensure that returned array holds order information
                  if (orders.Length > 0)
                  {
                      for (int i = 0; i < orders.GetLength(0); i++)
                      {
                            Print("Average fill price is " + orders[i, 0].ToString());
                            Print("Filled amount is " + orders[i, 1].ToString());
                      }
                  }
              }
              Output:
              Average fill price is 0
              Filled amount is 0

              Comment


                #8
                Hello fawzanalim,

                Those values should be 0 while the stop is active, it would only have values for those two fields if it partially filled. It would then have an average fill price and an filled amount. Have you checked the third item in the array to see what the orders state is to verify you are observing the order?

                Code:
                   Print("Current state is " + orders[i, 2].ToString());
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by reynoldsn, Today, 02:34 PM
                0 responses
                6 views
                0 likes
                Last Post reynoldsn  
                Started by nightstalker, Today, 02:05 PM
                0 responses
                9 views
                0 likes
                Last Post nightstalker  
                Started by llanqui, Yesterday, 09:59 AM
                8 responses
                28 views
                0 likes
                Last Post llanqui
                by llanqui
                 
                Started by quicksandatl, Today, 01:39 PM
                1 response
                6 views
                0 likes
                Last Post quicksandatl  
                Started by md4866, 05-01-2024, 08:15 PM
                2 responses
                18 views
                0 likes
                Last Post md4866
                by md4866
                 
                Working...
                X