Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StopMar****rder activating next bar

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

    StopMar****rder activating next bar

    Dear Support

    When entering a position, few lines after i am creating an Exit stop market order but this is not getting created just after position is created... but in the next closing bar.

    how do i set this up to work like ATM strategy. as soon as i enter the position i want the stop market order to be activated.

    Code:
    EnterShort(FirstEntry, "GoShort");
    PreviousLowFirstEntry = Low[0];
    
    ...few lines later...
    
    //SET EXIT POSITION
    if (Position.MarketPosition == MarketPosition.Short)
    {
    
    //V4.2.4.3.5 - BREAK EVEN WHEN PSITION IS POSITVE 1 POINT
    if (Position.Quantity == 1)
    {
    
    ExitShortStopMarket(0, true, 0, PreviousHighFirstEntry, "StopLossShort", "GoShort");
    Print(Time[0].ToString() + "Setting Stop Loss: " + PreviousHighFirstEntry.ToString());
    }
    the problem here is that 1 minute bar can go very bad in volatile hour, i can not wait for the next 1 minute bar to form... i need to get the stop market created as soon as i enter a position.

    in this case is the previous low

    can you help me?

    Thanks

    #2
    Hello jimmy_NT,

    Thanks for your post.

    Exit methods cannot be called on the same bar update as the Entry method. The Entry method would need to be called on one bar update and the Exit method would need to be called on the next bar update.

    If you run a strategy with Calculate.OnBarClose, this means the strategy would process logic and place orders at the end of each bar. To have the strategy process logic and place orders intrabar, you could use Calculate.OnEachTick. This means the strategy's OnBarUpdate method would process logic and place orders for each incoming tick.

    By using Calculate.OnEachTick, the Exit order could be placed the very next tick that occurs after the Entry order is placed.

    Or, you could consider using Atm Strategy methods to place an entry order with an Atm Strategy template applied to it to control the stop/target orders. You could view the SampleAtmStrategy script that comes default with NinjaTrader for how to use Atm Strategy methods. To do so, open a New > NinjaScript Editor window, open the Strategies folder, and double-click on the SampleAtmStrategy file.

    See the help guide documentation below for more information and sample code.

    Calculate: https://ninjatrader.com/support/help.../calculate.htm
    Atm Strategy Methods: https://ninjatrader.com/support/help...gy_methods.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


      #3
      Thanks i have enabled however i see some behavior not expected.

      my strategy suppose to open a position when RSI Crosses, however, i see the strategy triggered an entry but RSI did not cross down 70

      see image attached

      Attached Files

      Comment


        #4
        Hello jimmy_NT,

        Thanks for your note.

        To understand why the script is behaving as it is, such as placing orders or not placing orders 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

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 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
        72 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