• 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

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, 05: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 rwilliam, Today, 01:54 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by franco12364, Today, 11:27 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by YevhenShynkarenko, Today, 11:48 AM
        3 responses
        21 views
        0 likes
        Last Post YevhenShynkarenko  
        Started by NinjaTrader_ChrisL, Today, 11:21 AM
        0 responses
        21 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Started by lunardiplomacy, Today, 08:09 AM
        3 responses
        14 views
        0 likes
        Last Post NinjaTrader_Kate  
        Working...
        X