Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Having trouble with EnterLongLimit()

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

    Having trouble with EnterLongLimit()

    It seems my limit price keeps moving, most likely along with the actual ask/bid price. For my code below, my strategy shows numerous canceled orders and the entry won't execute. The canceled orders are around the time that my if statements are being satisified. Any ideas?

    CalculateOnBarClose = false;

    if (entry requirements here)
    {
    EnterLongLimit(DefaultQuantity, Close[0] + 1, "Long Entry One");

    if (profit loss requirements here)
    {
    SetStopLoss(CalculationMode.Ticks, 12);
    }
    }

    My reasoning is that with CalculateOnBarClose = false, my Close[0] price is moving along with the current price since the strategy updates tick-by-tick, and each time it updates and satisfies the if statements, then another long limit is entered at a different Close[0] price. However, I thought my Close[0] price should have been the close of the last bar, which is unchanging. Please let me know if this could be the case and how I can fix it.

    Thanks,
    Lee

    #2
    Lee,

    When you use EnterLongLimit() with that signature it will auto expire on every bar if you do not resubmit the order to keep it alive. This means that if your conditional if-statement is no longer true the order would be expired and cancelled. To prevent this you can either reprogram the logic to have the if-statement true throughout the entire life of the order, or you can use the signature for EnterLongLimit() that uses liveUntilCancelled set to true.




    Code:
    EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I understand setting LiveUntilCanceled to true and then using a CancelOrder() when I want the order canceled, but could you explain in detail what you mean by reprogramming the logic to have the if-statement true throughout the entire life of the order? Or maybe you can provide a very simple code as an example of what you mean?

      Comment


        #4
        For example, if my condition was something like this:

        Code:
        if (CrossAbove(SMA(10), SMA(20), 1))
             EnterLongLimit(...);
        You can see that a cross over condition would only be true on 1 bar. This becomes a problem if we wanted the limit order to be kept in the market until it gets filled or otherwise cancelled. The very next bar this order would be expired if we left it alone like this.

        Now consider this approach:

        Code:
        if (keepAlive == false && CrossAbove(SMA(10), SMA(20), 1))
        {
             EnterLongLimit(...);
             keepAlive = true;
        }
        else if (keepAlive)
             EnterLongLimit(...);
        The order is resubmitted regardless of the original cross over condition and therefore kept alive. All you need to complete this approach would be to designate a condition (if desired) to set keepAlive to false and then the order would auto expire afterwards.
        Josh P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Tim-c, Today, 03:54 AM
        0 responses
        3 views
        0 likes
        Last Post Tim-c
        by Tim-c
         
        Started by FrancisMorro, Today, 03:24 AM
        0 responses
        2 views
        0 likes
        Last Post FrancisMorro  
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,772 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        31 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        945 views
        0 likes
        Last Post spwizard  
        Working...
        X