Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

EnterLongStopMarket in next bar

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

    EnterLongStopMarket in next bar

    How do I enter a stop market order to enter in the next bar if price is higher than the high of the current bar?

    #2
    Hello lisalisa, and thank you for your question. This commented code sample should help you get started. I am happy to answer any questions I can.

    There was one thing you said that I had to interpret, please let me know if I interpreted this correctly. When you say "the price is higher than the high of the current bar" I took that to mean that that the building bar has a price that is higher than any price in the most recent completed bar. Otherwise this condition would be true for every bar, since every currently building bar will have a highest price for that bar, and you would always enter stop market orders every single bar.

    I also assumed you wanted to enter on the long side of the market. If you wanted to enter on the short side of the market, just change "long" to "short" below.

    Finally, since you did not specify a stop price, I assumed that you would like to place this 1 tick above the next bar's highest price. If you are entering short, you may want to change High[0] to Low[0] and subtract TickSize instead of adding. To enter multiple ticks away, just multiply TickSize by the number of ticks away you would like to place your order.

    Code:
    [FONT=Courier New]protected override void OnBarUpdate()
    {
      //  if the price is higher than the high of the current bar, enter on the next bar
      // another way to say this is that if this is the next bar, and the highest price 2 bars ago was lower than the final price one bar ago, enter on this bar
      if (Close[1] > High[2])
      {
        // enter a stop market order
        EnterLongStop(High[0] + TickSize);
      }
    }[/FONT]
    Jessica P.NinjaTrader Customer Service

    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
    73 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