Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to place LongStop and ShortStop at same time with stoploss and profittargets

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

    How to place LongStop and ShortStop at same time with stoploss and profittargets

    Hi I'm new to NinjaTrader. I'm trying to open a LongStop and ShortStop at the same time. I am able to do this as long as I don't have any stoploss or profit targets set. As soon as I set these then only the first stop entry I create is created. When I run the code below I do not get a ShortEntryOrder object if I have created stoploss and profit targets.


    HighOfDay = High[HighestBar(High, 24)];
    LowOfDay = Low[LowestBar(Low, 24)];

    LongEntryOrder = EnterLongStopMarket(0, true, 100000, HighOfDay, "Longtest");
    ShortEntryOrder = EnterShortStopMarket(0, true, 100000, LowOfDay, "Shorttest");

    if(LongEntryOrder != null)
    Print("First Long stop" + LongEntryOrder.Id);
    if(ShortEntryOrder != null)
    Print("First short stop" + ShortEntryOrder.Id);



    I'm entering in my stops and profittarget in the onorderupdate function as below. I have tried creating stops in onexecuteupdate as well and have also tried creating stops in the
    state.configure in onstatechange function with SetStopLoss and SetProfitTarget. But I'm always getting the same result where only the first stop order I have set gets created.

    Can someone please help me here. Is what I'm trying to do possible in Ninjatrader 8.

    Thanks,
    Mark

    if (LongEntryOrder != null && LongEntryOrder == order)
    {
    if (order.OrderState == OrderState.Filled)
    {
    Print("Set the long profit target and stop " + HighOfDay);
    LongStop = ExitLongStopMarket(0, true, 100000, HighOfDay - 0.001, "MyLongStop", "Longtest");
    LongProfit = ExitLongLimit(0, true, 100000, HighOfDay + 0.001, "MyShortTarget", "Longtest");
    LongEntryOrder = null;
    }
    }
    if (ShortEntryOrder != null && ShortEntryOrder == order)
    {
    if (order.OrderState == OrderState.Filled)
    {
    Print("Set the short profit target and stop " + LowOfDay);
    ShortStop = ExitShortStopMarket(0, true, 100000, LowOfDay + 0.001, "MyShortStop", "Shorttest");
    ShortProfit = ExitShortLimit(0, true, 100000, LowOfDay - 0.001, "MyShortTarget", "Shorttest");
    ShortEntryOrder = null;
    }
    }

    #2
    Originally posted by marcus99 View Post
    Hi I'm new to NinjaTrader. I'm trying to open a LongStop and ShortStop at the same time. I am able to do this as long as I don't have any stoploss or profit targets set. As soon as I set these then only the first stop entry I create is created. When I run the code below I do not get a ShortEntryOrder object if I have created stoploss and profit targets.


    HighOfDay = High[HighestBar(High, 24)];
    LowOfDay = Low[LowestBar(Low, 24)];

    LongEntryOrder = EnterLongStopMarket(0, true, 100000, HighOfDay, "Longtest");
    ShortEntryOrder = EnterShortStopMarket(0, true, 100000, LowOfDay, "Shorttest");

    if(LongEntryOrder != null)
    Print("First Long stop" + LongEntryOrder.Id);
    if(ShortEntryOrder != null)
    Print("First short stop" + ShortEntryOrder.Id);



    I'm entering in my stops and profittarget in the onorderupdate function as below. I have tried creating stops in onexecuteupdate as well and have also tried creating stops in the
    state.configure in onstatechange function with SetStopLoss and SetProfitTarget. But I'm always getting the same result where only the first stop order I have set gets created.

    Can someone please help me here. Is what I'm trying to do possible in Ninjatrader 8.

    Thanks,
    Mark

    if (LongEntryOrder != null && LongEntryOrder == order)
    {
    if (order.OrderState == OrderState.Filled)
    {
    Print("Set the long profit target and stop " + HighOfDay);
    LongStop = ExitLongStopMarket(0, true, 100000, HighOfDay - 0.001, "MyLongStop", "Longtest");
    LongProfit = ExitLongLimit(0, true, 100000, HighOfDay + 0.001, "MyShortTarget", "Longtest");
    LongEntryOrder = null;
    }
    }
    if (ShortEntryOrder != null && ShortEntryOrder == order)
    {
    if (order.OrderState == OrderState.Filled)
    {
    Print("Set the short profit target and stop " + LowOfDay);
    ShortStop = ExitShortStopMarket(0, true, 100000, LowOfDay + 0.001, "MyShortStop", "Shorttest");
    ShortProfit = ExitShortLimit(0, true, 100000, LowOfDay - 0.001, "MyShortTarget", "Shorttest");
    ShortEntryOrder = null;
    }
    }
    You will have to use unmanaged order methods. By conscious design, managed orders are explicitly barred from doing what you want to do.
    Last edited by koganam; 02-16-2016, 06:10 PM.

    Comment


      #3
      Hello,
      Koganam is correct in that you will need to use unmanaged orders to achieve this. Due to internal order handling rules with managed orders you can not generate an order to enter a position if there is a position is open and an order submitted by a set method (SetStopLoss() for example) is active and the order is used to open a position in the opposite direction.

      For more information on the internal order handling rules please see the following link: http://ninjatrader.com/support/helpG...d_approach.htm

      The unmanaged order approach does not use these rules though.
      For more information on the unmanaged order approach please see the following link: http://ninjatrader.com/support/helpG...d_approach.htm

      If we can be of any other assistance please let us know.
      Cody B.NinjaTrader Customer Service

      Comment


        #4
        Thanks Osikani and Cody for your quick response. Makes sense. I'll look into unmanaged orders.

        Cheers,
        Mark

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by chbruno, Today, 04:10 PM
        0 responses
        3 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        6 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by frslvr, 04-11-2024, 07:26 AM
        9 responses
        127 views
        1 like
        Last Post caryc123  
        Working...
        X