• 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

Set Order object to an ExitShortLimit order method

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

    Set Order object to an ExitShortLimit order method

    Hello,

    I´m having trouble using Order objects set to ExitShortLimit for my target and stoploss in an "Advanced Managed Approach" since I don´t want to use SetProfitTarget and SetStopLoss methods. My aim is to have these orders cancel each other once either is filled but cannot figure out why they are not being placed.


    Here is my code:




    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class AddSeriesTest : Strategy
    {

    #region Variables
    private Order EntryOrder = null;
    private Order TargetOrder = null;
    private Order StopLossOrder = null;
    #endregion

    protected override void OnStateChange(){
    if (State == State.SetDefaults)
    {
    Description = @"";
    Name = "AddSeriesTest";
    Calculate = Calculate.OnBarClose;
    EntriesPerDirection = 1;
    EntryHandling = EntryHandling.AllEntries;
    IsExitOnSessionCloseStrategy = true;
    ExitOnSessionCloseSeconds = 30;
    IsFillLimitOnTouch = false;
    MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
    OrderFillResolution = OrderFillResolution.Standard;
    Slippage = 0;
    StartBehavior = StartBehavior.WaitUntilFlat;
    TimeInForce = TimeInForce.Gtc;
    TraceOrders = false;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 0;
    IsInstantiatedOnEachOptimizationIteration = true;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;

    }


    }

    protected override void OnBarUpdate()
    {

    if(BarsInProgress == 0 && ToDay(Time[0]) == 20131212 && ToTime(Time[0]) == ToTime(9,32,00) )
    {

    EntryOrder = EnterShortLimit(BarsInProgress,true, 1, Close[0],"Entry");
    TargetOrder = ExitShortLimit(BarsInProgress, true, 1, Close[0] - 1.5 , "ProfitTarget", "Entry");
    StopLossOrder = ExitShortLimit(BarsInProgress, true, 1, Close[0] + 2.5 , "StopLoss", "Entry");
    }
    }




    }

    }

    #2
    Hello Orden33,

    Thanks for your post.

    Our SampleOnOrderUpdate strategy and associated documentation can show you how to properly use Order objects and the OnExecutionUpdate and OnOrderUpdate events and accomplish your goal.

    The issue with your strategy is that it is submitting entry and exit orders at the same time when the Managed Approach requires that the strategy is in a position before you can submit an exit order.

    Please be sure to note the internal rules of the Managed Approach in addition to the resources involved with SampleOnOrderUpdate.

    SampleOnOrderUpdate - https://ninjatrader.com/support/help...and_onexec.htm

    Managed Approach - https://ninjatrader.com/support/help...d_approach.htm

    Please let us know if you have any questions on these materials.
    JimNinjaTrader Customer Service

    Comment


      #3
      Hi Jim, thanks for your reply,

      I have now made the change so the ExitShortLimit orders set when the OnExecutionUpdate method for the entry order is executed but still causes conflict.


      Here is the code:



      namespace NinjaTrader.NinjaScript.Strategies
      {
      public class AddSeriesTest : Strategy
      {

      #region Variables
      private Order EntryOrder = null;
      private Order TargetOrder = null;
      private Order StopLossOrder = null;
      private double EntryPrice;
      #endregion

      protected override void OnStateChange(){
      if (State == State.SetDefaults)
      {
      Description = @"";
      Name = "AddSeriesTest";
      Calculate = Calculate.OnBarClose;
      EntriesPerDirection = 1;
      EntryHandling = EntryHandling.UniqueEntries;
      IsExitOnSessionCloseStrategy = true;
      ExitOnSessionCloseSeconds = 30;
      IsFillLimitOnTouch = false;
      MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
      OrderFillResolution = OrderFillResolution.Standard;
      Slippage = 0;
      StartBehavior = StartBehavior.WaitUntilFlat;
      TimeInForce = TimeInForce.Gtc;
      TraceOrders = false;
      RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;
      BarsRequiredToTrade = 0;
      IsInstantiatedOnEachOptimizationIteration = true;
      StopTargetHandling = StopTargetHandling.PerEntryExecution;

      }


      }

      protected override void OnBarUpdate()
      {
      /////////////////// Submits order if on a specific bar in the asigned Bars
      if(BarsInProgress == 0 && ToDay(Time[0]) == 20131212 && ToTime(Time[0]) == ToTime(9,32,00) )
      {
      // SetProfitTarget(CalculationMode.Ticks,6);
      // SetStopLoss(CalculationMode.Ticks,9);
      EntryPrice = Close[0];
      Print(EntryPrice);
      EntryOrder = EnterShortLimit(BarsInProgress,true, 1, EntryPrice,"Entry");

      }
      }


      protected override void OnExecutionUpdate (Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
      {

      if(execution.Order.Name == "Entry")
      {

      TargetOrder = ExitShortLimit(BarsInProgress, true, 1, (EntryPrice - 10) , "ProfitTarget", "Entry");
      StopLossOrder = ExitShortLimit(BarsInProgress, true, 1, (EntryPrice + 20) , "StopLoss", "Entry");
      }

      if(execution.Order.Name == "ProfitTarget")
      {

      Print(@"PT executed");

      }

      if(execution.Order.Name == "StopLoss")
      {

      Print(@"SL Executed");
      }
      }

      }

      }

      Comment


        #4
        Hello Orden33,

        I'm not sure what issue you are running into when you mention a conflict.

        Since the SampleOnOrderUpdate is a working example, I would recommend modifying that strategy as needed so the strategy is modelled to use these methods appropriately, and if you incur any issues, you can compare against the original example to check your work.

        Also, as a tip for posting code on the forums, you can place your code in [CODE] blocks so it is properly formatted and easier to read.

        I'm confident that you will be able to accomplish your goal by closely modelling the example. If you are having any issues using the sample provided, please let me know how you are testing so I can do the same on my end and give further feedback.

        I look forward to being of further assistance.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TazoTodua, Today, 07:17 AM
        0 responses
        1 view
        0 likes
        Last Post TazoTodua  
        Started by frankduc, Today, 07:02 AM
        0 responses
        1 view
        0 likes
        Last Post frankduc  
        Started by i2w8am9ii2, Today, 06:57 AM
        0 responses
        1 view
        0 likes
        Last Post i2w8am9ii2  
        Started by sidviciousX, Today, 06:47 AM
        1 response
        2 views
        0 likes
        Last Post NinjaTrader_RyanS  
        Started by buzzripper, Today, 06:14 AM
        0 responses
        1 view
        0 likes
        Last Post buzzripper  
        Working...
        X