Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Pending EnterLongLimit cancelled in new Bar

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

    Pending EnterLongLimit cancelled in new Bar


    I have been trying for 15 days that not to cancel my EnterLongLimit at the end of the first candle. I tried it anyway
    What is wrong here? I would appreciate some help

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class diau : Strategy
    {
    private double Target;
    private Order myEntryOrder = null;
    private int barNumberOfOrder = 0;


    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "diau";
    Calculate = Calculate.OnEachTick;
    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 = 20;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    Target = 0;
    }
    else if (State == State.Configure)
    {
    }
    }

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 1)
    return;


    // Set 1
    if ((Close[1] > Open[1])
    && (myEntryOrder == null))
    {
    Target = (Low[1] + (-30 * TickSize)) ;
    myEntryOrder = EnterLongLimit(Convert.ToInt32(DefaultQuantity), Target, "hello");
    barNumberOfOrder = CurrentBar;


    }

    if (myEntryOrder != null && CurrentBar > barNumberOfOrder + 5 && myEntryOrder.OrderState == OrderState.Working)
    {
    CancelOrder(myEntryOrder);
    myEntryOrder = null;
    }
    }


    }
    }


    #2
    Hello milfocs,

    When using the managed approach orders are automatically cancelled after the submission bar closes, unless the overload with isLiveUntilCancelled is used and set to true.

    EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)

    "isLiveUntilCancelled - The order will NOT expire at the end of a bar, but instead remain live until the CancelOrder() method is called or its time in force is reached.​"

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      oki thanks,
      I've change it, but now it doesn't put the enterlonglimit

      BarsRequiredToTrade = 20;
      // Disable this property for performance gains in Strategy Analyzer optimizations
      // See the Help Guide for additional information
      IsInstantiatedOnEachOptimizationIteration = true;
      Target = 0;
      Velestime = 1;
      }
      else if (State == State.Configure)
      {
      }
      }

      protected override void OnBarUpdate()
      {
      if (BarsInProgress != 0)
      return;

      if (CurrentBars[0] < 1)
      return;

      // Set 1
      if (Close[1] > Open[1])
      {
      Target = (Open[1] + (-30 * TickSize)) ;
      EnterLongLimit(0, true, Convert.ToInt32(DefaultQuantity), Target, "LongEntry");
      }

      }
      }
      }​

      Comment


        #4
        Hello milfocs,

        Your code would be updating the price of the that order on every bar update the condition is true (instead of submitting the order once).

        One line above the condition, print the time of the bar, print Close[1], Open[1], and print GetCurrentAsk().

        Enable TraceOrders and print the order.ToString() object in OnOrderUpdate().

        Below is a link to a support article on using Print() and TraceOrders to understand behavior.


        Re-run the script and provide the output from the output window.

        We want to see the limit price of the order is above the ask price for the order to fill on each bar update.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by charlesugo_1, 05-26-2026, 05:03 PM
        0 responses
        50 views
        0 likes
        Last Post charlesugo_1  
        Started by DannyP96, 05-18-2026, 02:38 PM
        1 response
        141 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        160 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        96 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        275 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Working...
        X