No announcement yet.

Partner 728x90


Placing orders in both directions

  • Filter
  • Time
  • Show
Clear All
new posts

    Placing orders in both directions

    Hi. Please kindly help me figure out the following:

    My strategy involves entering a position through stop orders. The condition prescribes the simultaneous firing of an order for long and short at a certain distance from the market. However, when the condition is fulfilled, the strategy fires only a long order, while the short order is missing.
    Strategy created in Strategy Builder. Is there any default reason why a Ninja trader cannot place long and short orders at the same time (whichever to hit first)?

    Hello Aporshnev,

    Thanks for your post.

    The Strategy Builder generates Managed Approach code which includes internal rules that prevent unwanted positions. The Managed Approach does not allow for custom OCO (One Cancels Other) order handling with Enter and Exit methods, so we could not set up logic in a Strategy Builder strategy to "handle X direction if order fills, and cancel Y order." The other order would be left in place which could result in an unwanted position. Thus, the internal rules prevent these submissions.

    Managed Approach Internal Rules -

    This is certainly possible with the Unmanaged Approach however. The Unmanaged Approach is reserved for advanced programmers and would be a very large step from using the Strategy Builder.

    If you have a programming background, please see the example I attached.

    Unmanaged Approach -

    If you are interested in services to have an Unmanaged strategy written for you that meets your needs, please let us know and we can have a colleague share some information on NinjaScript Consulting services in our EcoSystem.

    We look forward to assisting.
    Attached Files
    JimNinjaTrader Customer Service


      OK I understood.
      In this case, I have one more question that may be related to Managed approach: when the transaction cycle is completed (i.e., entering a position, moving the stop to breakeven, fulfilling the profit target ) and the conditions are repeated again, my idea was to the strategy to replicate the trade and rotate the cycle as many times as the conditions will be met, as long as the strategy works. However, after exiting the position and repeating the condition, my strategy does not fire entry order again. Could this be related to the Managed approach? In my case, a variable like “trade flag” works for me. I asked this question here. But so far I can’t find the answer...


        Hello Aporshnev,

        Resetting variables would be related to how your logic is set up rather than a concept of the Managed Approach.

        Conditions and actions will be processed sequentially from Condition Set 1 and onward. This logic will also be processed with each new bar. The Strategy Builder strategies I have attached can be referenced for examples that reset some variables to control a move to Breakeven.

        Creating your own logic will often require that the logic gets checked if it is not working as intended. Investigating further will involve taking debugging steps to observe what values the variables hold when you expect them to have a certain value. This can tell you why an action was not met and will help you to see how you can modify your logic to accomplish your goal.

        The Simulated Data Feed and the Playback Connection can help to repeat cases which you wish to investigate further and you can add debugging prints to monitor how the logic is evaluating.

        Debugging Tips -

        TraceOrders -

        Debugging in the Strategy Builder -

        Playback Connection -

        Debugging Demo -

        Let us know if you have any additional questions.
        Attached Files
        JimNinjaTrader Customer Service


          Thank you for the detailed instructions.

          However, I want to understand the script execution logic in the following sense:

          In my strategy there are 14 sets; upon activation and the onset of conditions, all sets are executed in order as it should be; Set 13 provides for the exit from the position, after which the general logic ends - the trade is completed. However, the conditions may repeat and set 1 will turn the variable back to true. And according to the logic of strategy, the position should open again. But as you can see in the video (see link, the trade entry does not repeat.

          Question: after the sequential execution of all sets, is the strategy considered complete and should I re-enable it manually (remarking the checkbox)? Or will the script be automatically executed again from set 1, in which the variable becomes true? Because at the moment it does not re-enter the position.

          I get the feeling that the Ninja Trader correctly executes sets from the first to the last in order, after which he “forgets” about this particular script, since it considers it completed. Please confirm that my understanding is right or wrong.

          Click image for larger version

Name:	sets_false.jpg
Views:	94
Size:	103.4 KB
ID:	1102859
          Click image for larger version

Name:	sets_true.jpg
Views:	61
Size:	98.7 KB
ID:	1102860


            Hello Aporshnev,

            Please use debugging prints to observe and follow your strategy logic. These steps would also be taken to see why some condition is becoming true if you are not expecting it to become true.

            All condition sets are processed sequentially, with each bar update. For example, if you enable a strategy, it will process all historical bars on the chart following Calculate.OnBarClose behaviors. All condition set is processed (1-14) for each bar.

            If you enable the strategy with Calculate.OnEachTick, the strategy will process historical bars following Calculate.OnBarClose processing, and then when the strategy starts processing realtime data, it will process all condition sets for each tick that updates the developing bar.

            You can set up some condition sets with a print of the CurrentBar index to see how this logic is processed. Se below for an example demonstration.

            Demo -

            We look forward to assisting.
            JimNinjaTrader Customer Service


              Thank you! It helped!


              Latest Posts


              Topics Statistics Last Post
              Started by sidlercom80, Today, 02:40 AM
              1 response
              Last Post NinjaTrader_PaulH  
              Started by b16_aln, Today, 01:52 AM
              0 responses
              Last Post b16_aln
              by b16_aln
              Started by junkone, Yesterday, 08:55 PM
              2 responses
              Last Post junkone
              by junkone
              Started by adaeiqendqw, 01-16-2021, 02:56 AM
              1 response
              Last Post NinjaTrader_Jason  
              Started by [email protected], Yesterday, 06:10 PM
              5 responses
              Last Post NinjaTrader_ChrisSch