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

Place BuyStop, SellStop, BuyLimit, SellLimit pending orders

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

    Place BuyStop, SellStop, BuyLimit, SellLimit pending orders

    Hi there,

    I am want to place BuyStop, SellStop, BuyLimit, SellLimit pending orders but unfortunately I can't open them my code is wrong. Can you please give me code example how to make it?
    also I need function which will delete all placed pending orders together.

    Waiting for your reply and thank you very much for help in advanced.

    P.S. I posted it incorrectly in NT7 forum(https://ninjatrader.com/support/foru...pending-orders) and please delete that post. I couldn't delete that.

    #2
    Hello Revazi123,

    Below is a link to an example that uses ExitLongStopMarket and ExitLongStopLimit orders.
    https://ninjatrader.com/support/foru...269#post802269

    Also, below is a link to a forum post with helpful information about getting started with NinjaScript and C#.
    https://ninjatrader.com/support/foru...040#post786040
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello Revazi123,

      Below is a link to an example that uses ExitLongStopMarket and ExitLongStopLimit orders.
      https://ninjatrader.com/support/foru...269#post802269

      Also, below is a link to a forum post with helpful information about getting started with NinjaScript and C#.
      https://ninjatrader.com/support/foru...040#post786040
      Excuse me its my bad that I didn't gave more detailed information. My main issue is that I am trying to do it with ATM strategy.
      I have created ATM strategy bot what creates buttons on Chart Trader. Currently its placing orders but some times it gets error:
      Strategy 'MyCustomStrategyChartTrader': Error on calling 'OnBarUpdate' method on bar 5793: Object reference not set to an instance of an object.
      I have searched fix of this issue on this forum and what was suggestions I have implemented them I mean this part of code:
      Code:
      if (CurrentBar < 0)
      return;
      
      if (CurrentBar < BarsRequiredToTrade)
      return;
      But I still get this issues.

      So summery is that I have left 2 issues to fix:
      1) OnBarUpdate issue.
      2) make CancelPendingOrders button work. CloseAnyOpenTrades button works and it deletes all atm strategies but CancelPendingOrders doesn't works.

      Thank you for your help.
      Attached Files

      Comment


        #4
        Hello Revazi123,

        'Object reference not set to an instance of an object' means a variable with a null value was used.

        For any nullable object, check the object is not null.

        if (myVariable != null)
        {
        Print(myVariable.ToString() + " is not null");
        }

        If you are unsure of which object is the null object, add prints to the script after each line. The last print to appear before an error is just above the line of code causing the error.

        Below is a link to a forum post that demonstrates using prints to understand behavior.
        https://ninjatrader.com/support/foru...121#post791121

        When you say something work, what specifically is not working.

        Do you have a click event handler for the button? If you print in the event handler do you see the print when the button is clicked?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello Revazi123,

          'Object reference not set to an instance of an object' means a variable with a null value was used.

          For any nullable object, check the object is not null.

          if (myVariable != null)
          {
          Print(myVariable.ToString() + " is not null");
          }

          If you are unsure of which object is the null object, add prints to the script after each line. The last print to appear before an error is just above the line of code causing the error.

          Below is a link to a forum post that demonstrates using prints to understand behavior.
          https://ninjatrader.com/support/foru...121#post791121

          When you say something work, what specifically is not working.

          Do you have a click event handler for the button? If you print in the event handler do you see the print when the button is clicked?
          Thank you I already fixed all issues. Only one what missing is AtmStrategyCancelEntryOrder doesn't works correctly. for that Kite is helping me on this post(https://ninjatrader.com/support/foru...s-with-buttons).

          Thanks

          Comment


            #6
            Hello Chelsea B,

            Can you please help me with this post. Its refers to this project what we have discussed here.

            Hope you will help me. Thanks a lot in advanced.

            Comment


              #7
              Hello Revazi123,

              The thread you have linked is currently with NinjaTrader_Kate who will continue assisting you in that thread. I will offer any assistance to Kate that I am able.

              As a heads up, your post appears to be asking for someone to develop custom logic for you. Our job is to show the tools and demonstrate that the tools work as defined in the help guide. Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services. This is so that we can maintain a high level of service for all of our clients as well as our associates.

              This forum is still a good place to request for the NinjaTrader Community of users to assist with custom logic and your thread will remain open for the community to write custom code for you at your request. We simply have to manage expectations of the responsibilities of the NinjaTrader staff.

              You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one on one educational services.

              That said, I will work with Kate to try and answer any questions you may have, and assist you with you writing your own custom logic.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Thank you Chelsea for replying,

                no I am asking about different thing. my problem is that I can't call OnPositionUpdate, OnOrderUpdate, OnExecutionUpdate but non of them is printing so this means I couldn't call any of those 3 functions and I am wondering why. I am using very simple code:
                Code:
                #region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.Indicators; using NinjaTrader.NinjaScript.DrawingTools; #endregion //This namespace holds Strategies in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Strategies { public class ExampleAtmStrategyCancelEntryOrder : Strategy { private string atmStrategyId = string.Empty; private string orderId = string.Empty; private bool isAtmStrategyCreated = false; private int OrderCreatedOnBar; protected override void OnStateChange() { if (State == State.SetDefaults) { Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDes criptionSampleATMStrategy; Name = "ExampleAtmStrategyCancelEntryOrder"; // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations // See the Help Guide for additional information IsInstantiatedOnEachOptimizationIteration = false; } } protected override void OnBarUpdate() { if (CurrentBar < BarsRequiredToTrade) return; // HELP DOCUMENTATION REFERENCE: Please see the Help Guide section "Using ATM Strategies" under NinjaScript--> Educational Resources--> http://ninjatrader.com/support/helpGuides/nt8/en-us/using_atm_strategies.htm // Make sure this strategy does not execute against historical data if(State == State.Historical) return; // Submits an entry limit order at the current low price to initiate an ATM Strategy if both order id and strategy id are in a reset state // **** YOU MUST HAVE AN ATM STRATEGY TEMPLATE NAMED 'AtmStrategyTemplate' CREATED IN NINJATRADER (SUPERDOM FOR EXAMPLE) FOR THIS TO WORK **** if (orderId.Length == 0 && atmStrategyId.Length == 0 && Close[0] > Open[0]) { isAtmStrategyCreated = false; // reset atm strategy created check to false atmStrategyId = GetAtmStrategyUniqueId(); orderId = GetAtmStrategyUniqueId(); AtmStrategyCreate(OrderAction.Buy, OrderType.Limit, Low[0], 0, TimeInForce.Day, orderId, "ATM 1", 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; // keep track of what bar the order is submitted on so we can cancel if more than three bars pass without a fill OrderCreatedOnBar = CurrentBar; }); } // Check that atm strategy was created before checking other properties if (!isAtmStrategyCreated) return; } protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition) { Print("OnPositionUpdate"); } protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError) { Print("OnOrderUpdate"); } protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time) { Print("OnExecutionUpdate"); } } }
                If I change code and just use for example EnterLong() then I can get those 3 function work. So obviously they are not working because of ATM strategy.

                Thanks

                Comment


                  #9
                  Hello Revazi123,

                  I am seeing that you may be creating duplicate posts on the forum. We respectfully ask that you only create one inquiry. Creating multiple forum threads will create two separate tickets and may cause multiple technicians to start at the beginning of reviewing your inquiry, tying up resources with our platform support and delaying our ability to respond to all customers in a timely manner.

                  May I confirm that this a new inquiry and not related to the post below?
                  Hi there, I am placing pending orders using ATM strategy and I am trying to print order execution time when order get executed. I am using simple code: #region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using



                  From the help guide:
                  "Executions resulting from an ATM Strategy that is created from within a NinjaScript automated strategy will not plot on a chart during real-time operation
                  Executions from ATM Strategies will not have an impact on the hosting NinjaScript strategy position and PnL - the NinjaScript strategy hands off the execution aspects to the ATM, thus no monitoring via the regular NinjaScript strategy methods will take place (also applies to strategy performance tracking)"


                  Atm strategies do not affect the strategy position or order methods.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Thank I will continue this thread with Jim.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by terofs, Yesterday, 04:18 PM
                    1 response
                    21 views
                    0 likes
                    Last Post terofs
                    by terofs
                     
                    Started by CommonWhale, Today, 09:55 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Erick  
                    Started by Gerik, Today, 09:40 AM
                    2 responses
                    7 views
                    0 likes
                    Last Post Gerik
                    by Gerik
                     
                    Started by RookieTrader, Today, 09:37 AM
                    2 responses
                    13 views
                    0 likes
                    Last Post RookieTrader  
                    Started by alifarahani, Today, 09:40 AM
                    1 response
                    7 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X