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

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 mjairg, 07-20-2023, 11:57 PM
        3 responses
        213 views
        1 like
        Last Post PaulMohn  
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        4 responses
        544 views
        0 likes
        Last Post PaulMohn  
        Started by GLFX005, Today, 03:23 AM
        0 responses
        3 views
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        12 views
        0 likes
        Last Post XXtrader  
        Started by Waxavi, Today, 02:10 AM
        0 responses
        7 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Working...
        X