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

About place long & short together

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

    About place long & short together

    Hello...

    I have seen all post about rules placing opposite Stop Order together, OCO and limitations but I do not understand something please...

    I have test in manual trade and is possible to place two stop-order above and below price





    ...when enter one the other will be the stop.




    I'm working in a automatic Strategy and I'm trying to do the same but I cannot do it due "Internal Order Handling Rules"

    The strategy place only the first.
    This is the code to place 2 orders:

    Code:
    EnterLongStop(DefaultQuantity, Close[0] + bBracket * TickSize, "Buy Trade");
    EnterShortStop(DefaultQuantity, Close[0] - bBracket * TickSize, "Sell Trade");

    I have seen the rules:


    Methods that generate orders to enter a position will be ignored if:

    The strategy position is flat and an order submitted by an enter method (EnterLongLimit() for example) is active and the order is used to open a position in the opposite direction


    My questions:

    1. Why in manual trade I can do it?
    2. How can i do it with automatic strategy? Can you tell me please the code to do it?

    Many thanks!

    #2
    Hello ClauTrade,

    Thank you for your post.

    1. Manually trading allows you to manage the orders and positions manually. the Managed Order Approach has specific items in place to avoid overfills, and other items. If you want to remove these items in order to place whatever orders you want you would look into the Unmanaged Order Approach, keep in mind this is for advanced programmers: http://ninjatrader.com/support/helpG...d_approach.htm

    2. We would not provide programming services and I would highly recommend that if you intend to go the route of the Unmanaged Approach that you fully understand it before implementing it.

    Another option is to use the Managed Approach but not submit the orders until their price reached. So you would have a double variable hold the price you want and compare that to the Close (or High or Low) and then when the price is reached you can submit the respective order and then it's protective stop market order.

    Below is an example of a bracket based on the High and Low of the prior trading day, and how to place an entry when one level is hit and how to place the stop as the other level. Please review the code below.
    Code:
    public class ExampleBracket : Strategy
        {
            #region Variables
            private double buyLevel = 0;
    		private double sellLevel = 0;
            #endregion
    		
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
            }
    		
            protected override void OnBarUpdate()
            {
    			if (Bars.FirstBarOfSession)
    			{
    				buyLevel = PriorDayOHLC().PriorHigh[0];
    				sellLevel = PriorDayOHLC().PriorLow[0];
    			}
    			if (buyLevel == 0 || sellLevel == 0) return;
    			
    			if (High[0] >= buyLevel)
    			{
    				EnterLong();
    			}
    			if (Low[0] <= sellLevel)
    			{
    				EnterShort();
    			}
    			
    			if (Position.MarketPosition == MarketPosition.Long)
    			{
    				ExitLongStop(sellLevel);
    			}
    			if (Position.MarketPosition == MarketPosition.Short)
    			{
    				ExitShortStop(buyLevel);
    			}
            }
        }

    Comment


      #3
      Hello!

      many thanks for suggest! .. I solve with Unmanaged Order!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by helpwanted, Today, 03:06 AM
      1 response
      8 views
      0 likes
      Last Post sarafuenonly123  
      Started by Brevo, Today, 01:45 AM
      0 responses
      7 views
      0 likes
      Last Post Brevo
      by Brevo
       
      Started by aussugardefender, Today, 01:07 AM
      0 responses
      5 views
      0 likes
      Last Post aussugardefender  
      Started by pvincent, 06-23-2022, 12:53 PM
      14 responses
      242 views
      0 likes
      Last Post Nyman
      by Nyman
       
      Started by TraderG23, 12-08-2023, 07:56 AM
      9 responses
      385 views
      1 like
      Last Post Gavini
      by Gavini
       
      Working...
      X