Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Placing orders in both directions

Collapse
X
 
  • 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)?

    #2
    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 - https://ninjatrader.com/support/help...antedPositions

    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 - https://ninjatrader.com/support/help...d_approach.htm

    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

    Comment


      #3
      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...

      Comment


        #4
        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 - https://ninjatrader.com/support/help...script_cod.htm

        TraceOrders - https://ninjatrader.com/support/help...aceorders2.htm

        Debugging in the Strategy Builder - https://drive.google.com/file/d/1mTq...w?usp=drivesdk

        Playback Connection - https://ninjatrader.com/support/help...connection.htm

        Debugging Demo - https://drive.google.com/file/d/1rOz...w?usp=drivesdk

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

        Comment


          #5
          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 https://www.screencast.com/t/ykpClRA77), 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:	109
Size:	103.4 KB
ID:	1102859
          Click image for larger version

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

          Comment


            #6
            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 - https://drive.google.com/file/d/1q3C...w?usp=drivesdk

            We look forward to assisting.
            JimNinjaTrader Customer Service

            Comment


              #7
              Thank you! It helped!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rayko, Today, 03:12 AM
              0 responses
              2 views
              0 likes
              Last Post rayko
              by rayko
               
              Started by [email protected], Yesterday, 06:03 PM
              1 response
              5 views
              0 likes
              Last Post NinjaTrader_Marco  
              Started by thanajo, Today, 03:00 AM
              0 responses
              1 view
              0 likes
              Last Post thanajo
              by thanajo
               
              Started by Emma1, Yesterday, 07:15 PM
              1 response
              7 views
              0 likes
              Last Post MicroTrends  
              Started by elliot5, Today, 12:45 AM
              3 responses
              9 views
              0 likes
              Last Post elliot5
              by elliot5
               
              Working...
              X