Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Order Collison?

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

    Order Collison?

    I seem to be getting errors on my stop orders in this code. I'm new to coding. Any advice? Set 2 entered the trade correctly and set 3c entered the stop and limit orders, but when the stop was hit, all hell broke loose, lol. Here's a small snippet.

    // Set 2
    if ((Times[0][0].TimeOfDay > new TimeSpan(9, 35, 0))
    && (Times[0][0].TimeOfDay < new TimeSpan(15, 51, 0))
    && (Circuitbreaker == true)
    && ((FiveMinHigh - FiveMinLow) < 62.75)
    && (CrossAbove(High, LongBreak, 1)))
    {
    EnterLong(Convert.ToInt32(TradeSize), "");
    TargetHigh = CurrentDayOHL1.CurrentHigh[0];
    TargetLow = CurrentDayOHL1.CurrentLow[0];

    }

    // Set 3a Checks to see if open is greater than the long break and there is at least 50% of range points to gain. Exits at the TargetOpen
    if ((Position.MarketPosition == MarketPosition.Long)
    && (OpenGreaterThanLongBreak == true))
    {
    ExitLongLimit(Convert.ToInt32(TradeSize), TargetOpen, "", "");
    ExitLongStopMarket(Convert.ToInt32(TradeSize), LongStop, "", "");
    }

    // Set 3b
    if ((Position.MarketPosition == MarketPosition.Long)
    && (OpenLessThanLongMin == true))
    {
    ExitLongLimit(Convert.ToInt32(TradeSize), TargetHigh, "", "");
    ExitLongStopMarket(Convert.ToInt32(TradeSize), MidPoint, "", "");

    }

    // Set 3c
    if ((Position.MarketPosition == MarketPosition.Long)
    && (OpenLessThanLongBreak == true))
    {
    ExitLongLimit(Convert.ToInt32(TradeSize), TargetHigh, "", "");
    ExitLongStopMarket(Convert.ToInt32(TradeSize), MidPoint, "", "");
    }​

    #2
    Hello NTtrader4375,

    When you ran the script and the stop was hit what specifically happened or what problem did you see?

    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse I seem to have fixed this (I think I had some logic twisted in the code) Thanks

      Comment


        #4
        I have a new issue. Exit limit and Stop orders are cancelling out when a new bar starts. My strategy is set to run on price change. I'll paste the code. The exits for longs are set 3 and the exits for shorts are set 6. This is a simple opening range breakout strategy. The entries are working, the stop and limits are getting set...they are just getting cancelled for some reason.

        public class RTS4MidStop : Strategy
        {
        private double FiveMinLow;
        private double FiveMinHigh;
        private double TargetOpen;
        private double TargetHigh;
        private double TargetLow;
        private bool Circuitbreaker;
        private double Accumulated;
        private double LongStop;
        private double ShortStop;
        private double LongBreak;
        private double ShortBreak;
        private double HighBreakTarget;
        private double LowBreakTarget;
        private double MidPoint;
        private bool exitMessagePrintedSet3;
        private bool exitMessagePrintedSet6;
        private bool longMessagePrintedSet2;
        private bool shortMessagePrintedSet5;
        private bool eodLongExitPrintedSet10;
        private bool eodShortExitPrintedSet11;
        private bool exitEntryVariablesReset;
        private bool ITHset935;
        private bool ITLset935;
        private bool ITOset935;
        private bool LongBreakSet935;
        private bool ShortBreakSet935;
        private double openingRangeSize;
        private bool midPointSet935;
        private bool openingRangeSet935;
        private bool ORTooLarge;
        private bool ORTooLargeSet935;








        private CurrentDayOHL CurrentDayOHL1;





        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"Enter the description for your new custom Strategy here.";
        Name = "RTS4MidStop";
        Calculate = Calculate.OnPriceChange;
        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 = 20;
        // Disable this property for performance gains in Strategy Analyzer optimizations
        // See the Help Guide for additional information
        IsInstantiatedOnEachOptimizationIteration = true;
        DailyGoal = 75;
        TradeSize = 1;
        FiveMinLow = 1;
        FiveMinHigh = 1;
        TargetOpen = 1;
        TargetHigh = 1;
        TargetLow = 1;
        LongBreak = 1;
        ShortBreak = 1;
        HighBreakTarget = 1;
        LowBreakTarget = 1;
        MidPoint = 1;
        Circuitbreaker = true;
        exitMessagePrintedSet3 = false;
        exitMessagePrintedSet6 = false;
        longMessagePrintedSet2 = false;
        shortMessagePrintedSet5 = false;
        eodLongExitPrintedSet10 = false;
        eodShortExitPrintedSet11 = false;
        exitEntryVariablesReset = false;
        ITHset935 = false;
        ITLset935 = false;
        ITOset935 = false;
        ShortBreakSet935 = false;
        LongBreakSet935 = false;
        openingRangeSize = 1;
        midPointSet935 = false;
        openingRangeSet935 = false;
        ORTooLarge = false;
        ORTooLargeSet935 = false;

        }
        else if (State == State.Configure)
        {
        }
        else if (State == State.DataLoaded)
        {
        CurrentDayOHL1 = CurrentDayOHL(Close);
        CurrentDayOHL1.Plots[0].Brush = Brushes.Goldenrod;
        CurrentDayOHL1.Plots[1].Brush = Brushes.SeaGreen;
        CurrentDayOHL1.Plots[2].Brush = Brushes.Red;
        AddChartIndicator(CurrentDayOHL1);
        }
        }


        protected override void OnBarUpdate()
        {

        if (BarsInProgress != 0)
        return;

        if (CurrentBars[0] < 25)
        return;



        // Set 1

        if ((Times[0][0].TimeOfDay > new TimeSpan(9, 30, 0))
        && (Times[0][0].TimeOfDay <= new TimeSpan(9, 35, 0)))
        {
        Draw.HorizontalLine(this, @"paint123 Horizontal Line_1", false, High[0], Brushes.Lime, DashStyleHelper.Solid, 2);
        Draw.HorizontalLine(this, @"paint123 Horizontal Line_2", false, Low[0], Brushes.Red, DashStyleHelper.Solid, 2);
        FiveMinLow = Low[0];
        FiveMinHigh = High[0];
        openingRangeSize = FiveMinHigh - FiveMinLow;
        LongBreak = FiveMinHigh + 1;
        ShortBreak = FiveMinLow - 1;
        MidPoint = FiveMinHigh - ((FiveMinHigh - FiveMinLow) / 2);
        TargetHigh = FiveMinHigh + openingRangeSize;
        TargetLow = FiveMinLow - openingRangeSize;
        Draw.TextFixed(this, @"paint123 Text_1", @"Opening Range High:" + Convert.ToString(FiveMinHigh), TextPosition.TopLeft);
        Draw.TextFixed(this, @"paint123 Text_2", @"Opening Range Low:" + Convert.ToString(FiveMinLow), TextPosition.BottomLeft );
        Draw.TextFixed(this, @"paint123 Text_3", @"Target High:" + TargetHigh.ToString(), TextPosition.TopRight); // Simplified conversion
        Draw.TextFixed(this, @"paint123 Text_4", @"Target Low:" + TargetLow.ToString(), TextPosition.BottomRight); // Simplified calculation and conversion
        Draw.RegionHighlightY(this, @"paint123 Region highlight y_1", false, High[0], Low[0], Brushes.Gold, Brushes.Gold, 25);

        // Check opening range size and set corresponding variables
        {
        if (openingRangeSize > 62.5)
        ORTooLarge = true;
        }


        }


        {
        if (!ITHset935 && !ITLset935 && !LongBreakSet935 && !ShortBreakSet935 && !openingRangeSet935 && !midPointSet935)
        {
        Print(Time[0] + " - Opening Range Size: " + openingRangeSize);
        Print(Time[0] + " - Initial Target High: " + TargetHigh);
        Print(Time[0] + " - Initial Target Low: " + TargetLow);
        Print(Time[0] + " - LongBreak Set: " + LongBreak);
        Print(Time[0] + " - ShortBreak Set: " + ShortBreak);
        Print(Time[0] + " - MidPoint Set: " + MidPoint);
        ITHset935 = true;
        ITLset935 = true;
        LongBreakSet935 = true;
        ShortBreakSet935 = true;
        openingRangeSet935 = true;
        midPointSet935 = true;
        }

        {
        if (!midPointSet935)
        Print(Time[0] + " - OR Too Large, No Trades: ");
        ORTooLargeSet935 = true;
        }
        }



        // Set 2
        if ((Times[0][0].TimeOfDay > new TimeSpan(9, 35, 0))
        && (Times[0][0].TimeOfDay < new TimeSpan(16, 00, 0))
        && (Circuitbreaker == true)
        && (openingRangeSize < 62.75)
        && (CrossAbove(High, LongBreak, 1)))
        {
        {
        if (!longMessagePrintedSet2)
        {
        openingRangeSize = FiveMinHigh - FiveMinLow;
        TargetHigh = FiveMinHigh + openingRangeSize;
        MidPoint = FiveMinHigh - ((FiveMinHigh - FiveMinLow) / 2);

        EnterLong(Convert.ToInt32(TradeSize), "");
        Print(Time[0] + " ***** Set 2 Long Entry");
        longMessagePrintedSet2 = true;
        }
        }

        }



        // Set 3
        if ((Position.MarketPosition == MarketPosition.Long))

        {
        if (!exitMessagePrintedSet3)

        {
        ExitLongLimit(Convert.ToInt32(TradeSize), TargetHigh, "", "");
        ExitLongStopLimit(Convert.ToInt32(TradeSize), MidPoint, "", "");
        Print(" *** Set 3 Long Trade Stop and Limit Set at Target High and Midpoint Stop");
        exitMessagePrintedSet3 = true;
        }

        }




        // Set 4
        if (SystemPerformance.AllTrades.TradesPerformance.Cur rency.CumProfit - Accumulated >= DailyGoal)
        {
        Circuitbreaker = false;

        }
        // Set 5
        if ((Times[0][0].TimeOfDay > new TimeSpan(9, 35, 0))
        && (Times[0][0].TimeOfDay < new TimeSpan(16, 00, 0))
        && (Circuitbreaker == true)
        && (openingRangeSize < 62.75)
        && (CrossBelow(Low, ShortBreak, 1)))
        {

        if (!shortMessagePrintedSet5)
        {
        openingRangeSize = FiveMinHigh - FiveMinLow;
        TargetLow = FiveMinLow - openingRangeSize;
        MidPoint = FiveMinHigh - ((FiveMinHigh - FiveMinLow) / 2);

        EnterShort(Convert.ToInt32(TradeSize), "");
        Print(Time[0] + " ***** Set 5 Short Entry ");
        shortMessagePrintedSet5 = true;
        }
        }



        // Set 6
        if ((Position.MarketPosition == MarketPosition.Short))

        {

        if (!exitMessagePrintedSet6)

        {
        ExitShortLimit(Convert.ToInt32(TradeSize), TargetLow, "", "");
        ExitShortStopLimit(Convert.ToInt32(TradeSize), MidPoint, "", "");
        Print(" *** Set 6 Short Trade Stop and Limit Set at Target High and Midpoint Stop");
        exitMessagePrintedSet6 = true;
        }


        }



        // Set 9
        if (SystemPerformance.AllTrades.TradesPerformance.Cur rency.CumProfit - Accumulated >= DailyGoal)
        {
        Circuitbreaker = false;
        Print("Set 9 - circuit breaker triggered due to positive day");
        }

        // Set 10
        if ((Times[0][0].TimeOfDay >= new TimeSpan(16, 05, 0))
        && (Position.MarketPosition == MarketPosition.Long))
        {
        if (!eodLongExitPrintedSet10)
        {
        ExitLong(Convert.ToInt32(Position.Quantity), "", "");
        Print(" Set 10 Exited Long trade post 4pm");
        eodLongExitPrintedSet10 = true;

        }
        }

        // Set 11
        if ((Times[0][0].TimeOfDay >= new TimeSpan(16, 05, 0))
        && (Position.MarketPosition == MarketPosition.Short))
        {
        if (!eodShortExitPrintedSet11)
        {
        ExitShort(Convert.ToInt32(Position.Quantity), "", "");
        Print(" Set 11 Exited short trade post 4pm");
        eodShortExitPrintedSet11 = true;
        }
        }
        // Set 11a
        if ((Position.MarketPosition == MarketPosition.Flat))
        {
        if(!exitEntryVariablesReset)
        {

        exitMessagePrintedSet3 = false;
        exitMessagePrintedSet6 = false;
        longMessagePrintedSet2 = false;
        shortMessagePrintedSet5 = false;
        Print("Set 11a- All exit and entry variables reset to false");
        exitEntryVariablesReset = true;
        }
        }

        // Set 12
        if (Times[0][0].TimeOfDay < Times[0][1].TimeOfDay)
        {
        FiveMinHigh = 1;
        TargetHigh = 1;
        TargetLow = 1;
        FiveMinLow = 1;
        LongBreak = 1;
        ShortBreak = 1;
        MidPoint = 1;
        exitMessagePrintedSet3 = false;
        exitMessagePrintedSet6 = false;
        ITHset935 = false;
        ITLset935 = false;
        LongBreakSet935 = false;
        ShortBreakSet935 = false;
        longMessagePrintedSet2 = false;
        shortMessagePrintedSet5 = false;
        eodLongExitPrintedSet10 = false;
        eodShortExitPrintedSet11 = false;
        Circuitbreaker = true;
        Draw.Text(this, @"RTS4MidStop", @"VARIABLES RESET", 0, Close[0]);
        Accumulated = SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit;
        Print("Set 12 Reset daily values");
        }

        }

        region Properties
        [NinjaScriptProperty]
        [Range(0, double.MaxValue)]
        [Display(Name="DailyGoal", Description="Daily Trading Goal", Order=1, GroupName="Parameters")]
        public double DailyGoal
        { get; set; }


        [NinjaScriptProperty]
        [Range(1, int.MaxValue)]
        [Display(Name="TradeSize", Description="Trade Size", Order=3, GroupName="Parameters")]
        public int TradeSize
        { get; set; }
        #endregion
        }
        }​

        Comment


          #5
          Hello NTtrader4375,

          When you ran the script and your prints are output, are you seeing that they print for each bar where the target should be active? I see that you have some variables being used to control the conditions, a first step would be to add a print to each set which calls the exit orders to make sure on the new bar at least one of those sets became true to keep the order active.
          JesseNinjaTrader Customer Service

          Comment


            #6
            I'm not sure I follow. This is what I have for print, can you give me example? Sets 3 and 6 are the only sets that call the orders (unless I am missing something)


            // Set 6
            if ((Position.MarketPosition == MarketPosition.Short))

            {

            if (!exitMessagePrintedSet6)

            {
            ExitShortLimit(Convert.ToInt32(TradeSize), TargetLow, "", "");
            ExitShortStopLimit(Convert.ToInt32(TradeSize), MidPoint, "", "");
            Print(" *** Set 6 Short Trade Stop and Limit Set at Target High and Midpoint Stop");
            exitMessagePrintedSet6 = true;
            }


            }

            Comment


              #7
              Could it be that because I reset the variables "MidPoint, openingRangeSize, and TargetHigh in set 2 (just to be sure they were accurate) even though I had them set in Set 1 there could be a glitch as the code cycles?

              // Set 1

              if ((Times[0][0].TimeOfDay > new TimeSpan(9, 30, 0))
              && (Times[0][0].TimeOfDay <= new TimeSpan(9, 35, 0)))
              {
              Draw.HorizontalLine(this, @"paint123 Horizontal Line_1", false, High[0], Brushes.Lime, DashStyleHelper.Solid, 2);
              Draw.HorizontalLine(this, @"paint123 Horizontal Line_2", false, Low[0], Brushes.Red, DashStyleHelper.Solid, 2);
              FiveMinLow = Low[0];
              FiveMinHigh = High[0];
              openingRangeSize = FiveMinHigh - FiveMinLow;
              LongBreak = FiveMinHigh + 1;
              ShortBreak = FiveMinLow - 1;
              MidPoint = FiveMinHigh - ((FiveMinHigh - FiveMinLow) / 2);
              TargetHigh = FiveMinHigh + openingRangeSize;
              TargetLow = FiveMinLow - openingRangeSize;
              Draw.TextFixed(this, @"paint123 Text_1", @"Opening Range High:" + Convert.ToString(FiveMinHigh), TextPosition.TopLeft);
              Draw.TextFixed(this, @"paint123 Text_2", @"Opening Range Low:" + Convert.ToString(FiveMinLow), TextPosition.BottomLeft );
              Draw.TextFixed(this, @"paint123 Text_3", @"Target High:" + TargetHigh.ToString(), TextPosition.TopRight); // Simplified conversion
              Draw.TextFixed(this, @"paint123 Text_4", @"Target Low:" + TargetLow.ToString(), TextPosition.BottomRight); // Simplified calculation and conversion
              Draw.RegionHighlightY(this, @"paint123 Region highlight y_1", false, High[0], Low[0], Brushes.Gold, Brushes.Gold, 25);

              // Check opening range size and set corresponding variables
              {
              if (openingRangeSize > 62.5)
              ORTooLarge = true;
              }


              }


              {
              if (!ITHset935 && !ITLset935 && !LongBreakSet935 && !ShortBreakSet935 && !openingRangeSet935 && !midPointSet935)
              {
              Print(Time[0] + " - Opening Range Size: " + openingRangeSize);
              Print(Time[0] + " - Initial Target High: " + TargetHigh);
              Print(Time[0] + " - Initial Target Low: " + TargetLow);
              Print(Time[0] + " - LongBreak Set: " + LongBreak);
              Print(Time[0] + " - ShortBreak Set: " + ShortBreak);
              Print(Time[0] + " - MidPoint Set: " + MidPoint);
              ITHset935 = true;
              ITLset935 = true;
              LongBreakSet935 = true;
              ShortBreakSet935 = true;
              openingRangeSet935 = true;
              midPointSet935 = true;
              }

              {
              if (!midPointSet935)
              Print(Time[0] + " - OR Too Large, No Trades: ");
              ORTooLargeSet935 = true;
              }
              }



              // Set 2
              if ((Times[0][0].TimeOfDay > new TimeSpan(9, 35, 0))
              && (Times[0][0].TimeOfDay < new TimeSpan(16, 00, 0))
              && (Circuitbreaker == true)
              && (openingRangeSize < 62.75)
              && (CrossAbove(High, LongBreak, 1)))
              {
              {
              if (!longMessagePrintedSet2)
              {
              openingRangeSize = FiveMinHigh - FiveMinLow;
              TargetHigh = FiveMinHigh + openingRangeSize;
              MidPoint = FiveMinHigh - ((FiveMinHigh - FiveMinLow) / 2);

              EnterLong(Convert.ToInt32(TradeSize), "");
              Print(Time[0] + " ***** Set 2 Long Entry");
              longMessagePrintedSet2 = true;
              }
              }

              }



              // Set 3
              if ((Position.MarketPosition == MarketPosition.Long))

              {
              if (!exitMessagePrintedSet3)

              {
              ExitLongLimit(Convert.ToInt32(TradeSize), TargetHigh, "", "");
              ExitLongStopLimit(Convert.ToInt32(TradeSize), MidPoint, "", "");
              Print(" *** Set 3 Long Trade Stop and Limit Set at Target High and Midpoint Stop");
              exitMessagePrintedSet3 = true;
              }

              }

              Comment


                #8
                Hello NTtrader4375,

                You would need to analyze your prints to see if those items are an issue. For an order to not expire after 1 bar you need to call the order method on each bar while it should be active. If one of your conditions to call the order is false and it does not get called again the order will expire. TO know if that is happening you would need to check the output to see if the condition is not true on the bar where the order got expired.

                JesseNinjaTrader Customer Service

                Comment


                  #9
                  Isn't that what set 3 is doing? If long, do ......

                  // Set 3
                  if ((Position.MarketPosition == MarketPosition.Long))

                  {
                  if (!exitMessagePrintedSet3)

                  {
                  ExitLongLimit(Convert.ToInt32(TradeSize), TargetHigh, "", "");
                  ExitLongStopLimit(Convert.ToInt32(TradeSize), MidPoint, "", "");
                  Print(" *** Set 3 Long Trade Stop and Limit Set at Target High and Midpoint Stop");
                  exitMessagePrintedSet3 = true;
                  }

                  }​

                  Comment


                    #10
                    Hello NTtrader4375,

                    Are you seeing that print when the new bar hapens? I cant tell just by looking at the code, you have 1 condition which should be true and another condition that is being toggled. You would need to check if that print is happening when the order is expired.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      I've taken my code down to bare bones. My stop orders are cancelling and terminating the trade as soon as it triggers. See errors attached and the output screen below. You can see it triggered the entry sell (like it was supposed to) at 2:23:10 and 1 second later it cancelled everything out. I noticed something in the output about exceeded entry signals....is that something I need to address in the code or when I run the strategy?


                      2/16/2024 2:23:10 PM Strategy 'RTS5MidStop/297783262': Entered internal SubmitOrderManaged() method at 2/16/2024 2:23:10 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                      2/16/2024 2:25:00 PM ***** Set 5 Short Entry
                      2/16/2024 2:23:10 PM Strategy 'RTS5MidStop/297783262': Entered internal SubmitOrderManaged() method at 2/16/2024 2:23:10 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                      2/16/2024 2:23:10 PM Strategy 'RTS5MidStop/297783262': Ignored SubmitOrderManaged() method at 2/16/2024 2:23:10 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'
                      2/16/2024 2:25:00 PM ***** Set 5 Short Entry
                      2/16/2024 2:23:11 PM Strategy 'RTS5MidStop/297783262': Entered internal SubmitOrderManaged() method at 2/16/2024 2:23:11 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                      2/16/2024 2:23:11 PM Strategy 'RTS5MidStop/297783262': Ignored SubmitOrderManaged() method at 2/16/2024 2:23:11 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Sell short' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'
                      2/16/2024 2:25:00 PM ***** Set 5 Short Entry
                      2/16/2024 2:23:11 PM Strategy 'RTS5MidStop/297783262': Entered internal SubmitOrderManaged() method at 2/16/2024 2:23:11 PM: BarsInProgress=0 Action=BuyToCover OrderType=Limit Quantity=1 LimitPrice=17843.50 StopPrice=0 SignalName='' FromEntrySignal=''
                      2/16/2024 2:23:11 PM Strategy 'RTS5MidStop/297783262': Entered internal SubmitOrderManaged() method at 2/16/2024 2:23:11 PM: BarsInProgress=0 Action=BuyToCover OrderType=StopLimit Quantity=0 LimitPrice=1.00 StopPrice=17908.50 SignalName='' FromEntrySignal=''
                      *** Set 6 Short Trade Stop and Limit Set at Target High and Midpoint Stop
                      2/16/2024 2:23:11 PM Strategy 'RTS5MidStop/297783262': Entered internal SubmitOrderManaged() method at 2/16/2024 2:23:11 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                      2/16/2024 2:23:11 PM Strategy 'RTS5MidStop/297783262': Ignored SubmitOrderManaged() method at 2/16/2024 2:23:11 PM: BarsInProgress=0 Action=SellShort OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Sell short' FromEntrySignal='' Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'​
                      Attached Files

                      Comment


                        #12
                        Hello NTtrader4375,

                        That is not an expired order that is a rejection, the image says the reason for that. You used a price for the limit which was less than the stop price. You need to correct the prices you are trying to use for that order.
                        JesseNinjaTrader Customer Service

                        Comment


                          #13
                          It was supposed to be set at the target low as indicated in the code. Do you think the variable is getting reset somewhere to "1"? Its supposed to do it at set 12, but that's meant to reset all the variables on the start of the new day.

                          // Set 1
                          if ((Times[0][0].TimeOfDay > new TimeSpan(9, 30, 0))
                          && (Times[0][0].TimeOfDay <= new TimeSpan(9, 35, 0)))
                          {
                          Draw.HorizontalLine(this, @"paint123 Horizontal Line_1", false, High[0], Brushes.Lime, DashStyleHelper.Solid, 2);
                          Draw.HorizontalLine(this, @"paint123 Horizontal Line_2", false, Low[0], Brushes.Red, DashStyleHelper.Solid, 2);
                          FiveMinLow = Low[0];
                          FiveMinHigh = High[0];
                          openingRangeSize = FiveMinHigh - FiveMinLow;
                          LongBreak = FiveMinHigh + 1;
                          ShortBreak = FiveMinLow - 1;
                          MidPoint = FiveMinHigh - ((FiveMinHigh - FiveMinLow) / 2);
                          TargetHigh = FiveMinHigh + openingRangeSize;
                          TargetLow = FiveMinLow - openingRangeSize;
                          Draw.TextFixed(this, @"paint123 Text_1", @"Opening Range High:" + Convert.ToString(FiveMinHigh), TextPosition.TopLeft);
                          Draw.TextFixed(this, @"paint123 Text_2", @"Opening Range Low:" + Convert.ToString(FiveMinLow), TextPosition.BottomLeft);
                          Draw.TextFixed(this, @"paint123 Text_3", @"Target High:" + TargetHigh.ToString(), TextPosition.TopRight); // Simplified conversion
                          Draw.TextFixed(this, @"paint123 Text_4", @"Target Low:" + TargetLow.ToString(), TextPosition.BottomRight); // Simplified calculation and conversion
                          Draw.RegionHighlightY(this, @"paint123 Region highlight y_1", false, High[0], Low[0], Brushes.Gold, Brushes.Gold, 25);

                          // Check opening range size and set corresponding variables
                          if (openingRangeSize > 62.5)
                          {
                          ORTooLarge = true;
                          Print(Time[0] + " - OR Too Large, No Trades: ");
                          }
                          }




                          // Set 2
                          if ((Times[0][0].TimeOfDay > new TimeSpan(9, 35, 0))
                          && (Times[0][0].TimeOfDay < new TimeSpan(16, 00, 0))
                          && (Circuitbreaker == true)
                          && (openingRangeSize < 62.75)
                          && (CrossAbove(High, LongBreak, 1)))

                          {

                          EnterLong(Convert.ToInt32(TradeSize), "");

                          }



                          // Set 3
                          if ((Times[0][0].TimeOfDay > new TimeSpan(9, 35, 0))
                          && (Times[0][0].TimeOfDay < new TimeSpan(16, 00, 0))
                          &&((Position.MarketPosition == MarketPosition.Long)))

                          {

                          ExitLongLimit(Convert.ToInt32(TradeSize), TargetHigh, "", "");
                          ExitLongStopLimit(Convert.ToInt32(TradeSize), MidPoint, "", "");
                          Print(" *** Set 3 Long Trade Stop and Limit Set at Target High and Midpoint Stop");

                          }




                          // Set 4
                          if (SystemPerformance.AllTrades.TradesPerformance.Cur rency.CumProfit - Accumulated >= DailyGoal)
                          {
                          Circuitbreaker = false;

                          }
                          // Set 5
                          if ((Times[0][0].TimeOfDay > new TimeSpan(9, 35, 0))
                          && (Times[0][0].TimeOfDay < new TimeSpan(16, 00, 0))
                          && (Circuitbreaker == true)
                          && (openingRangeSize < 62.75)
                          && (CrossBelow(Low, ShortBreak, 1)))
                          {

                          EnterShort(Convert.ToInt32(TradeSize), "");
                          Print(" ***** Set 5 Short Entry ");

                          }



                          // Set 6
                          if ((Times[0][0].TimeOfDay > new TimeSpan(9, 35, 0))
                          && (Times[0][0].TimeOfDay < new TimeSpan(16, 00, 0))
                          && ((Position.MarketPosition == MarketPosition.Short)))

                          {

                          ExitShortLimit(Convert.ToInt32(TradeSize), TargetLow, "", "");
                          ExitShortStopLimit(Convert.ToInt32(TradeSize), MidPoint, "", "");
                          Print(" *** Set 6 Short Trade Stop and Limit Set at Target High and Midpoint Stop");

                          }



                          // Set 9
                          if (SystemPerformance.AllTrades.TradesPerformance.Cur rency.CumProfit - Accumulated >= DailyGoal)
                          {
                          Circuitbreaker = false;
                          Print("Set 9 - circuit breaker triggered due to positive day");
                          }



                          // Set 12
                          if (Times[0][0].TimeOfDay < Times[0][1].TimeOfDay)
                          {
                          FiveMinHigh = 1;
                          TargetHigh = 1;
                          TargetLow = 1;
                          FiveMinLow = 1;
                          LongBreak = 1;
                          ShortBreak = 1;
                          MidPoint = 1;
                          ITHset935 = false;
                          ITLset935 = false;
                          LongBreakSet935 = false;
                          ShortBreakSet935 = false;
                          Circuitbreaker = true;
                          Draw.Text(this, @"RTS5MidStop", @"VARIABLES RESET", 0, Close[0]);
                          Accumulated = SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit;
                          Print("Set 12 Reset daily values");
                          }

                          }

                          region Properties
                          [NinjaScriptProperty]
                          [Range(0, double.MaxValue)]
                          [Display(Name="DailyGoal", Description="Daily Trading Goal", Order=1, GroupName="Parameters")]
                          public double DailyGoal
                          { get; set; }


                          [NinjaScriptProperty]
                          [Range(1, int.MaxValue)]
                          [Display(Name="TradeSize", Description="Trade Size", Order=3, GroupName="Parameters")]
                          public int TradeSize
                          { get; set; }
                          #endregion
                          }
                          }​


                          Comment


                            #14
                            Hello NTtrader4375,

                            That would be a good use case for Print statements to find out if that is happening. I can't tell by just looking at the code how it is going to run, prints let you see what it actually did when you ran it to make a diagnosis. Because the order had an incorrect price a good starting place would be to print the prices you are using for the orders to see what is being calculated wrong.

                            JesseNinjaTrader Customer Service

                            Comment


                              #15
                              I'll add that in. I think I'm also going to remove set 12. I added that it mostly for backtesting tool and I believe that because I'm entering trades on price change instead of on bar close the time check and variable reset that happens with it may be the issue. Thanks for all your help on this!

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Touch-Ups, Today, 10:36 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Touch-Ups  
                              Started by geddyisodin, 04-25-2024, 05:20 AM
                              8 responses
                              61 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by jxs_xrj, 01-12-2020, 09:49 AM
                              4 responses
                              3,289 views
                              1 like
                              Last Post jgualdronc  
                              Started by Option Whisperer, Today, 09:55 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Option Whisperer  
                              Started by halgo_boulder, 04-20-2024, 08:44 AM
                              2 responses
                              22 views
                              0 likes
                              Last Post halgo_boulder  
                              Working...
                              X