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

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 kevinenergy, 02-17-2023, 12:42 PM
        123 responses
        2,880 views
        1 like
        Last Post SilverSurfer1  
        Started by warpinator, Yesterday, 10:44 AM
        2 responses
        17 views
        0 likes
        Last Post warpinator  
        Started by rayyyu12, Today, 03:59 PM
        0 responses
        6 views
        0 likes
        Last Post rayyyu12  
        Started by calmcosmia, Today, 03:07 PM
        4 responses
        13 views
        0 likes
        Last Post calmcosmia  
        Started by Tim-c, Today, 02:34 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X