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

Ignored and multiple duplicate output messages. To use a bool or not to use a bool?

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

    Ignored and multiple duplicate output messages. To use a bool or not to use a bool?

    Hello,

    I started developing NT8 strategies on my own a couple months ago. Until recently, I was using EnterLong/EnterShort, SetProfitTarget, and SetStopLoss for my entry and exit logic. I started using orders as objects logic (private Order entryOrder = null; ) so I could use limit orders (EnterLongLimit/EnterShortLimit) and determine if the orders are active by checking if they are null.

    With my first market-order strategies I would use a bool to prevent multiple instances of the same command from being generated.




    private bool shortTradeEntered = false; // bool to prevent multiple instances of the same command being generated


    if (some logic && shortTradeEntered == false)
    {
    shortTradeEntered = true;

    EnterShort(0, 1, "shortTrade");
    SetStopLoss(.......);
    SetProfitTarget(.......);
    }


    Then depending on the strategy I would reset the bool to false at the appropriate time to allow for the another short entry once the trade completes.




    With the orders as objects logic I have not done this. When live trading with it I get anywhere from 10 - 25 duplicate/ignored "Entered internal SubmitOrderManaged..." orders. When an order is cancelled before it is filled I get 20-40 "Cancelled custom managed order" messages in the output window. I fully understand why this is occurring, and the strategy is entering and exiting orders as intended.

    What I am curious about is if there is a best practice to deal with this? Does this method of allowing and ignoring multiple duplicate commands utilize more resources and possibly create errors that will halt a trading strategy during peak volume? Or does adding bools to limit the entered orders to one instance create additional unneeded complication in a strategy's logic?


    I appreciate anyone's input on how they handle this.

    And I did look through the forum before submitting this and did not find anything specifically addressing this question. So hopefully it has not been discussed already.
    Last edited by 9817_dynamic; 12-02-2020, 01:22 PM.

    #2
    Hello 9817_dynamic,

    With the orders as objects logic you would do basically the same task if you want to better control when your logic is called. Instead of a bool you just use the order object and check if its null or not:
    Code:
    if(myOrder != null)
    {
        //do something because the order exists
    }
    or
    if(myOrder == null)
    {
        //do something because the order does not exist
    }
    You can find an example of that in the following reference sample: https://ninjatrader.com/support/help...and_onexec.htm

    Its always suggested to do less so if your strategy is repeatedly submitting the same orders over and over it would be suggested to refine that so the strategy is being more specific. While it may be working now with the ignored messages there is always the possibility that allowing it to run rampant will cause problems in some way. When submitting orders to a live account you generally want to make sure the strategy is doing exactly what you intended instead of relying on managed order handling warnings or some background logic to take care of handling that.

    You can otherwise use any C# mechanics like bools to toggle logic on or off.


    One other note here is that you need to call the Set methods before your entry to setup the prices. Calling it after allows the previously used prices to work as the price upon activation.
    Code:
    SetStopLoss(.......); // sets it up, submitted upon entry fill
    SetProfitTarget(.......); // sets it up, submitted upon entry fill
    EnterShort(0, 1, "shortTrade");
    This is very important if you are calculating prices or using prices close to the market price. A farther away price you likely won't notice that the old price was used, a closer price may result in a rejection depending on the price calculated and if the order was valid or not.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      I have added bools to attempt to limit multiple orders from being submitted and ignored. They have helped, but I am still getting some duplicate orders sent which I am guessing is just the lag time between the broker receiving the order, accepting it, and then NT setting the order as active or != null. So far these duplicates do not seem to be creating any problems for me.


      Thank you very much for the info! Much appreciated

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by andrewtrades, Today, 04:57 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by chbruno, Today, 04:10 PM
      0 responses
      6 views
      0 likes
      Last Post chbruno
      by chbruno
       
      Started by josh18955, 03-25-2023, 11:16 AM
      6 responses
      436 views
      0 likes
      Last Post Delerium  
      Started by FAQtrader, Today, 03:35 PM
      0 responses
      8 views
      0 likes
      Last Post FAQtrader  
      Started by rocketman7, Today, 09:41 AM
      5 responses
      19 views
      0 likes
      Last Post NinjaTrader_Jesse  
      Working...
      X