• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop limits for reversing strategy

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

    Stop limits for reversing strategy

    I'm trying to reverse with stop limit orders under onexecution. So if I get filled long or short, a target, an exit stop limit, and a reversing stop limit would be placed. For some reason from what I can tell, the stop limits aren't being placed at all, only the target. I've been using position.avgprice for the stop limits' "limit" and "stop" prices.
    [CODE
    {
    if(execution.Order != null && execution.Order.OrderState == OrderState.Filled && execution.Order.Name == "short" && execution.Order.OrderAction == OrderAction.SellShort )
    {
    SetProfitTarget("short", CalculationMode.Ticks, 18);
    ExitShortStopLimit(Position.AvgPrice + 5, Position.AvgPrice + 5, "short");
    EnterLongStopLimit(Position.AvgPrice + 5, Position.AvgPrice + 5, "long");
    }
    if(execution.Order != null && execution.Order.OrderState == OrderState.Filled && execution.Order.Name == "long" && execution.Order.OrderAction == OrderAction.Buy )
    {
    SetProfitTarget("long", CalculationMode.Ticks, 18);
    ExitLongStopLimit(Position.AvgPrice - 5, Position.AvgPrice - 5, "long");
    EnterShortStopLimit(Position.AvgPrice - 5, Position.AvgPrice - 5, "short");
    }

    }

    sampras010 is offline
    ][/CODE]

    #2
    Hello,
    Thank you for your post.
    The reason the Exit stop limit orders are being ignored is due to the internal order handling rule that methods that generate orders to exit a position will be ignored if a position is open and there is an active order submitted by a set method, such as the SetProfitTarget() method.
    The reason that the Enter stop limit orders are being ignored is due to the internal order hanlding rule that methods that generate orders to enter a position will be ignored if a position is open and an active order submitted by a set method, such as the SetProfitTarget() method, and the order is used to open a position in the opposite direction.
    For more information on the internal handling order rules with Managed order methods please see the following link: http://ninjatrader.com/support/helpG...d_approach.htm

    You would need to use the Unmanaged order methods to achieve what you are wanting to accomplish with your strategy. The Unmanaged approach is reserved for VERY EXPERIENCED programmers. In place of the convenience layer that the Managed approach offered, the Unmanaged approach instead offers ultimate flexibility in terms of order submission and management. For more information on using the Unmanged Approach please see the following link: http://ninjatrader.com/support/helpG...d_approach.htm
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      Hello,
      OCO IDs must be unique for them to submit properly and will need to be the same for the orders you are wanting to submit with OCO.
      Please try running with unique OCO IDs. You can create a unique OCO ID by doing something like the following :

      Code:
      shorttarget = SubmitOrder(0, OrderAction.BuyToCover, OrderType.Limit, 1, Position.AvgPrice - 18, 0, "short", "OCOOrder" + CurrentBar);
      shortstop = SubmitOrder(0, OrderAction.BuyToCover, OrderType.StopLimit , 1, Position.AvgPrice + 2, Position.AvgPrice + 2, "short", "OCOOrder" + CurrentBar);
      Cody B.NinjaTrader Customer Service

      Comment


        #4
        I tried again with this
        [CODE
        shorttarget = SubmitOrder(0, OrderAction.BuyToCover, OrderType.Limit, 1, Position.AvgPrice - 18, 0,"shortoco", "shorttarget");
        shortstop = SubmitOrder(0, OrderAction.BuyToCover, OrderType.StopLimit , 1, Position.AvgPrice + 2, Position.AvgPrice + 2, "shortoco", "shortstop");
        longreverse = SubmitOrder(0, OrderAction.Buy, OrderType.StopLimit , 1, Position.AvgPrice + 2, Position.AvgPrice + 2, "longoco", "long");
        ][/CODE]


        Still, the orders under onexecution are being ignored.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by w0lverine, Today, 08:22 PM
        0 responses
        1 view
        0 likes
        Last Post w0lverine  
        Started by dkbyond, Today, 04:11 PM
        0 responses
        5 views
        0 likes
        Last Post dkbyond
        by dkbyond
         
        Started by markus3500, Today, 03:29 PM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_EricB  
        Started by bohenriksen, Today, 04:00 AM
        1 response
        21 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by brett0, Today, 12:33 PM
        3 responses
        17 views
        0 likes
        Last Post marcus2300  
        Working...
        X