Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Entering Trades With Limit Order - Issue with Playback Connection / Futures

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

    Entering Trades With Limit Order - Issue with Playback Connection / Futures

    Hello,

    I've been updating the Price Action Order Entry Buttons to enter with limit orders but have ran into an issue where the Stop(ExitStopMarket) and Profit Targets(ExitLimit)t don't match the actual order entry number.

    Now this only happens when trading Futures and only on playback (Historical or Market Replay).

    Made a quick video to show what happens. The first trades, only ES and NQ do not set proper limit or Stop. TSLA works just fine.
    On the 2nd trade, I switched it to a Market order instead of Limit. Then All of them work properly.

    >>>>>>>>>>>>>>>>>>>>>>>>
    Please see the video link below:
    LimitOrderEntryIssue
    >>>>>>>>>>>>>>>>>>>>>>>>

    Works perfectly fine with the following conditions:

    -With Stocks
    -Futures Work when trading Real time (With Sim Account)
    -Playback Futures with 'Market Order' only.


    Conditions where it doesn't set proper Stop and Profit (All 3 have to be met to not work):

    -Only on Playback (Historical or Market Replay)
    -Only with Futures
    -Only when using Limit Order to enter.

    I made a quick simple strategy to try and narrow down the root of the problem but the same issue still exists. (Same from video)

    Code:
    namespace NinjaTrader.NinjaScript.Strategies.TradeSimpleStrategies.CurrentTest
    {
    public class EntryExample : Strategy
    {
    
    private bool myFreeTradeShort = true;
    
    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"";
    Name = "Entry Example";
    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;
    
    }
    else if (State == State.Configure)
    {
    
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;
    
    if(State != State.Realtime ) return ;
    
    if (CurrentBars[0] < 2)
    return;
    
    //>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>
    if ((Close[0] < Low [1])
    && (Position.MarketPosition == MarketPosition.Flat))
    {
    EnterShortLimit(100, Low[1], "MyEntryShort");
    
    myFreeTradeShort = true;
    }
    
    
    if (Position.MarketPosition == MarketPosition.Short && myFreeTradeShort == true)
    {
    ExitShortStopMarket(0, true, Position.Quantity, High[1], "MyStopShort", "MyEntryShort");
    ExitShortLimit(0, true, Position.Quantity, Low[1] - (High[1] - Low[1]) *3, "MyTargetShort", "MyEntryShort");
    
    myFreeTradeShort = false;
    }
    
    
    }
    
    
    }
    }
    Up to this point, I've only really used market orders to enter trades and have mainly concentrated on Stocks. So perhaps I'm missing something obvious.

    Please let me know if there is an oversight on my end or if this just the nature of Futures with the playback feature.

    Thank you!

    #2
    Hello TradeSimple(Dre),

    May we have some debugging output to understand what part of the code is where the unexpected behavior is?

    Is the condition evaluating as true and the line of code with the order method is being reached?

    Is TraceOrders showing the order is being submitted or ignored, rejected, or automatically cancelled?

    Below is a link to a forum post that demonstrates using Print() and TraceOrders to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Please provide the output saved to a text file and let us know the order id or the date and time to look for in the output.
    Last edited by NinjaTrader_ChelseaB; 08-30-2022, 07:34 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi NinjaTrader_ChelseaB,


      I attached the TraceOrder from the output screen. It seems it's reading the correct Quantity of shares(Set to 100 for this) and it's reading the correct price levels to set. Just doesn't set the correct quantity on the STP and LMT
      I attached another screenshot. It shows the correct 100 shares entered. But the LMT and STP get stuck at only 1 share.

      On the Text file: The second entry is a Market order submitted with the same quantity. In this condition, it sets the Proper LMT and STP quantity

      It's giving me the same issue now with Real time data on a Sim Account. Just with Futures. And still only with Limit orders. Market orders seem to work fine.


      Thank you for your help. Please let me know if you require any additional info

      Attached Files

      Comment


        #4
        Hello,

        I'm not certain I am understanding.

        The output shows:

        2022-08-28 6:54:57 PM Strategy 'PA Multiple TEST/252717178': Entered internal SubmitOrderManaged() method at 2022-08-28 6:54:57 PM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=100 LimitPrice=12522.50 StopPrice=0 SignalName='MyTargetLong' FromEntrySignal='MyEntryLong'

        The quantity for this limit order is submitted with 100.. What are you expecting?

        Are you certain this order is the order from this code? Are you printing the order object in OnOrderUpdate() to confirm?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hello,

          Thank you for your reply.

          Yes the Limit order entry is set to a quantity of 100.

          The Limit(Profit target) and Stop(Stop Loss) are both supposed to be a quantity of 100 as shown from the log.
          The problem is the Profit and Stop do not actually update to the full 100 share quantity. (The screenshot attached above shows only 1 Share for the LMT and STP instead of 100. Even thou it entered the 100 shares as it should)

          The above prints are from my main code with the same issue. Here I'll attach the prints for the code from the first post.

          I am using OnBarUpdate
          Attached Files

          Comment


            #6
            Hello TradeSimple(Dre),

            Is it part filled on a slow moving instrument?

            I see the order submitted.

            2022-08-28 8:02:19 PM Strategy 'Entry Example/252717180': Entered internal SubmitOrderManaged() method at 2022-08-28 8:02:19 PM: BarsInProgress=0 Action=BuyToCover OrderType=StopMarket Quantity=34 LimitPrice=0 StopPrice=12461.25 SignalName='MyStopShort' FromEntrySignal='MyEntryShort'

            Perhaps this was the quantity filled when the exit is called.

            Print the order object in OnOrderUpdate() to see how much the entry and exits are filling.

            Provide the output from the output window with your reply.


            An example you might find helpful, ProfitChaseStopTrailExitOrdersExample, submits orders from OnOrderUpdate / OnExecutionUpdate().


            I look forward to further assisting.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,

              Thank you again for your reply.

              Is it part filled on a slow moving instrument?

              Perhaps this was the quantity filled when the exit is called.
              You are right. I think this may have been the issue all along. I've set a condition to only execute the Profit and Stop once the Position Quantity is equal to the entry order amount. This seems to have eliminated the problem I was having.

              Then incase of a partial fill, a different condition to set the Profit and Stop to the new quantity filled once the candle is closed and Limit Order is cancelled.

              Not sure if there is a better way to go about this with the Managed Approach. Ultimately I will need to learn unmanaged as it will probably give better options. But for the mean time, this is a work around that seems to function how I need it to.

              Thank you for all your help!

              Comment


                #8
                Hello TradeSimple(Dre),

                Not sure if there is a better way to go about this with the Managed Approach.
                Are you finding the example I have provided you also causes the same behavior?
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hello NinjaTrader_ChelseaB,

                  I've been testing it out. This way of entering trades is still a bit too advanced for me at this time.

                  Using the ProfitChaseStopTrailExitOrdersExample :

                  Tried changing the EnterLong(1, 1, "entry"); to -> EnterLongLimit(1,1, "entry");
                  but wasn't able to successfully enter a trade using a Limit Order (I'm sure I'm just doing something wrong. Just need to understand this better)

                  However, I did notice an issue once it was in the trade already. A potential Partial Fill from the 'Limit Order' and then a reversal to the 'Stop Order' would cause an overfill and reversal condition.
                  See this video for an example: ProfitChaseStopOverfill

                  Either way, it looks like there is a lot more learning that needs to be done on my end before I can start implementing these more advanced methods.

                  Thank you again for all your help. I really do appreciate it!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  53 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  130 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  70 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  44 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  49 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X