Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

New Strategy - Orders don't get executed

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

    New Strategy - Orders don't get executed

    I'm facing a few issues with this basic code.

    1) Orders don't get executed even when the conditions are met (Long and Short)
    2) For some reason, the strategy starts with a current position size of 1 when it should start with 0

    How do I fix the 2 issues listed above? I've pasted the code below and also attached screenshots of the log and output.

    HERE'S THE CODE

    region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion

    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class TestZ20EMAForCoding : Strategy
    {
    private int Var_TakeProfit;
    private int Var_StopLoss;
    private double Var_20EMA_Price;
    private double Var_Order_Entry_Price;
    private int Var_ATR_Val;
    private int Var_Position;

    private EMA EMA1;
    private RSI RSI1;
    private MACD MACD1;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "TestZ20EMAForCoding";
    Calculate = Calculate.OnBarClose;
    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 = true;
    RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
    StopTargetHandling = StopTargetHandling.PerEntryExecution;
    BarsRequiredToTrade = 0;
    // Disable this property for performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = true;
    ProfitTarget = 6;
    StopLoss = 6;
    Var_TakeProfit = 1;
    Var_StopLoss = 1;
    Var_Order_Entry_Price = 0;
    Var_ATR_Val = 1;
    Var_Position = 1;
    }
    else if (State == State.Configure)
    {
    }
    else if (State == State.DataLoaded)
    {
    EMA1 = EMA(Close, 20);
    RSI1 = RSI(Close, 14, 3);
    MACD1 = MACD(Close, 12, 26, 10);
    SetProfitTarget(Convert.ToString(ProfitTarget), CalculationMode.Currency, 0);
    SetStopLoss(Convert.ToString(StopLoss), CalculationMode.Currency, 0, false);
    }
    }

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

    if (CurrentBars[0] < 14)
    return;

    // Set 1
    if ((Close[0] > EMA1[0])
    && (RSI1.Default[0] < 25)
    && (MACD1.Default[0] > MACD1.Default[3]))
    // && (Position.Quantity == 0))
    {
    Print("LONG Entry");
    Print(Position.Quantity);
    EnterLong(Convert.ToInt32(DefaultQuantity), "");
    ExitLongLimit(Convert.ToInt32(DefaultQuantity), 0, "", Convert.ToString(ProfitTarget));
    ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), 0, "", Convert.ToString(StopLoss));
    }

    // Set 2
    if ((Close[0] < EMA1[0])
    && (RSI1.Default[0] > 75)
    && (MACD1.Default[0] < MACD1.Default[3]))
    // && (Position.Quantity == 0))
    {
    Print("SHORT Entry");
    Print(Position.Quantity);
    EnterShort(Convert.ToInt32(DefaultQuantity), "");
    ExitShortLimit(Convert.ToInt32(DefaultQuantity), 0, "", Convert.ToString(ProfitTarget));
    ExitShortStopMarket(Convert.ToInt32(DefaultQuantit y), 0, "", Convert.ToString(StopLoss));
    }

    // Set 3
    // if (Position.Quantity > 0)
    // {
    // Var_Position = 1;
    // Print(Convert.ToString(Position.Quantity));
    // }

    // Set 4
    // if (Position.Quantity == 0)
    // {
    // Var_Position = 0;
    // Print(@"Ok it enters here!!!!");
    // }

    }

    region Properties
    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="ProfitTarget", Order=1, GroupName="Parameters")]
    public int ProfitTarget
    { get; set; }

    [NinjaScriptProperty]
    [Range(1, int.MaxValue)]
    [Display(Name="StopLoss", Order=2, GroupName="Parameters")]
    public int StopLoss
    { get; set; }
    #endregion

    }
    }
    ​
    Attached Files

    #2
    Hello givemefood,

    Thanks for your post.

    I see in the code that you shared that you are using Exit methods and Set methods in your strategy. Using Exit methods and Set methods in your strategy creates a violation of the Managed Approach Internal Order Handling Rules linked below.

    Managed Approach Internal Order Handling Rules: https://ninjatrader.com/support/help...rnalOrderHandl ingRulesThatReduceUnwantedPositions

    You would need to modify your strategy to use either Exit methods or Set methods, but not both.

    Ultimately, if the expected trade(s) are not appearing, this would indicate that the condition to place the order is not evaluating as true or the order is being ignored for other reasons.

    To understand why the script is behaving as it is, such as placing orders or not placing orders or drawing objects when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar. Prints will appear in the NinjaScript Output window (New > NinjaScript Output window).​

    Also, enable TraceOrders which will let us know if any orders are being ignored and not being submitted when the condition to place the orders is evaluating as true.

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.

    https://ninjatrader.com/support/foru...121#post791121

    Let us know if we may assist further.​
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thanks. I disabled the code for set methods. Will try your suggestions. Can you advise why I'm starting with a position size of 1? This is why the condition doesn't work, or if the condition works, it's not placing the orders. The latter I will research based on your suggestions. What about the former, that is, a position size of 1?

      Comment


        #4
        Hello givemefood,

        Thanks for your note.

        When a strategy is enabled, it processes historical data to determine trades that the strategy would have made on the data that is already on the PC/chart and to determine what position the strategy is in. (Strategy positions are separate from actual Account positions.)

        If you are using the 'Wait until flat' Start Behavior and the strategy calculates a historical position, this means that once the strategy has finished processing the historical data and has transitioned to real-time, it will wait until there is a real-time order submission that will cause the strategy to become flat. This also includes changing from a long position to a short position or vice versa as the position would pass through flat.

        This also applies to secondary instruments if there are added series to the script. All positions must be flat before real-time orders will begin.

        If you do not want the strategy to calculate a position from processing historical data, add if (State == State.Historical) return; to the top of your OnBarUpodate() strategy logic so historical processing is skipped. The strategy will then always start from a flat position because it has not calculated any orders.

        See the help guide documentation below for more information.
        Strategy vs. Account Position — https://ninjatrader.com/support/help..._account_p.htm
        Start Behaviors — https://ninjatrader.com/support/help..._positions.htm

        Additional information could be found in this forum thread - https://ninjatrader.com/support/foru...ion#post811541

        Let me know if I may assist further.​
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment


          #5
          Thanks. The orders execute now. However, the exit orders (OCO) don't get placed. What have I configured incorrectly?

          The following is from the trace orders output:

          9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Entered internal SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
          9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Ignored SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Buy' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
          9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Entered internal SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='6'
          9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Ignored SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Sell' FromEntrySignal='6' Reason='SignalName does not have a matching FromEntrySignal to exit'
          9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Entered internal SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='6'
          9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Ignored SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Sell' FromEntrySignal='6' Reason='SignalName does not have a matching FromEntrySignal to exit'
          Enters LONG CONDITION
          1
          9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Entered internal SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
          9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Ignored SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Buy' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
          9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Entered internal SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='6'
          9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Ignored SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Sell' FromEntrySignal='6' Reason='SignalName does not have a matching FromEntrySignal to exit'
          9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Entered internal SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='6'
          9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Ignored SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Sell' FromEntrySignal='6' Reason='SignalName does not have a matching FromEntrySignal to exit'
          Enters LONG CONDITION
          1
          ​

          Comment


            #6
            Hello givemefood,

            Thanks for your note.

            I see in the output you shared that you are getting the error message: "SignalName does not have a matching FromEntrySignal to exit" multiple times.

            9/16/2022 10:00:18 AM Strategy 'MainSimpleStrategyCODE/274804639': Ignored SubmitOrderManaged() method at 9/16/2022 10:00:18 AM: BarsInProgress=0 Action=Sell OrderType=StopMarket Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Sell' FromEntrySignal='6' Reason='SignalName does not have a matching FromEntrySignal to exit'

            This happens if you use a FromEntrySignal for an order that does not match the SignalName of any working orders.

            You would need to go through your strategy and make sure that you use the correct FromEntrySignal for the appropriate SignalName of your Entry order.

            See this forum thread post for some more information: https://ninjatrader.com/support/foru...238#post735238

            Let me know if I may assist further.
            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

            Comment


              #7

              I read the other blog and it wasn't helpful, to be honest. Can you share a link to the NT published documentation on how to set up exit limit and exit stop orders? That might lead to a resolution. I've spent hours trying to resolve this and I know it shouldn't take as long.
              Please share instructions or documentation.

              Thank you.

              ​

              Comment


                #8
                Hello givemefood,

                Thanks for your note.

                Please see the attached sample strategy which demonstrates using ExitLongLimit() and ExitLongStopLimit() in a Strategy Builder strategy.

                See the help guide documentation below.
                ExitLongLimit(): https://ninjatrader.com/support/help...tlonglimit.htm
                ExitLongStopLimit(): https://ninjatrader.com/support/help...gstoplimit.htm

                Also, this reference sample demonstrates using multiple Entry/Exit signals simultaneously: https://ninjatrader.com/support/help..._exit_sign.htm

                Here is a link to our publicly available training videos, 'Strategy Builder 301' and 'NinjaScript Editor 401', for you to view at your own convenience.

                Strategy Builder 301 — https://www.youtube.com/watch?v=_KQF2Sv27oE&t=13s

                NinjaScript Editor 401 - https://youtu.be/H7aDpWoWUQs?list=PL...We0Nf&index=14

                I am also linking you to the Educational Resources section of the Help Guide to help you get started with NinjaScript:
                https://ninjatrader.com/support/help..._resources.htm

                Let me know if I may assist further.
                Attached Files
                <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                Comment


                  #9
                  Brandon,

                  The ExitMethods sample file was very helpful. Thank you. However, it did not include the "re-arming" of the order in the next bar and subsequent bars.

                  Here's the text from the output file:

                  8/19/2022 5:47:51 AM Strategy 'MainSimpleStrategyCODE/274804642': Entered internal SubmitOrderManaged() method at 8/19/2022 5:47:51 AM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='myEntry' FromEntrySignal=''
                  Enters LONG CONDITION
                  8/19/2022 5:47:51 AM Strategy 'MainSimpleStrategyCODE/274804642': Entered internal SubmitOrderManaged() method at 8/19/2022 5:47:51 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=1 LimitPrice=4253.00 StopPrice=0 SignalName='myTarget' FromEntrySignal='myEntry'
                  8/19/2022 5:47:51 AM Strategy 'MainSimpleStrategyCODE/274804642': Entered internal SubmitOrderManaged() method at 8/19/2022 5:47:51 AM: BarsInProgress=0 Action=Sell OrderType=StopLimit Quantity=1 LimitPrice=0 StopPrice=4249.25 SignalName='myStop' FromEntrySignal='myEntry'
                  8/19/2022 5:49:57 AM Strategy 'MainSimpleStrategyCODE/274804642': Cancelled expired order: BarsInProgress=0, orderId='c0c5a88152664b29a65d4028cab10ad0' account='Playback101' name='myTarget' orderState=Working instrument='ES 09-22' orderAction=Sell orderType='Limit' limitPrice=4253 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=608 time='2022-08-19 05:47:51' gtd='2099-12-01' statementDate='2022-08-19'
                  8/19/2022 5:49:57 AM Strategy 'MainSimpleStrategyCODE/274804642': Cancelled expired order: BarsInProgress=0, orderId='acc254894db04672acd073761d15621e' account='Playback101' name='myStop' orderState=Accepted instrument='ES 09-22' orderAction=Sell orderType='Stop Limit' limitPrice=0 stopPrice=4249.25 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=609 time='2022-08-19 05:47:51' gtd='2099-12-01' statementDate='2022-08-19'​

                  How do I address the "Cancelled expired order" error or issue?
                  I don't want the order to cancel or expire but to close only through either take profit (limit order) or stop loss (stop limit order). Do you have an example for this?

                  This is for Tick Change strategy and not Bar Close.

                  Thanks.
                  Last edited by givemefood; 09-19-2022, 05:39 PM.

                  Comment


                    #10
                    Hello givemefood,

                    Thanks for your note.

                    In general, the message 'Cancelled expired order' means that the order was canceled because you had not re-armed the order on the next bar. If the order is meant to persist for more than 1 bar you would either need to ensure the logic remains true for that span of bars or use the LiveUntilCancelled overload set.

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

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


                    Using true for isliveUntilCancelled would keep the order open for multiple bars or until you cancel it.​ Note that you can only use the isliveUntilCancelled overload set in an unlocked strategy, not from the Strategy Builder.

                    See the help guide documentation below for more information.
                    EnterLongLimit(): https://ninjatrader.com/support/helpGuides/nt8/enterlonglimit.htm
                    ExitLongLimit(): https://ninjatrader.com/support/help...tlonglimit.htm

                    Let me know if I may assist further.
                    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                    Comment


                      #11
                      Hi Brandon,

                      Can you share an example of how isLiveUntilCancelled would be used for exit orders to take profit and to hit stop loss? The syntax is helpful but without an actual and complete example, I might be spinning in circles.

                      Thanks.

                      Comment


                        #12
                        Hello givemefood,

                        Thanks for your note.

                        The isLiveUntilCancelled property would work the same way for both Entry order methods and Exit order methods. When this property is set to true, the order will remain live on the chart until it is filled or canceled. When the property is set to false, Entry and Exit orders will be canceled at the end of the bar they are submitted to if they are not filled. By default, this property is false.

                        Please see the attached sample script demonstrating using the isLiveUntilCanceled overload for Exit order methods.

                        Also, see the reference sample on this help guide page which demonstrates keeping orders alive using the isLiveUntilCancelled property.



                        Let me know if I may further assist.
                        Attached Files
                        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                        Comment


                          #13
                          Awesome. Very helpful. Thank you.
                          I revised the code below based on the samples you shared.
                          __________________________________________________

                          if ((RSI1.Default[0] > 25))
                          {

                          if ((Position.MarketPosition == MarketPosition.Flat))

                          {
                          EnterLong(Convert.ToInt32(DefaultQuantity), @"myEntry");
                          OkToTrade = true;
                          }

                          if (Position.MarketPosition == MarketPosition.Long && OkToTrade == true)
                          {
                          ExitLongLimit(0, true, Convert.ToInt32(DefaultQuantity), (Position.AveragePrice + (TakeProfit * TickSize)) , @"myTarget", @"myEntry");
                          ExitLongStopLimit(0, true, Convert.ToInt32(DefaultQuantity), 0, (Position.AveragePrice + (-StopLoss * TickSize)) , @"myStop", @"myEntry");
                          OkToTrade = false;
                          }

                          }
                          ______________________________________

                          The 1st trade that is entered by the code when the condition is met, an order is placed and fulfilled following which 2 exit orders are immediately placed (take profit, stop loss). However, after the 1st trade exits, the next trade and other trades do not get the 2 exit orders placed. I get the following errors in the log. Any ideas or suggestions?


                          9/20/2022 5:50:19 PM Strategy '274804650/MainSimpleStrategyCODE: Cancelled pending exit order, since associated position is closed, orderId='ccee2dcd76004b7abf3d8bbe53c02745' account='Sim101' name='myTarget' orderState=Working instrument='ES 12-22' orderAction=Sell orderType='Limit' limitPrice=3882.25 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=1025 time='2022-09-20 17:38:53' gtd='2099-12-01' statementDate='2022-09-20'

                          9/20/2022 5:50:26 PM Strategy 'MainSimpleStrategyCODE/274804650': Entered internal SubmitOrderManaged() method at 9/20/2022 5:50:26 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                          9/20/2022 5:50:26 PM Strategy 'MainSimpleStrategyCODE/274804650': Entered internal SubmitOrderManaged() method at 9/20/2022 5:50:26 PM: BarsInProgress=0 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=2.25 StopPrice=0 SignalName='myTarget' FromEntrySignal='myEntry'

                          9/20/2022 5:50:26 PM Strategy 'MainSimpleStrategyCODE/274804650': Ignored SubmitOrderManaged() method at 9/20/2022 5:50:26 PM: BarsInProgress=0 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=2.25 StopPrice=0 SignalName='myTarget' FromEntrySignal='myEntry' Reason='This was an exit order but no position exists to exit'

                          9/20/2022 5:50:26 PM Strategy 'MainSimpleStrategyCODE/274804650': Entered internal SubmitOrderManaged() method at 9/20/2022 5:50:26 PM: BarsInProgress=0 Action=BuyToCover OrderType=StopLimit Quantity=1 LimitPrice=0 StopPrice=-1.50 SignalName='myStop' FromEntrySignal='myEntry'
                          ​
                          9/20/2022 5:50:26 PM Strategy 'MainSimpleStrategyCODE/274804650': Ignored SubmitOrderManaged() method at 9/20/2022 5:50:26 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Sell short' FromEntrySignal='' Reason='There already is a matching order with same prices and quantity'
                          ​

                          Comment


                            #14
                            Hello givemefood,

                            Thanks for your note.

                            "Cancelled pending exit order, since associated position is closed"

                            This trace tells us that our stop-loss order was cancelled because its corresponding position was already closed by another order.

                            "Entered internal SubmitOrderManaged() method at 9/20/2022 5:50:26 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''"

                            This trace is outputted when we place an entry order. It tells us all the pertaining properties of our order as well as the time it was submitted.

                            "Ignored SubmitOrderManaged() method at 9/20/2022 5:50:26 PM: BarsInProgress=0 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=2.25 StopPrice=0 SignalName='myTarget' FromEntrySignal='myEntry' Reason='This was an exit order but no position exists to exit'"

                            This trace provides the reason why our Limit order was ignored. We can see that this order was ignored because an exit order was triggered to submit but no positions exist to exit. This is likely because the position was closed by another order already, similar to the first TraceOrder output.

                            Your strategy then places another entry order, as seen below.

                            "Entered internal SubmitOrderManaged() method at 9/20/2022 5:50:26 PM: BarsInProgress=0 Action=BuyToCover OrderType=StopLimit Quantity=1 LimitPrice=0 StopPrice=-1.50 SignalName='myStop' FromEntrySignal='myEntry'"

                            Then, an order is ignored because there is already a matching order placed with the same prices and quantity.

                            "Ignored SubmitOrderManaged() method at 9/20/2022 5:50:26 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Sell short' FromEntrySignal='' Reason='There already is a matching order with same prices and quantity'"


                            Please send me an exported copy of your strategy so I may look into this further.

                            To export a strategy, go to Control Center > Tools > Export > NinjaScript AddOn.

                            I look forward to further assisting.
                            <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                            Comment


                              #15
                              Hi Brandon,
                              Thanks for taking a look at this strategy. Attached is the exported version.
                              Attached Files

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Yesterday, 05:17 AM
                              0 responses
                              65 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              139 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              75 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              45 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              50 views
                              0 likes
                              Last Post TheRealMorford  
                              Working...
                              X