• 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 trail limit entry and stop?

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

    How to trail limit entry and stop?

    Hi,

    I'm working on a strategy that has a limit entry order and stoploss trailing indicator values. Historical trades seem to plot as they should, yet in realtime, the pending orders are cancelled every other bar and are not replaced with new orders though the conditions still remain true. How do I either modify the limit price to the new indicator value, or cancel and replace the order so that I always have an active order when the conditions are true?

    protected override void OnBarUpdate()
    {

    if (CurrentBars[0] < 51)
    return;

    // Set 1
    if (EMA1[0] > EMA2[0])
    {
    EnterLongLimit(10000, EMA(Close, 50)[0] + (TickSize * 10), "AverageBuy" + CurrentBar);
    SetStopLoss(CalculationMode.Price, EMA(Close, 50)[0] - (TickSize * 100) );
    }

    #2
    Hello Ticnician,

    Thanks for your post and welcome to the forums!

    Orders submitted with the Managed Approach (the NinjaScript approach taken with the Strategy Builder) will only stay alive until the next bar is processed. To keep the order alive the Enter method will need to be called on each bar iot should be active. If you are unlocking the code, you can use the IsLiveUntilCancelled overloads to keep orders alive until you cancel them or their Time in Force is reached.

    IsLiveUntilCancelled - https://ninjatrader.com/support/help...ancelledOrders

    Help Guide syntax - EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)

    Information on EnterLongLimit parameters can be found here - https://ninjatrader.com/support/help...rlonglimit.htm

    If you would like to explicitly cancel orders in your logic, then you may use CancelOrder. Please note that you will need to track these orders as Order objects in order to use CancelOrder. Please see the example below and associated documentation for more details.

    SampleCancelOrder - https://ninjatrader.com/support/help...thod_to_ca.htm

    Also to note, SetProfitTarget/SetStopLoss should be set to an initial level when the strategy is in a flat position to ensure it is submitted to an appropriate level when your next Entry order fills. Please see the example and documentation below for further details.

    SamplePriceModification - https://ninjatrader.com/support/help...of_stop_lo.htm

    Please let me know if I can be of further assistance.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by xsgex, Yesterday, 09:46 PM
    0 responses
    2 views
    0 likes
    Last Post xsgex
    by xsgex
     
    Started by Steve L, Yesterday, 09:36 PM
    0 responses
    1 view
    0 likes
    Last Post Steve L
    by Steve L
     
    Started by krugman25, Yesterday, 09:34 PM
    0 responses
    4 views
    0 likes
    Last Post krugman25  
    Started by indy73, Yesterday, 04:42 PM
    0 responses
    15 views
    0 likes
    Last Post indy73
    by indy73
     
    Started by Italianforex, Yesterday, 06:20 AM
    2 responses
    13 views
    0 likes
    Last Post gplatis
    by gplatis
     
    Working...
    X