Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MIT order at low of previous 15 minutes not working

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

    MIT order at low of previous 15 minutes not working

    Hi, I could use help as I am relatively new to this language. I am currently using the Strategy Builder. I want to place a short MIT order at the low of the previous 15 minutes. I would also like to set the stop loss and take profit to 40 and 60 ticks, respectively. When I run this in the Analyzer and replay it sets an order at the current price at 6:30 and closes the trade immediately. I can't figure out where I made a mistake. I have tried calculating it every tick, I have even modified it to just look back 15 bars and set a stop order at the low (without the extra series). I get the same result no matter what modification I make. Here is the code:

    namespace NinjaTrader.NinjaScript.Strategies
    {
    public class Short15MinBO : Strategy
    {
    private bool ShortFirst;



    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Strategy here.";
    Name = "Short15MinBO";
    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 = 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;
    ShortFirst = false;
    }
    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Minute, 15);
    SetProfitTarget(@"", CalculationMode.Ticks, 60);
    SetStopLoss("", CalculationMode.Ticks, 40, false);
    }
    }

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

    if (CurrentBars[0] < 1
    || CurrentBars[1] < 1)
    return;

    // Set 1
    if ((Times[0][0].TimeOfDay >= new TimeSpan(6, 30, 0))
    && (Times[0][0].TimeOfDay < new TimeSpan(6, 35, 0))
    && (ShortFirst == false))
    {
    ShortFirst = true;
    EnterShortMIT(Convert.ToInt32(DefaultQuantity), Lows[1][0], "");
    }

    // Set 2
    if (Bars.IsFirstBarOfSession == true)
    {
    ShortFirst = false;
    }

    }
    }
    }​
    Thank you in advance for your help!

    #2
    Hello bk597,

    Welcome to the NinjaTrader forums!

    Below is a link to a support article with helpful resources on getting started with NinjaScript and includes a video of using the Strategy Builder.


    To select the previous bars value, set Bars ago to 1 when selecting the series.

    A sell MIT order would be placed above the current bid.
    A buy MIT order would be placed below the current ask.

    Try placing MIT orders manually using Chart Trader to see where each order is placed.

    A sell MIT order that is placed equal to or below the bid would become a market order and fill at market price.

    If you would like a sell order working above the bid use a sell limit order.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for the insight and help. I am still getting immediate execution at the current price even when using 1 Bar ago and Stop orders. Whatever the price is at 6:30 is the execution price. Here is what the order lines look like, with the rest of the code being the same as above.

      EnterShortStopLimit(Convert.ToInt32(DefaultQuantit y), Lows[1][1], Lows[1][1], "");
      EnterShortStopMarket(Convert.ToInt32(DefaultQuanti ty), Lows[1][1], "");

      The orders still immediately close the instant they are opened.

      Comment


        #4
        I think I have figured out the problem and have it working now. I appreciate your help!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        52 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
        48 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X