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

Set Order object to an ExitShortLimit order method

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

  • NinjaTrader_Jim
    replied
    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.

    Leave a comment:


  • Orden33
    replied
    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");
    }
    }

    }

    }

    Leave a comment:


  • NinjaTrader_Jim
    replied
    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.

    Leave a comment:


  • Orden33
    started a topic Set Order object to an ExitShortLimit order method

    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");
    }
    }




    }

    }

Latest Posts

Collapse

Topics Statistics Last Post
Started by ScottWalsh, Today, 04:29 PM
0 responses
0 views
0 likes
Last Post ScottWalsh  
Started by rtwave, 04-12-2024, 09:30 AM
2 responses
20 views
0 likes
Last Post rtwave
by rtwave
 
Started by tsantospinto, 04-12-2024, 07:04 PM
5 responses
68 views
0 likes
Last Post tsantospinto  
Started by cre8able, Today, 03:20 PM
0 responses
7 views
0 likes
Last Post cre8able  
Started by Fran888, 02-16-2024, 10:48 AM
3 responses
49 views
0 likes
Last Post Sam2515
by Sam2515
 
Working...
X