Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Price Limit Order Being Ignored

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

    Stop Price Limit Order Being Ignored

    Ok so on conditions met, I have a limit order long which is working just fine. I'm attempting to set a stop limit order at the pricepoint of the Low[1].

    From this page: https://ninjatrader.com/support/help...ngstopmarket.h tm

    I have followed its instruction yet the the stopPrice is being ignored.

    Long Example:
    if ( blah blah )

    {

    EnterLongLimit(Convert.ToInt32(Contracts), IB_High, @"Long");
    stopPrice = Low[1];​

    }

    ExitLongStopMarket(stopPrice);

    Do I need to identify the signal name [Long] somehow in this? The example did not stipulate that. Currently I have no other hard stop in place as I assume the exchange would immediately reject a double order.

    ************************************************** ************************************************** ************************************************** ************************************************** ********
    ************************************************** ************************************************** ************************************************** ************************************************** ********

    Also, I have tried the following:

    SetProfitTarget(@"Long", CalculationMode.Ticks, Target);
    SetProfitTarget(@"Short", CalculationMode.Ticks, Target);
    SetStopLoss(@"Long", CalculationMode.Price, AlphaLow, false);
    SetStopLoss(@"Short", CalculationMode.Price, AlphaHigh, false);​




    Long Example:
    if ( blah blah )​

    {
    AlphaLow = Convert.ToInt32(Low[1]);
    EnterLongLimit(Convert.ToInt32(Contracts), IB_High, @"Long");
    }

    ​AlphaLow is of course a variable with a default setting of zero.

    Still being ignored...

    Thanx
    JM

    #2
    Hello JM,

    Thanks for your post.

    In your script, you should check if you are in a long position (Position.MarketPosition == MarketPosition.Long) and call your ExitLongStopMarket() method within that condition.

    Yes, you should use the signal name of the entry order for the 'FromEntrySignal' parameter when calling the ExitLongStopMarket() order. And, provide the exit order method a signal name property of something like 'Exit Stop Market".

    ExitLongStopMarket(double stopPrice, string signalName, string fromEntrySignal)

    ExitLongStopMarket(): https://ninjatrader.com/support/help...stopmarket.htm

    Further, 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).

    Below is a link to a forum post that demonstrates how to use prints to understand behavior.
    https://ninjatrader.com/support/foru...121#post791121

    Also, keep an eye on the Log tab of the Control Center to see if any errors occur when the strategy should place the exit order.​​
    <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
      Thank you Brandon,

      Still not working... Agreed on print usage, but (graduating slowly ) need to study that further before I take a shot at it.

      Immediate moment, the inclusion of what I assume correct syntax in a variety of ways simply fails...

      Due Diligence:

      private double AlphaHigh;
      private double AlphaLow;​


      were created.

      Limit entry execution signals work spot on.

      Example: On Short entry execution I have the following actions:

      {
      InsideBar = true;
      IB_High = Convert.ToInt32(High[0]);
      IB_Low = Convert.ToInt32(Low[0]);
      AlphaHigh = Convert.ToInt32(High[1]);
      AlphaLow = Convert.ToInt32(Low[1]);
      EnterShortLimit(Convert.ToInt32(Contracts), IB_Low, @"Short");


      }​

      So assumedly here I've set price parameters for the variables, notably here the 'Alphas' above.

      Following your counsel I created conditional sets, and per help guide I created:


      // Set 7 Long Alpha Exit

      if (Position.MarketPosition = MarketPosition.Long)

      { ExitLongStopMarket(AlphaLow, "Exit", "Long");
      }


      // Set 8 Short Alpha Exit

      if (Position.MarketPosition = MarketPosition.Short)

      { ExitShortStopMarket(AlphaHigh, "Exit", "Short");
      }


      Checking for Current Market position as you suggested yields the compilation error:

      Cannot implicitly convert type 'NinjaTraderCBI.MarketPosition' to 'bool'

      ok so assuming it doesn't like my If statement

      so then I tried:

      if ((Position.MarketPosition = MarketPosition.Long) = true)

      { ExitLongStopMarket(AlphaLow, "Exit", "Long");
      }

      // Set 8 Short Alpha Exit
      if ((Position.MarketPosition = MarketPosition.Short) = true)

      { ExitShortStopMarket(AlphaHigh, "Exit", "Short");
      }​


      which now yields this error:

      The left-hand side of an assignment must be a variable, property, or indexer

      OK....

      So, the next stab was this:

      if (AlphaLow > 0)

      { ExitLongStopMarket(AlphaLow, "Exit", "Long");
      }

      // Set 8 Short Alpha Exit
      if (AlphaHigh > 0)

      { ExitShortStopMarket(AlphaHigh, "Exit", "Short");
      }


      Compilation successful but signal still being ignored... ​

      Comment


        #4
        Hello johnMoss,

        Thanks for your notes.

        The error message "Cannot implicitly convert type 'NinjaTraderCBI.MarketPosition' to 'bool'" is occurring because you are not using the 'equal to' comparison operator (==) in your script, you are assigning a value with "=".

        You would need to change this code to use "==", such as Position.MarketPosition == MarketPosition.Long.

        See this help guide page for more information and sample code: https://ninjatrader.com/support/help...etposition.htm

        Further, it is necessary to add debugging prints to a strategy to understand how your logic in the strategy is behaving if the strategy is not behaving as expected.

        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).

        Below is a link to a forum post that demonstrates how to use prints to understand behavior.
        https://ninjatrader.com/support/foru...121#post791121
        <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
          Thank you Brandon, I suspect == should solve the problem... If not, off to prints I go .. Thank you for your input...

          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